package open.dolphin.infomodel;
// Generated 2010/06/30 10:57:59 by Hibernate Tools 3.2.1.GA

import java.io.IOException;
import java.io.Writer;
import java.sql.Blob;
import java.sql.SQLException;
import javax.persistence.Transient;
import javax.swing.ImageIcon;
import org.hibernate.lob.BlobImpl;

/**
 * SchemaModel generated by hbm2java
 */
public class SchemaModel extends KarteEntryBean {

    private DocumentModel document;
    private transient Blob jpegBlob;
    private byte[] jpegBytes;

    private ExtRefModel extRef;

    @Transient
    private String fileName;

    @Transient
    private ImageIcon icon;

    @Transient
    private int imageNumber;

    public SchemaModel() {
    }

    public ExtRefModel getExtRef() {
        return extRef;
    }

    public void setExtRef(ExtRefModel val) {
        extRef = val;
    }

    /**
     *
     * @return
     */
    public DocumentModel getDocument() {
        return document;
    }

    public void setDocument(DocumentModel document) {
        this.document = document;
    }

    public byte[] getJpegBytes() {
        return jpegBytes;
    }

    /**
     *
     * @param jpegBytes
     */
    public void setJpegBytes(byte[] jpegBytes) {
        this.jpegBytes = jpegBytes;
        if (jpegBytes == null) {
            jpegBytes = null;
        }
        else {
            this.jpegBlob = new BlobImpl(jpegBytes);
        }
    }

    public Blob getJpegBlob() {
        return this.jpegBlob;
    }

    public void setJpegBlob(Blob jpegBlob) throws SQLException {
        if (jpegBlob != null) {
            this.jpegBlob = jpegBlob;
            this.jpegBytes = jpegBlob.getBytes(1, (int)jpegBlob.length());
        }
    }

    public ImageIcon getIcon() {
        return icon;
    }

    public void setIcon(ImageIcon val) {
        icon = val;
    }

    public int getImageNumber() {
        return imageNumber;
    }

    /**
     *
     * @param imageNumber
     */
    public void setImageNumber(int imageNumber) {
        this.imageNumber = imageNumber;
    }

    public String getFileName() {
        return fileName;
    }

    public void setFileName(String val) {
        fileName = val;
    }

    public IInfoModel getModel() {
        return (IInfoModel) getExtRef();
    }

    public void setModel(IInfoModel val) {
        setExtRef((ExtRefModel) val);
    }

    public int compareTo(Object other) {
        int result = super.compareTo(other);
        if (result == 0) {
            int no1 = getImageNumber();
            int no2 = ((SchemaModel) other).getImageNumber();
            result = no1 - no2;
        }
        return result;
    }

    private String DocumentModelToString(DocumentModel d) {
        if (d == null) {
            return "";
        }
        return Long.toString(d.getId());
    }

    @Override
    public void serialize(Writer result) throws IOException {
        result.append("<SchemaModel" + " document_id='" + DocumentModelToString(document) + "'>" + System.getProperty("line.separator"));
        super.serialize(result);
        if (extRef != null) {
            extRef.serialize(result);
        }
        result.append("<jpegByte>");
        result.append(System.getProperty("line.separator"));
        result.append(jpegBytes.toString());
        result.append("</jpegByte>");
        result.append(System.getProperty("line.separator"));
        result.append("</SchemaModel>");
        result.append(System.getProperty("line.separator"));
    }
}


