/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.common.io.NonCloseableOutputStream
 *  com.l7tech.objectmodel.imp.NamedEntityImp
 *  com.l7tech.util.Charsets
 *  com.l7tech.util.PoolByteArrayOutputStream
 *  com.l7tech.util.SafeXMLDecoder
 *  com.l7tech.util.SafeXMLDecoderBuilder
 *  jakarta.persistence.Basic
 *  jakarta.persistence.Column
 *  jakarta.persistence.Entity
 *  jakarta.persistence.FetchType
 *  jakarta.persistence.Lob
 *  jakarta.persistence.Table
 *  org.hibernate.annotations.Proxy
 */
package com.l7tech.server.security.keystore;

import com.l7tech.common.io.NonCloseableOutputStream;
import com.l7tech.objectmodel.imp.NamedEntityImp;
import com.l7tech.util.Charsets;
import com.l7tech.util.PoolByteArrayOutputStream;
import com.l7tech.util.SafeXMLDecoder;
import com.l7tech.util.SafeXMLDecoderBuilder;
import jakarta.persistence.Basic;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.Lob;
import jakarta.persistence.Table;
import java.beans.XMLEncoder;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.hibernate.annotations.Proxy;

@Entity
@Proxy(lazy=false)
@Table(name="keystore_file")
public class KeystoreFile
extends NamedEntityImp {
    private static final long serialVersionUID = 7293792837442132345L;
    private static final Charset PROPERTIES_ENCODING = Charsets.UTF8;
    @Column(name="format", nullable=false, length=128)
    private String format;
    private byte[] databytes;
    private transient String xmlProperties;
    private Map<String, String> properties;

    public String getFormat() {
        return this.format;
    }

    public void setFormat(String string) {
        this.format = string;
    }

    @Basic(fetch=FetchType.LAZY)
    @Column(name="databytes", length=0x7FFFFFFF)
    @Lob
    public byte[] getDatabytes() {
        return this.databytes;
    }

    public void setDatabytes(byte[] byArray) {
        this.databytes = byArray;
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    @Column(name="properties", length=0x7FFFFFFF)
    @Lob
    public String getXmlProperties() {
        if (this.xmlProperties == null) {
            Map<String, String> map = this.properties;
            if (map == null) {
                return null;
            }
            try (PoolByteArrayOutputStream poolByteArrayOutputStream = new PoolByteArrayOutputStream();){
                XMLEncoder xMLEncoder = new XMLEncoder((OutputStream)new NonCloseableOutputStream((OutputStream)poolByteArrayOutputStream));
                xMLEncoder.writeObject(map);
                xMLEncoder.close();
                this.xmlProperties = poolByteArrayOutputStream.toString(PROPERTIES_ENCODING);
            }
        }
        return this.xmlProperties;
    }

    public void setXmlProperties(String string) {
        if (string != null && string.equals(this.xmlProperties)) {
            return;
        }
        this.xmlProperties = string;
        if (string != null && string.length() > 0) {
            SafeXMLDecoder safeXMLDecoder = new SafeXMLDecoderBuilder((InputStream)new ByteArrayInputStream(string.getBytes(PROPERTIES_ENCODING))).build();
            this.properties = (Map)safeXMLDecoder.readObject();
        }
    }

    public String getProperty(String string) {
        String string2 = null;
        Map<String, String> map = this.properties;
        if (map != null) {
            string2 = map.get(string);
        }
        return string2;
    }

    public void setProperty(String string, String string2) {
        Map<String, String> map = this.properties;
        if (map == null) {
            this.properties = map = new HashMap<String, String>();
        }
        map.put(string, string2);
        this.xmlProperties = null;
    }

    public boolean equals(Object object) {
        if (this == object) {
            return true;
        }
        if (object == null || ((Object)((Object)this)).getClass() != object.getClass()) {
            return false;
        }
        if (!super.equals(object)) {
            return false;
        }
        KeystoreFile keystoreFile = (KeystoreFile)((Object)object);
        if (!Arrays.equals(this.databytes, keystoreFile.databytes)) {
            return false;
        }
        return !(this.format != null ? !this.format.equals(keystoreFile.format) : keystoreFile.format != null);
    }

    public int hashCode() {
        int n2 = super.hashCode();
        n2 = 31 * n2 + (this.format != null ? this.format.hashCode() : 0);
        n2 = 31 * n2 + (this.databytes != null ? Arrays.hashCode(this.databytes) : 0);
        return n2;
    }
}

