merging branches/cdmlib/2.2 [7345:7377] to trunk
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / name / NameTypeDesignation.java
index a2968c39c04491534bc675827b43a44b862d61de..df57551d996c0a4951f127c4c7d52aa46e3be6e0 100644 (file)
@@ -9,18 +9,13 @@
 
 package eu.etaxonomy.cdm.model.name;
 
-
-import java.util.HashSet;
-import java.util.Set;
-
 import javax.persistence.Entity;
-import javax.persistence.ManyToMany;
+import javax.persistence.FetchType;
 import javax.persistence.ManyToOne;
 import javax.persistence.Transient;
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlElementWrapper;
 import javax.xml.bind.annotation.XmlIDREF;
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlSchemaType;
@@ -29,8 +24,8 @@ import javax.xml.bind.annotation.XmlType;
 import org.apache.log4j.Logger;
 import org.hibernate.annotations.Cascade;
 import org.hibernate.annotations.CascadeType;
+import org.hibernate.envers.Audited;
 
-import eu.etaxonomy.cdm.model.common.ReferencedEntityBase;
 import eu.etaxonomy.cdm.model.reference.ReferenceBase;
 
 /**
@@ -56,35 +51,38 @@ import eu.etaxonomy.cdm.model.reference.ReferenceBase;
 @XmlRootElement(name = "NameTypeDesignation")
 @XmlAccessorType(XmlAccessType.FIELD)
 @XmlType(name = "NameTypeDesignation", propOrder = {
-    "isRejectedType",
-    "isConservedType",
-    "isLectoType",
+    "rejectedType",
+    "conservedType",
+    /*"lectoType",*/
     "typeName"
 })
 @Entity
-public class NameTypeDesignation extends TypeDesignationBase implements ITypeDesignation {
+@Audited
+public class NameTypeDesignation extends TypeDesignationBase<NameTypeDesignationStatus> 
+implements ITypeDesignation {
        
-       static Logger logger = Logger.getLogger(NameTypeDesignation.class);
+       final static Logger logger = Logger.getLogger(NameTypeDesignation.class);
        
        @XmlElement(name = "IsRejectedType")
-       private boolean isRejectedType;
+       private boolean rejectedType;
        
        @XmlElement(name = "IsConservedType")
-       private boolean isConservedType;
+       private boolean conservedType;
        
-       @XmlElement(name = "IsLectoType")
-       private boolean isLectoType;
+//     @XmlElement(name = "IsLectoType")
+//     private boolean lectoType;
        
        @XmlElement(name = "TypeName")
        @XmlIDREF
        @XmlSchemaType(name = "IDREF")
+       @ManyToOne(fetch = FetchType.LAZY)
+       @Cascade(CascadeType.SAVE_UPDATE)
        private TaxonNameBase typeName;
+
        
-//     @XmlElement(name = "HomotypicalGroup")
-//     @XmlIDREF
-//     @XmlSchemaType(name = "IDREF")
-//     private HomotypicalGroup homotypicalGroup;
-       
+       public static NameTypeDesignation NewInstance() {
+               return new NameTypeDesignation();
+       }
        
        
        // ************* CONSTRUCTORS *************/    
@@ -94,9 +92,9 @@ public class NameTypeDesignation extends TypeDesignationBase implements ITypeDes
         * @see #NameTypeDesignation(TaxonNameBase, ReferenceBase, String, String, boolean, boolean, boolean)
         */
        protected NameTypeDesignation() {
-               super();
        }
 
+
        /**
         * Class constructor: creates a new name type designation instance
         * (including its {@link eu.etaxonomy.cdm.model.reference.ReferenceBase reference source} and eventually
@@ -117,12 +115,46 @@ public class NameTypeDesignation extends TypeDesignationBase implements ITypeDes
         * @see                                                 TypeDesignationBase#isNotDesignated()
         * @see                                                 TaxonNameBase#addNameTypeDesignation(TaxonNameBase, ReferenceBase, String, String, boolean, boolean, boolean, boolean, boolean)
         */
-       protected NameTypeDesignation(TaxonNameBase typeName, ReferenceBase citation, String citationMicroReference,
-                       String originalNameString, boolean isRejectedType, boolean isConservedType, boolean isNotDesignated) {
-               super(citation, citationMicroReference, originalNameString, isNotDesignated);
+       protected NameTypeDesignation(TaxonNameBase typeName, NameTypeDesignationStatus status,
+                       ReferenceBase citation, String citationMicroReference, String originalNameString) {
+               super(citation, citationMicroReference, originalNameString);
                this.setTypeName(typeName);
-               this.isRejectedType = isRejectedType;
-               this.isConservedType = isConservedType;
+               this.setTypeStatus(status);
+       }
+
+       /**
+        * Class constructor: creates a new name type designation instance
+        * (including its {@link eu.etaxonomy.cdm.model.reference.ReferenceBase reference source} and eventually
+        * the taxon name string originally used by this reference when establishing
+        * the former designation).
+        * 
+        * @param typeName                              the taxon name used as a type 
+        * @param citation                              the reference source for the new designation
+        * @param citationMicroReference        the string with the details describing the exact localisation within the reference
+        * @param originalNameString    the taxon name string used originally in the reference source for the new designation
+        * @param isRejectedType                the boolean flag indicating whether the competent authorities rejected
+        *                                                              <i>this</i> name type designation
+        * @param isConservedType               the boolean flag indicating whether the competent authorities conserved
+        *                                                              <i>this</i> name type designation
+        * @param isNotDesignated               the boolean flag indicating whether there is no name type at all for 
+        *                                                              <i>this</i> name type designation
+        * @see                                                 #NameTypeDesignation()
+        * @see                                                 TypeDesignationBase#isNotDesignated()
+        * @see                                                 TaxonNameBase#addNameTypeDesignation(TaxonNameBase, ReferenceBase, String, String, boolean, boolean, boolean, boolean, boolean)
+        */
+       protected NameTypeDesignation(  TaxonNameBase typeName, 
+                                                                       ReferenceBase citation, 
+                                                                       String citationMicroReference,
+                                                                       String originalNameString, 
+                                                                       NameTypeDesignationStatus status, 
+                                                                       boolean rejectedType, 
+                                                                       boolean conservedType, 
+                                                                       boolean isNotDesignated
+                                                               ) {
+               this(typeName, status, citation, citationMicroReference, originalNameString);
+               this.setNotDesignated(isNotDesignated);
+               this.rejectedType = rejectedType;
+               this.conservedType = conservedType;
        }
                
        //********* METHODS **************************************/
@@ -133,15 +165,13 @@ public class NameTypeDesignation extends TypeDesignationBase implements ITypeDes
         * taxon name type in <i>this</i> taxon name type designation. The {@link Rank rank}
         * of the taxon name type must be "species".
         */
-       @ManyToOne
-       @Cascade({CascadeType.SAVE_UPDATE})
        public TaxonNameBase getTypeName(){
                return this.typeName;
        }
        /**
         * @see  #getTypeName()
         */
-       private void setTypeName(TaxonNameBase typeName){
+       public void setTypeName(TaxonNameBase typeName){
                this.typeName = typeName;
        }
 
@@ -153,13 +183,13 @@ public class NameTypeDesignation extends TypeDesignationBase implements ITypeDes
         * @see   #isConservedType()
         */
        public boolean isRejectedType(){
-               return this.isRejectedType;
+               return this.rejectedType;
        }
        /**
         * @see  #isRejectedType()
         */
-       public void setRejectedType(boolean isRejectedType){
-               this.isRejectedType = isRejectedType;
+       public void setRejectedType(boolean rejectedType){
+               this.rejectedType = rejectedType;
        }
 
        /** 
@@ -170,15 +200,23 @@ public class NameTypeDesignation extends TypeDesignationBase implements ITypeDes
         * @see   #isRejectedType()
         */
        public boolean isConservedType(){
-               return this.isConservedType;
+               return this.conservedType;
        }
        /**
         * @see  #isConservedType()
         */
-       public void setConservedType(boolean isConservedType){
-               this.isConservedType = isConservedType;
+       public void setConservedType(boolean conservedType){
+               this.conservedType = conservedType;
        }
 
+       @Transient
+       public boolean isLectoType() {
+               if (getTypeStatus() == null) {
+                       return false;
+               }
+               return getTypeStatus().isLectotype();
+       }
+       
        /** 
         * Returns the boolean value "true" if the use of the species {@link TaxonNameBase taxon name}
         * as the type for <i>this</i> taxon name type designation was posterior to the
@@ -188,18 +226,17 @@ public class NameTypeDesignation extends TypeDesignationBase implements ITypeDes
         *  
         * @see   ReferencedEntityBase#getCitation()
         */
-       /* (non-Javadoc)
-        * @see eu.etaxonomy.cdm.model.name.ITypeDesignation#isLectoType()
-        */
-       public boolean isLectoType() {
-               return isLectoType;
-       }
-
-       /**
-        * @see   #isLectoType()
-        */
-       public void setLectoType(boolean isLectoType) {
-               this.isLectoType = isLectoType;
-       }
-
+//     /* (non-Javadoc)
+//      * @see eu.etaxonomy.cdm.model.name.ITypeDesignation#isLectoType()
+//      */
+//     public boolean isLectoType() {
+//             return lectoType;
+//     }
+//
+//     /**
+//      * @see   #isLectoType()
+//      */
+//     public void setLectoType(boolean lectoType) {
+//             this.lectoType = lectoType;
+//     }
 }
\ No newline at end of file