(no commit message)
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / common / CdmBase.java
index f2a8df1d6ae8843bcc15f11551c63b3123fc2d01..1f611e66be6da3714fb67cb662212f8cacbaa843 100644 (file)
@@ -18,6 +18,18 @@ import javax.persistence.Temporal;
 import javax.persistence.TemporalType;
 import javax.persistence.Transient;
 
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlID;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlSchemaType;
+import javax.xml.bind.annotation.XmlTransient;
+import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.adapters.CollapsedStringAdapter;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+
 import org.hibernate.annotations.Cascade;
 import org.hibernate.annotations.CascadeType;
 
@@ -39,13 +51,20 @@ import eu.etaxonomy.cdm.model.agent.Person;
  * @author m.doering
  *
  */
+@XmlAccessorType(XmlAccessType.PROPERTY)
+@XmlType(name = "CdmBase", propOrder = {
+    "created",
+    "createdBy"
+})
+@XmlRootElement(name = "CdmBase")
 @MappedSuperclass
 public abstract class CdmBase implements Serializable, ICdmBase{
+
        private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
        private int id;
-       private UUID uuid;
+    private UUID uuid;
        private Calendar created;
-       private Person createdBy;
+    private Person createdBy;
 
        /**
         * Class constructor assigning a unique UUID and creation date.
@@ -109,27 +128,14 @@ public abstract class CdmBase implements Serializable, ICdmBase{
                propertyChangeSupport.firePropertyChange(evt);
        }
 
-       /* (non-Javadoc)
-        * @see eu.etaxonomy.cdm.model.common.ICdmBase#getId()
-        */
-       @Id
-       @GeneratedValue(generator = "system-increment")
-       public int getId() {
-               return this.id;
-       }
-       /* (non-Javadoc)
-        * @see eu.etaxonomy.cdm.model.common.ICdmBase#setId(int)
-        */
-       public void setId(int id) {
-               this.id = id;
-       }
-
-       
        /**
         * Method for hibernate only to read the UUID value as a simple string from the object and persist it (e.g. in a database).
         * For reading the UUID please use getUuid method
         * @return String representation of the UUID
         */
+       @XmlAttribute(name = "uuid", required = true)
+       @XmlID
+       @XmlSchemaType(name = "ID")
        private String getStrUuid() {
                return this.uuid.toString();
        }
@@ -142,9 +148,26 @@ public abstract class CdmBase implements Serializable, ICdmBase{
        }
        
        
+       /* (non-Javadoc)
+        * @see eu.etaxonomy.cdm.model.common.ICdmBase#getId()
+        */
+       @XmlAttribute(name = "id", required = true)
+       @Id
+       @GeneratedValue(generator = "system-increment")
+       public int getId() {
+               return this.id;
+       }
+       /* (non-Javadoc)
+        * @see eu.etaxonomy.cdm.model.common.ICdmBase#setId(int)
+        */
+       public void setId(int id) {
+               this.id = id;
+       }
+
        /* (non-Javadoc)
         * @see eu.etaxonomy.cdm.model.common.ICdmBase#getUuid()
         */
+    @XmlTransient
        @Transient
        public UUID getUuid() {
                return this.uuid;
@@ -160,6 +183,7 @@ public abstract class CdmBase implements Serializable, ICdmBase{
        /* (non-Javadoc)
         * @see eu.etaxonomy.cdm.model.common.ICdmBase#getCreated()
         */
+       @XmlElement (name = "Created")
        @Temporal(TemporalType.TIMESTAMP)
        @Basic(fetch = FetchType.LAZY)
        public Calendar getCreated() {
@@ -179,6 +203,7 @@ public abstract class CdmBase implements Serializable, ICdmBase{
        /* (non-Javadoc)
         * @see eu.etaxonomy.cdm.model.common.ICdmBase#getCreatedBy()
         */
+       @XmlElement (name = "CreatedBy")
        @ManyToOne(fetch=FetchType.LAZY)
        @Cascade( { CascadeType.SAVE_UPDATE })
        public Person getCreatedBy() {
@@ -258,11 +283,39 @@ public abstract class CdmBase implements Serializable, ICdmBase{
        
        protected void invokeSetMethodWithNull(Method method, Object object){
                try {
-                       method.invoke(object, null);
+                       Object[] nul = new Object[]{null}; 
+                       method.invoke(object, nul);
                } catch (Exception e) {
                        e.printStackTrace();
                        //TODO handle exceptioin;
                }
        }
        
+//********************** CLONE *****************************************/
+       
+       protected void clone(CdmBase clone){
+               clone.setCreatedBy(createdBy);
+               clone.setId(id);
+               //Constructor Attributes
+               //clone.setCreated(created);
+               //clone.setUuid(getUuid());
+
+       }
+       
+       /* (non-Javadoc)
+        * @see java.lang.Object#clone()
+        */
+       public Object clone() throws CloneNotSupportedException{
+               CdmBase result = (CdmBase)super.clone();
+               
+               //TODO ?
+               result.setId(0);
+               result.setUuid(UUID.randomUUID());
+               result.setCreated(Calendar.getInstance());
+               result.setCreatedBy(null);
+               
+               //no changes to: -
+               return result;
+       }
+       
 }