merging branches/cdmlib/2.2 [7345:7377] to trunk
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / name / NameTypeDesignation.java
index 2cbeba844d09e969e17e70a56cf67df80fcc26bf..df57551d996c0a4951f127c4c7d52aa46e3be6e0 100644 (file)
 
 package eu.etaxonomy.cdm.model.name;
 
-
 import javax.persistence.Entity;
+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.XmlIDREF;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlSchemaType;
 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;
 
 /**
- * The class representing a typification of a {@link TaxonNameBase taxon name} with
- * a {@link Rank rank} above "species aggregate" by a species taxon name. A type of a
- * genus name or of any subdivision of a genus can only be a species name.
- * A type of a family name or of any subdivision of a family is a genus name 
- * (and resolving it: a species name typifying this genus).
- * Moreover the designation of a particular species name as a type for a
- * suprageneric taxon name might be nomenclaturally rejected or conserved.
- * Depending on the date of publication, the same typification could be rejected
- * according to one reference and later be conserved according to another
- * reference, but a name type designation cannot be simultaneously rejected and
- * conserved. Both names, the typified name and the species name used in
- * the name type designation, must belong to the same {@link HomotypicalGroup homotypical group}.
+ * The class representing a typification of a {@link TaxonNameBase taxon name} with a {@link Rank rank}
+ * above "species aggregate" by another taxon name.<BR>
+ * According to nomenclature a type of a genus name or of any subdivision of a
+ * genus can only be a species name. A type of a family name or of any
+ * subdivision of a family is a genus name.<BR>
+ * Moreover the designation of a particular taxon name as a type might be
+ * nomenclaturally rejected or conserved. Depending on the date of publication,
+ * the same typification could be rejected according to one reference and later
+ * be conserved according to another reference, but a name type designation
+ * cannot be simultaneously rejected and conserved.<BR>
+ * Name type designations are treated as {@link TypeDesignationBase type designations}
+ * and not as {@link NameRelationship name relationships}.
  * 
+ * @see                TypeDesignationBase
  * @see                SpecimenTypeDesignation
  * @author     m.doering
  * @version 1.0
  * @created 08-Nov-2007 13:06:38
  */
-@XmlType(name="NameTypeDesignation")
+@XmlRootElement(name = "NameTypeDesignation")
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "NameTypeDesignation", propOrder = {
+    "rejectedType",
+    "conservedType",
+    /*"lectoType",*/
+    "typeName"
+})
 @Entity
-public class NameTypeDesignation extends ReferencedEntityBase {
-       static Logger logger = Logger.getLogger(NameTypeDesignation.class);
-       private boolean isRejectedType;
-       private boolean isConservedType;
-       private boolean isLectoType;
-       private ReferenceBase lectoTypeReference;
-       private String lectoTypeMicroReference;
-       private boolean isNotDesignated;
-       private TaxonNameBase typeSpecies;
-       private TaxonNameBase typifiedName;
+@Audited
+public class NameTypeDesignation extends TypeDesignationBase<NameTypeDesignationStatus> 
+implements ITypeDesignation {
+       
+       final static Logger logger = Logger.getLogger(NameTypeDesignation.class);
+       
+       @XmlElement(name = "IsRejectedType")
+       private boolean rejectedType;
+       
+       @XmlElement(name = "IsConservedType")
+       private boolean conservedType;
+       
+//     @XmlElement(name = "IsLectoType")
+//     private boolean lectoType;
+       
+       @XmlElement(name = "TypeName")
+       @XmlIDREF
+       @XmlSchemaType(name = "IDREF")
+       @ManyToOne(fetch = FetchType.LAZY)
+       @Cascade(CascadeType.SAVE_UPDATE)
+       private TaxonNameBase typeName;
+
+       
+       public static NameTypeDesignation NewInstance() {
+               return new NameTypeDesignation();
+       }
+       
        
        // ************* CONSTRUCTORS *************/    
        /** 
         * Class constructor: creates a new empty name type designation.
         * 
-        * @see #NameTypeDesignation(TaxonNameBase, TaxonNameBase, ReferenceBase, String, String, boolean, boolean)
+        * @see #NameTypeDesignation(TaxonNameBase, ReferenceBase, String, String, boolean, boolean, boolean)
         */
        protected NameTypeDesignation() {
-               super();
        }
 
+
        /**
         * Class constructor: creates a new name type designation instance
-        * (including its {@link reference.ReferenceBase reference source} and eventually
+        * (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) and adds it to the corresponding 
-        * {@link TaxonNameBase#getNameTypeDesignations() name type designation set} of the typified name.
-        * The typified name will be added to the {@link HomotypicalGroup homotypical group} to which
-        * the species taxon name used for the typification belongs. 
+        * the former designation).
         * 
-        * @param typifiedName                  the suprageneric taxon name to be typified
-        * @param typeSpecies                   the species taxon name typifying the suprageneric taxon name 
+        * @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
-        *                                                              this name type designation
+        *                                                              <i>this</i> name type designation
         * @param isConservedType               the boolean flag indicating whether the competent authorities conserved
-        *                                                              this name type designation
-        * @param isNotDesignated               see at {@link #isNotDesignated()}
+        *                                                              <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                                                 TaxonNameBase#addNameTypeDesignation(TaxonNameBase, ReferenceBase, String, String, boolean, boolean)
+        * @see                                                 TypeDesignationBase#isNotDesignated()
+        * @see                                                 TaxonNameBase#addNameTypeDesignation(TaxonNameBase, ReferenceBase, String, String, boolean, boolean, boolean, boolean, boolean)
         */
-       protected NameTypeDesignation(TaxonNameBase typifiedName, TaxonNameBase typeSpecies, ReferenceBase citation, String citationMicroReference,
-                       String originalNameString, boolean isRejectedType, boolean isConservedType, boolean isNotDesignated) {
+       protected NameTypeDesignation(TaxonNameBase typeName, NameTypeDesignationStatus status,
+                       ReferenceBase citation, String citationMicroReference, String originalNameString) {
                super(citation, citationMicroReference, originalNameString);
-               this.setTypeSpecies(typeSpecies);
-               this.setTypifiedName(typifiedName);
-               typifiedName.setHomotypicalGroup(typeSpecies.getHomotypicalGroup());
-               this.isRejectedType = isRejectedType;
-               this.isConservedType = isConservedType;
-               this.isNotDesignated = isNotDesignated;
+               this.setTypeName(typeName);
+               this.setTypeStatus(status);
        }
-               
-       //********* METHODS **************************************/
 
-       /** 
-        * Returns the {@link TaxonNameBase taxon name} that plays the role of the
-        * typified taxon name in this taxon name type designation. The {@link Rank rank}
-        * of a taxon name typified by another taxon name must be higher than
-        * "species aggregate".
-        *  
-        * @see   #getTypeSpecies()
-        */
-       @ManyToOne
-       @Cascade({CascadeType.SAVE_UPDATE})
-       public TaxonNameBase getTypifiedName() {
-               return typifiedName;
-       }
        /**
-        * @see  #getTypifiedName()
-        */
-       private void setTypifiedName(TaxonNameBase typifiedName) {
-               this.typifiedName = typifiedName;
-               if (typifiedName != null){
-                       typifiedName.getNameTypeDesignations().add(this);
-               }
+        * 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 **************************************/
 
 
        /** 
         * Returns the {@link TaxonNameBase taxon name} that plays the role of the
-        * taxon name type in this taxon name type designation. The {@link Rank rank}
-        * of a taxon name type must be "species".
-        *  
-        * @see   #getTypifiedName()
+        * 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 getTypeSpecies(){
-               return this.typeSpecies;
+       public TaxonNameBase getTypeName(){
+               return this.typeName;
        }
        /**
-        * @see  #getTypeSpecies()
+        * @see  #getTypeName()
         */
-       private void setTypeSpecies(TaxonNameBase typeSpecies){
-               this.typeSpecies = typeSpecies;
+       public void setTypeName(TaxonNameBase typeName){
+               this.typeName = typeName;
        }
 
        /** 
         * Returns the boolean value "true" if the competent authorities decided to
-        * reject the use of the species taxon name for this taxon name type
-        * designation.
+        * reject the use of the species taxon name as the type for <i>this</i> taxon
+        * name type designation.
         *  
         * @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;
        }
 
        /** 
         * Returns the boolean value "true" if the competent authorities decided to
-        * conserve the use of the species taxon name for this taxon name type
-        * designation.
+        * conserve the use of the species taxon name as the type for <i>this</i> taxon
+        * name type designation.
         *  
-        * @see   #isConservedType()
+        * @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;
        }
 
-       /**
-        * @return the isLectoType
-        */
+       @Transient
        public boolean isLectoType() {
-               return isLectoType;
-       }
-
-       /**
-        * @param isLectoType the isLectoType to set
-        */
-       public void setLectoType(boolean isLectoType) {
-               this.isLectoType = isLectoType;
-       }
-
-       /**
-        * @return the lectoTypeReference
-        */
-       public ReferenceBase getLectoTypeReference() {
-               return lectoTypeReference;
-       }
-
-       /**
-        * @param lectoTypeReference the lectoTypeReference to set
-        */
-       public void setLectoTypeReference(ReferenceBase lectoTypeReference) {
-               this.lectoTypeReference = lectoTypeReference;
-       }
-
-       /**
-        * @return the lectoTypeMicroReference
-        */
-       public String getLectoTypeMicroReference() {
-               return lectoTypeMicroReference;
-       }
-
-       /**
-        * @param lectoTypeMicroReference the lectoTypeMicroReference to set
-        */
-       public void setLectoTypeMicroReference(String lectoTypeMicroReference) {
-               this.lectoTypeMicroReference = lectoTypeMicroReference;
-       }
-
-       /**
-        * If true this indicates that a name type does not exist.
-        * This is differentiate that <BR> 
-        *      a) it is unknown if a name type exists and <BR>
-        *  b) it is known that no name type exists <BR>
-        *  If b is true there should be a NameTypeDesignation with <code>isNotDesignate == true</code> 
-        * The typeSpecies should be <code>null</code> then.
-        * @return the notDesignated
-        */
-       public boolean isNotDesignated() {
-               return isNotDesignated;
-       }
-
-       /**
-        * @param notDesignated the notDesignated to set
-        */
-       public void setNotDesignated(boolean isNotDesignated) {
-               this.isNotDesignated = isNotDesignated;
+               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
+        * publication of the typified taxon name. In this case the taxon name type
+        * designation should have a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase reference} that is different to the
+        * {@link TaxonNameBase#getNomenclaturalReference() nomenclatural reference} of the typified taxon name.
+        *  
+        * @see   ReferencedEntityBase#getCitation()
+        */
+//     /* (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