gov.nih.nci.cbiit.cmts.core.ElementMeta.java Source code

Java tutorial

Introduction

Here is the source code for gov.nih.nci.cbiit.cmts.core.ElementMeta.java

Source

/*L
 * Copyright SAIC, SAIC-Frederick.
 *
 * Distributed under the OSI-approved BSD 3-Clause License.
 * See http://ncip.github.com/caadapter/LICENSE.txt for details.
 */

//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.3 in JDK 1.6 
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 
// Any modifications to this file will be lost upon recompilation of the source schema. 
// Generated on: 2008.12.23 at 11:43:13 AM EST 
//

package gov.nih.nci.cbiit.cmts.core;

import gov.nih.nci.cbiit.cmts.ui.properties.PropertiesResult;

import java.beans.PropertyDescriptor;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlType;

import org.apache.commons.beanutils.BeanUtils;

/**
 * <p>Java class for elementMeta complex type.
 * 
 * <p>The following schema fragment specifies the expected content contained within this class.
 * 
 * <pre>
 * &lt;complexType name="elementMeta">
 *   &lt;complexContent>
 *     &lt;extension base="{http://cmts.cbiit.nci.nih.gov/core}baseMeta">
 *       &lt;sequence>
 *         &lt;element name="attrData" type="{http://cmts.cbiit.nci.nih.gov/core}attributeMeta" maxOccurs="unbounded" minOccurs="0"/>
 *         &lt;element name="childElement" type="{http://cmts.cbiit.nci.nih.gov/core}elementMeta" maxOccurs="unbounded" minOccurs="0"/>
 *       &lt;/sequence>
 *       &lt;attribute name="multiplicityIndex" type="{http://www.w3.org/2001/XMLSchema}integer" />
 *       &lt;attribute name="isSimple" type="{http://www.w3.org/2001/XMLSchema}boolean" />
 *       &lt;attribute name="isRequired" type="{http://www.w3.org/2001/XMLSchema}boolean" />
 *       &lt;attribute name="isEnabled" type="{http://www.w3.org/2001/XMLSchema}boolean" />
 *       &lt;attribute name="isChoice" type="{http://www.w3.org/2001/XMLSchema}boolean" />
 *       &lt;attribute name="isValid" type="{http://www.w3.org/2001/XMLSchema}boolean" />
 *       &lt;attribute name="isRecursive" type="{http://www.w3.org/2001/XMLSchema}boolean" />
 *       &lt;attribute name="isFixed" type="{http://www.w3.org/2001/XMLSchema}boolean" />
 *       &lt;attribute name="defaultValue" type="{http://www.w3.org/2001/XMLSchema}string" />
 *       &lt;attribute name="concreteDataType" type="{http://www.w3.org/2001/XMLSchema}string" />
 *       &lt;attribute name="minOccurs" type="{http://www.w3.org/2001/XMLSchema}integer" />
 *       &lt;attribute name="maxOccurs" type="{http://www.w3.org/2001/XMLSchema}integer" />
 *     &lt;/extension>
 *   &lt;/complexContent>
 * &lt;/complexType>
 * </pre>
 * 
 * 
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "elementMeta", propOrder = { "attrData", "childElement" })
public class ElementMeta extends BaseMeta {

    protected List<AttributeMeta> attrData;
    protected List<ElementMeta> childElement;
    @XmlAttribute
    protected Boolean isChoice = false;
    @XmlAttribute
    protected Boolean isChosen = false;
    @XmlAttribute
    protected Boolean isEnabled = false;
    @XmlAttribute
    protected Boolean isRecursive = false;
    @XmlAttribute
    protected Boolean isSimple = true;
    @XmlAttribute
    protected BigInteger maxOccurs;
    @XmlAttribute
    protected BigInteger minOccurs;
    @XmlAttribute
    protected BigInteger multiplicityIndex;
    @XmlAttribute
    protected String concreteDataType;
    @XmlAttribute
    protected String defaultValue;

    /**
     * Gets the value of the attrData 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 attrData property.
     * 
     * <p>
     * For example, to add a new item, do as follows:
     * <pre>
     *    getAttrData().add(newItem);
     * </pre>
     * 
     * 
     * <p>
     * Objects of the following type(s) are allowed in the list
     * {@link AttributeMeta }
     * 
     * 
     */
    public List<AttributeMeta> getAttrData() {
        if (attrData == null) {
            attrData = new ArrayList<AttributeMeta>();
        }
        return this.attrData;
    }

    /**
     * Gets the value of the childElement 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 childElement property.
     * 
     * <p>
     * For example, to add a new item, do as follows:
     * <pre>
     *    getChildElement().add(newItem);
     * </pre>
     * 
     * 
     * <p>
     * Objects of the following type(s) are allowed in the list
     * {@link ElementMeta }
     * 
     * 
     */
    public List<ElementMeta> getChildElement() {
        if (childElement == null) {
            childElement = new ArrayList<ElementMeta>();
        }
        return this.childElement;
    }

    /**
     * Gets the value of the maxOccurs property.
     * 
     * @return
     *     possible object is
     *     {@link BigInteger }
     *     
     */
    public BigInteger getMaxOccurs() {
        return maxOccurs;
    }

    /**
     * Gets the value of the minOccurs property.
     * 
     * @return
     *     possible object is
     *     {@link BigInteger }
     *     
     */
    public BigInteger getMinOccurs() {
        return minOccurs;
    }

    /**
     * Gets the value of the multiplicityIndex property.
     *
     * @return
     *     possible object is
     *     {@link BigInteger }
     *
     */
    public BigInteger getMultiplicityIndex() {
        return multiplicityIndex;
    }

    /**
     * Gets the value of the concrete data type property.
     *
     * @return
     *     possible object is
     *     {@link String }
     *
     */
    public String getConcreteDataType() {
        return concreteDataType;
    }

    @Override
    public String getName() {
        if (getMultiplicityIndex() == null)
            return super.getName();
        return super.getName() + "[" + getMultiplicityIndex() + "]";
    }

    @Override
    public PropertiesResult getPropertyDescriptors() throws Exception {
        Class<?> beanClass = this.getClass();
        List<PropertyDescriptor> propList = new ArrayList<PropertyDescriptor>();

        propList.add(new PropertyDescriptor("Choice Element", beanClass, "isIsChoice", null));
        propList.add(new PropertyDescriptor("Chosen", beanClass, "isIsChosen", null));
        propList.add(new PropertyDescriptor("Enabled", beanClass, "isIsEnabled", null));
        propList.add(new PropertyDescriptor("minOccurs", beanClass, "getMinOccurs", null));
        propList.add(new PropertyDescriptor("maxOccurs", beanClass, "getMaxOccurs", null));
        propList.add(new PropertyDescriptor("Multiplicity Index", beanClass, "getMultiplicityIndex", null));
        propList.add(new PropertyDescriptor("Recursive", beanClass, "isIsRecursive", null));
        propList.add(new PropertyDescriptor("Simple Type", beanClass, "isIsSimple", null));

        if (concreteDataType != null)
            propList.add(new PropertyDescriptor("Concrete Data Type", beanClass, "getConcreteDataType", null));
        propList.add(new PropertyDescriptor("Annotation", beanClass, "getAnnotationString", null));
        propList.add(new PropertyDescriptor("Documentation", beanClass, "getDocumentation", null));
        propList.add(new PropertyDescriptor("Application Info", beanClass, "getAppInfo", null));
        PropertiesResult result = super.getPropertyDescriptors();
        result.addPropertyDescriptors(this, propList);
        return result;
    }

    public String getTitle() {
        // TODO Auto-generated method stub
        return "Element Properties";
    }

    /**
     * Gets the value of the isChosen property.
     * 
     * @return
     *     possible object is
     *     {@link Boolean }
     *     
     */
    public Boolean isIsChosen() {
        return isChosen;
    }

    /**
     * Gets the value of the isChoice property.
     * 
     * @return
     *     possible object is
     *     {@link Boolean }
     *     
     */
    public Boolean isIsChoice() {
        return isChoice;
    }

    /**
     * Gets the value of the isEnabled property.
     * 
     * @return
     *     possible object is
     *     {@link Boolean }
     *     
     */
    public Boolean isIsEnabled() {
        return isEnabled;
    }

    /**
     * Gets the value of the isRecursive property.
     * 
     * @return
     *     possible object is
     *     {@link Boolean }
     *     
     */
    public Boolean isIsRecursive() {
        return isRecursive;
    }

    /**
     * Gets the value of the isSimple property.
     * 
     * @return
     *     possible object is
     *     {@link Boolean }
     *     
     */
    public Boolean isIsSimple() {
        return isSimple;
    }

    /**
     * Sets the value of the isChosen property.
     * 
     * @param chosen
     *     allowed object is
     *     {@link Boolean }
     *     
     */
    public void setIsChosen(Boolean chosen) {
        this.isChosen = chosen;
    }

    /**
     * Sets the value of the isChoice property.
     * 
     * @param value
     *     allowed object is
     *     {@link Boolean }
     *     
     */
    public void setIsChoice(Boolean value) {
        this.isChoice = value;
    }

    /**
     * Sets the value of the isEnabled property.
     * 
     * @param value
     *     allowed object is
     *     {@link Boolean }
     *     
     */
    public void setIsEnabled(Boolean value) {
        this.isEnabled = value;
    }

    /**
     * Sets the value of the isRecursive property.
     * 
     * @param value
     *     allowed object is
     *     {@link Boolean }
     *     
     */
    public void setIsRecursive(Boolean value) {
        this.isRecursive = value;
    }

    /**
     * Sets the value of the isSimple property.
     * 
     * @param value
     *     allowed object is
     *     {@link Boolean }
     *     
     */
    public void setIsSimple(Boolean value) {
        this.isSimple = value;
    }

    /**
     * Sets the value of the maxOccurs property.
     * 
     * @param value
     *     allowed object is
     *     {@link BigInteger }
     *     
     */
    public void setMaxOccurs(BigInteger value) {
        this.maxOccurs = value;
    }

    /**
     * Sets the value of the minOccurs property.
     * 
     * @param value
     *     allowed object is
     *     {@link BigInteger }
     *     
     */
    public void setMinOccurs(BigInteger value) {
        this.minOccurs = value;
    }

    /**
     * Sets the value of the concrete data type for v3.
     *
     * @param value
     *     allowed object is
     *     {@link String }
     *
     */
    public void setConcreteDataType(String value) {
        this.concreteDataType = value;
    }

    /**
     * Sets the value of the multiplicityIndex property.
     * 
     * @param value
     *     allowed object is
     *     {@link BigInteger }
     *     
     */
    public void setMultiplicityIndex(BigInteger value) {
        this.multiplicityIndex = value;
    }

    /// inserted by umkis for determining if CDE attributes
    public boolean isCDE_Element() {
        List<AttributeMeta> fields = this.getAttrData();

        boolean publicidExist = false;
        boolean versionExist = false;
        for (int i = 0; i < fields.size(); i++) {
            AttributeMeta fieldMeta = fields.get(i);
            if (fieldMeta.getName().equals("PUBLICID"))
                publicidExist = true;
            if (fieldMeta.getName().equals("VERSION"))
                versionExist = true;
        }

        if (publicidExist && versionExist)
            return true;
        return false;
    }

    @Override
    public String toString() {
        StringBuffer rtBuffer = new StringBuffer();
        rtBuffer.append(super.toString());
        if (getMinOccurs() == null)
            return rtBuffer.toString();

        rtBuffer.append("[" + getMinOccurs() + "...");
        if (getMaxOccurs() != null && getMaxOccurs().intValue() == -1)
            rtBuffer.append("*]");
        else
            rtBuffer.append(getMaxOccurs() + "]");
        return rtBuffer.toString();
    }

    @Override
    public Object clone() {
        try {
            //         ElementMeta clonnedObj=(ElementMeta)super.clone();
            ElementMeta clonnedObj = (ElementMeta) BeanUtils.cloneBean(this);
            clonnedObj.setIsChosen(false);
            clonnedObj.setIsChoice(this.isIsChoice());
            clonnedObj.setIsEnabled(this.isIsEnabled());
            clonnedObj.setIsRecursive(this.isIsRecursive());
            clonnedObj.setRequired(this.isRequired());
            clonnedObj.setIsSimple(this.isIsSimple());

            for (AttributeMeta attrMeta : this.getAttrData()) {
                clonnedObj.getAttrData().add((AttributeMeta) attrMeta.clone());
            }

            //deep cloning of all children elements
            //clone all child elements and add them to the cloned Element meta
            //deep cloning will be terminated if no child element exist

            for (ElementMeta childMeta : this.getChildElement()) {
                clonnedObj.getChildElement().add((ElementMeta) childMeta.clone());
            }

            return clonnedObj;
        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }
        return null;
    }
}