/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package peaconnector;

/**
 *
 * @author Csubák Péter
 */
public class SchemaElement {

    private String schemaName;
    private String name;

    public static SchemaElement getByAnnot(SEAnnot annot){
        SchemaElement ret = null;
        try {
            ret = (SchemaElement) annot.type().newInstance();
            ret.setByAnnot(annot);
        } catch (Exception ex) {
        }
        return ret;
    }

    public SchemaElement(String schemaName, String name) {
        this.schemaName = schemaName;
        this.name = name;
    }

    public SchemaElement() {
    }

    public void setByAnnot(SEAnnot annot){
        this.name = annot.name();
        this.schemaName = annot.schemaName();
    }

    public String getName() {
        return name;
    }

    public String getSchemaName() {
        return schemaName;
    }

    private boolean equals(String s){
        return (this.schemaName.equals(s));
    }

    private boolean equals(SchemaElement se){
        if (se != null){
            return (this.schemaName.equals(se.schemaName));
        }else{
            return false;
        }
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof String){
            return equals((String) obj);
        }else if (obj instanceof SchemaElement){
            return equals((SchemaElement) obj);
        }else{
            return false;
        }
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 47 * hash + (this.schemaName != null ? this.schemaName.hashCode() : 0);
        hash = 47 * hash + (this.name != null ? this.name.hashCode() : 0);
        return hash;
    }


}
