package org.freebxml.omar.jaxb.bindings.rim;

import java.util.ArrayList;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElementRef;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlType;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.jvnet.hyperjaxb3.item.Item;
import org.jvnet.hyperjaxb3.item.ItemUtils;
import org.jvnet.hyperjaxb3.xml.bind.JAXBElementUtils;
import org.jvnet.jaxb2_commons.lang.Equals;
import org.jvnet.jaxb2_commons.lang.HashCode;
import org.jvnet.jaxb2_commons.lang.builder.JAXBEqualsBuilder;
import org.jvnet.jaxb2_commons.lang.builder.JAXBHashCodeBuilder;


/**
 * <p>Java class for RegistryObjectListType complex type.
 * 
 * <p>The following schema fragment specifies the expected content contained within this class.
 * 
 * <pre>
 * &lt;complexType name="RegistryObjectListType">
 *   &lt;complexContent>
 *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 *       &lt;sequence>
 *         &lt;element ref="{urn:oasis:names:tc:ebxml-regrep:xsd:rim:4.0}Identifiable" maxOccurs="unbounded" minOccurs="0"/>
 *       &lt;/sequence>
 *     &lt;/restriction>
 *   &lt;/complexContent>
 * &lt;/complexType>
 * </pre>
 * 
 * 
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "RegistryObjectListType", propOrder = {
    "identifiable"
})
@Entity
@Table(name = "RegistryObjectListType")
@Inheritance(strategy = InheritanceType.JOINED)
public class RegistryObjectListType
    implements Equals, HashCode
{

    @XmlElementRef(name = "Identifiable", namespace = "urn:oasis:names:tc:ebxml-regrep:xsd:rim:4.0", type = JAXBElement.class)
    protected List<JAXBElement<? extends IdentifiableType>> identifiable;
    @XmlAttribute
    protected Long hjid;
    @XmlTransient
    protected List<RegistryObjectListType.IdentifiableItem> identifiableItems;

    /**
     * Gets the value of the identifiable property.
     * 
     * <p>
     * This accessor method returns a reference to the live list,
     * not a snapshot. Therefore any modification you make to the
     * returned list will be present inside the JAXB object.
     * This is why there is not a <CODE>set</CODE> method for the identifiable property.
     * 
     * <p>
     * For example, to add a new item, do as follows:
     * <pre>
     *    getIdentifiable().add(newItem);
     * </pre>
     * 
     * 
     * <p>
     * Objects of the following type(s) are allowed in the list
     * {@link JAXBElement }{@code <}{@link AdhocQueryType }{@code >}
     * {@link JAXBElement }{@code <}{@link UserType }{@code >}
     * {@link JAXBElement }{@code <}{@link RegistryObjectType }{@code >}
     * {@link JAXBElement }{@code <}{@link ClassificationType }{@code >}
     * {@link JAXBElement }{@code <}{@link ClassificationNodeType }{@code >}
     * {@link JAXBElement }{@code <}{@link ExternalLinkType }{@code >}
     * {@link JAXBElement }{@code <}{@link RegistryPackageType }{@code >}
     * {@link JAXBElement }{@code <}{@link AuditableEventType }{@code >}
     * {@link JAXBElement }{@code <}{@link FederationType }{@code >}
     * {@link JAXBElement }{@code <}{@link ExternalIdentifierType }{@code >}
     * {@link JAXBElement }{@code <}{@link ServiceType }{@code >}
     * {@link JAXBElement }{@code <}{@link IdentifiableType }{@code >}
     * {@link JAXBElement }{@code <}{@link SubscriptionType }{@code >}
     * {@link JAXBElement }{@code <}{@link ServiceBindingType }{@code >}
     * {@link JAXBElement }{@code <}{@link AssociationType }{@code >}
     * {@link JAXBElement }{@code <}{@link OrganizationType }{@code >}
     * {@link JAXBElement }{@code <}{@link ExtrinsicObjectType }{@code >}
     * {@link JAXBElement }{@code <}{@link ClassificationSchemeType }{@code >}
     * {@link JAXBElement }{@code <}{@link SpecificationLinkType }{@code >}
     * {@link JAXBElement }{@code <}{@link RegistryType }{@code >}
     * {@link JAXBElement }{@code <}{@link PersonType }{@code >}
     * {@link JAXBElement }{@code <}{@link ObjectRefType }{@code >}
     * 
     * 
     */
    @Transient
    public List<JAXBElement<? extends IdentifiableType>> getIdentifiable() {
        if (identifiable == null) {
            identifiable = new ArrayList<JAXBElement<? extends IdentifiableType>>();
        }
        return this.identifiable;
    }

    /**
     * 
     * 
     */
    public void setIdentifiable(List<JAXBElement<? extends IdentifiableType>> identifiable) {
        this.identifiable = identifiable;
    }

    public void equals(Object object, EqualsBuilder equalsBuilder) {
        if (!(object instanceof RegistryObjectListType)) {
            equalsBuilder.appendSuper(false);
            return ;
        }
        if (this == object) {
            return ;
        }
        final RegistryObjectListType that = ((RegistryObjectListType) object);
        equalsBuilder.append(this.getIdentifiable(), that.getIdentifiable());
    }

    public boolean equals(Object object) {
        if (!(object instanceof RegistryObjectListType)) {
            return false;
        }
        if (this == object) {
            return true;
        }
        final EqualsBuilder equalsBuilder = new JAXBEqualsBuilder();
        equals(object, equalsBuilder);
        return equalsBuilder.isEquals();
    }

    public void hashCode(HashCodeBuilder hashCodeBuilder) {
        hashCodeBuilder.append(this.getIdentifiable());
    }

    public int hashCode() {
        final HashCodeBuilder hashCodeBuilder = new JAXBHashCodeBuilder();
        hashCode(hashCodeBuilder);
        return hashCodeBuilder.toHashCode();
    }

    /**
     * Gets the value of the hjid property.
     * 
     * @return
     *     possible object is
     *     {@link Long }
     *     
     */
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "Hjid")
    public Long getHjid() {
        return hjid;
    }

    /**
     * Sets the value of the hjid property.
     * 
     * @param value
     *     allowed object is
     *     {@link Long }
     *     
     */
    public void setHjid(Long value) {
        this.hjid = value;
    }

    @OneToMany(cascade = {
        CascadeType.ALL
    })
    @JoinTable(name = "RegistryObjectListType_Ident_0")
    public List<RegistryObjectListType.IdentifiableItem> getIdentifiableItems() {
        if (this.identifiableItems == null) {
            this.identifiableItems = new ArrayList<RegistryObjectListType.IdentifiableItem>();
        }
        if (ItemUtils.shouldBeWrapped(this.identifiable)) {
            this.identifiable = ItemUtils.wrap(this.identifiable, this.identifiableItems, RegistryObjectListType.IdentifiableItem.class);
        }
        return this.identifiableItems;
    }

    public void setIdentifiableItems(List<RegistryObjectListType.IdentifiableItem> value) {
        this.identifiable = null;
        this.identifiableItems = null;
        this.identifiableItems = value;
        if (this.identifiableItems == null) {
            this.identifiableItems = new ArrayList<RegistryObjectListType.IdentifiableItem>();
        }
        if (ItemUtils.shouldBeWrapped(this.identifiable)) {
            this.identifiable = ItemUtils.wrap(this.identifiable, this.identifiableItems, RegistryObjectListType.IdentifiableItem.class);
        }
    }

    @XmlAccessorType(XmlAccessType.FIELD)
    @Entity
    @Table(name = "RegistryObjectListTypeIdenti_0")
    @Inheritance(strategy = InheritanceType.JOINED)
    public static class IdentifiableItem
        implements Item<JAXBElement<? extends IdentifiableType>>
    {

        @XmlElementRef(name = "Identifiable", namespace = "urn:oasis:names:tc:ebxml-regrep:xsd:rim:4.0", type = JAXBElement.class)
        protected JAXBElement<? extends IdentifiableType> item;
        @XmlAttribute
        protected Long hjid;

        /**
         * Gets the value of the item property.
         * 
         * @return
         *     possible object is
         *     {@link JAXBElement }{@code <}{@link AdhocQueryType }{@code >}
         *     {@link JAXBElement }{@code <}{@link UserType }{@code >}
         *     {@link JAXBElement }{@code <}{@link RegistryObjectType }{@code >}
         *     {@link JAXBElement }{@code <}{@link ClassificationType }{@code >}
         *     {@link JAXBElement }{@code <}{@link ClassificationNodeType }{@code >}
         *     {@link JAXBElement }{@code <}{@link ExternalLinkType }{@code >}
         *     {@link JAXBElement }{@code <}{@link RegistryPackageType }{@code >}
         *     {@link JAXBElement }{@code <}{@link AuditableEventType }{@code >}
         *     {@link JAXBElement }{@code <}{@link FederationType }{@code >}
         *     {@link JAXBElement }{@code <}{@link ExternalIdentifierType }{@code >}
         *     {@link JAXBElement }{@code <}{@link ServiceType }{@code >}
         *     {@link JAXBElement }{@code <}{@link IdentifiableType }{@code >}
         *     {@link JAXBElement }{@code <}{@link SubscriptionType }{@code >}
         *     {@link JAXBElement }{@code <}{@link ServiceBindingType }{@code >}
         *     {@link JAXBElement }{@code <}{@link AssociationType }{@code >}
         *     {@link JAXBElement }{@code <}{@link OrganizationType }{@code >}
         *     {@link JAXBElement }{@code <}{@link ExtrinsicObjectType }{@code >}
         *     {@link JAXBElement }{@code <}{@link ClassificationSchemeType }{@code >}
         *     {@link JAXBElement }{@code <}{@link SpecificationLinkType }{@code >}
         *     {@link JAXBElement }{@code <}{@link RegistryType }{@code >}
         *     {@link JAXBElement }{@code <}{@link PersonType }{@code >}
         *     {@link JAXBElement }{@code <}{@link ObjectRefType }{@code >}
         *     
         */
        @Transient
        public JAXBElement<? extends IdentifiableType> getItem() {
            return item;
        }

        /**
         * Sets the value of the item property.
         * 
         * @param value
         *     allowed object is
         *     {@link JAXBElement }{@code <}{@link AdhocQueryType }{@code >}
         *     {@link JAXBElement }{@code <}{@link UserType }{@code >}
         *     {@link JAXBElement }{@code <}{@link RegistryObjectType }{@code >}
         *     {@link JAXBElement }{@code <}{@link ClassificationType }{@code >}
         *     {@link JAXBElement }{@code <}{@link ClassificationNodeType }{@code >}
         *     {@link JAXBElement }{@code <}{@link ExternalLinkType }{@code >}
         *     {@link JAXBElement }{@code <}{@link RegistryPackageType }{@code >}
         *     {@link JAXBElement }{@code <}{@link AuditableEventType }{@code >}
         *     {@link JAXBElement }{@code <}{@link FederationType }{@code >}
         *     {@link JAXBElement }{@code <}{@link ExternalIdentifierType }{@code >}
         *     {@link JAXBElement }{@code <}{@link ServiceType }{@code >}
         *     {@link JAXBElement }{@code <}{@link IdentifiableType }{@code >}
         *     {@link JAXBElement }{@code <}{@link SubscriptionType }{@code >}
         *     {@link JAXBElement }{@code <}{@link ServiceBindingType }{@code >}
         *     {@link JAXBElement }{@code <}{@link AssociationType }{@code >}
         *     {@link JAXBElement }{@code <}{@link OrganizationType }{@code >}
         *     {@link JAXBElement }{@code <}{@link ExtrinsicObjectType }{@code >}
         *     {@link JAXBElement }{@code <}{@link ClassificationSchemeType }{@code >}
         *     {@link JAXBElement }{@code <}{@link SpecificationLinkType }{@code >}
         *     {@link JAXBElement }{@code <}{@link RegistryType }{@code >}
         *     {@link JAXBElement }{@code <}{@link PersonType }{@code >}
         *     {@link JAXBElement }{@code <}{@link ObjectRefType }{@code >}
         *     
         */
        public void setItem(JAXBElement<? extends IdentifiableType> value) {
            this.item = ((JAXBElement<? extends IdentifiableType> ) value);
        }

        /**
         * Gets the value of the hjid property.
         * 
         * @return
         *     possible object is
         *     {@link Long }
         *     
         */
        @Id
        @GeneratedValue(strategy = GenerationType.AUTO)
        @Column(name = "Hjid")
        public Long getHjid() {
            return hjid;
        }

        /**
         * Sets the value of the hjid property.
         * 
         * @param value
         *     allowed object is
         *     {@link Long }
         *     
         */
        public void setHjid(Long value) {
            this.hjid = value;
        }

        @Basic
        @Column(name = "ItemName")
        public String getItemName() {
            if (this.item instanceof JAXBElement) {
                return JAXBElementUtils.getName(((JAXBElement<? extends IdentifiableType> ) this.item));
            } else {
                return null;
            }
        }

        public void setItemName(String target) {
            if (target!= null) {
                this.item = JAXBElementUtils.wrap(this.item, target, IdentifiableType.class);
            }
        }

        @ManyToOne(cascade = {
            CascadeType.ALL
        })
        public IdentifiableType getItemValue() {
            if (this.item instanceof JAXBElement) {
                return JAXBElementUtils.getValue(((JAXBElement<? extends IdentifiableType> ) this.item));
            } else {
                return null;
            }
        }

        public void setItemValue(IdentifiableType target) {
            if (target!= null) {
                this.item = JAXBElementUtils.wrap(this.item, target);
            }
        }

    }

}