(no commit message)
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / name / BotanicalName.java
index 09db62670d6db1892f78fa1964a9a8c4aaab7ce9..46c76b7a99bd4933e2055510eb4b7c927e6ca446 100644 (file)
@@ -14,16 +14,14 @@ import org.apache.log4j.Logger;
 import org.hibernate.annotations.Cascade;
 import org.hibernate.annotations.CascadeType;
 
-import eu.etaxonomy.cdm.model.agent.Agent;
-import eu.etaxonomy.cdm.model.agent.INomenclaturalAuthor;
 import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
+import eu.etaxonomy.cdm.model.common.RelationshipBase;
 import eu.etaxonomy.cdm.model.reference.INomenclaturalReference;
 import eu.etaxonomy.cdm.strategy.cache.BotanicNameDefaultCacheStrategy;
-import eu.etaxonomy.cdm.strategy.parser.TaxonNameParserBotanicalNameImpl;
+import eu.etaxonomy.cdm.strategy.parser.INonViralNameParser;
+import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl;
 
 import java.util.*;
-
-import javax.naming.NameParser;
 import javax.persistence.*;
 
 /**
@@ -34,7 +32,7 @@ import javax.persistence.*;
  */
 @Entity
 public class BotanicalName extends NonViralName {
-       static Logger logger = Logger.getLogger(BotanicalName.class);
+       private static final Logger logger = Logger.getLogger(BotanicalName.class);
        //if set: this name is a hybrid formula (a hybrid that does not have an own name) and no other hybrid flags may be set. A
        //hybrid name  may not have either an authorteam nor other name components.
        private boolean isHybridFormula = false;
@@ -45,12 +43,50 @@ public class BotanicalName extends NonViralName {
        private boolean isAnamorphic;
        private Set<HybridRelationship> hybridRelationships = new HashSet();
 
+       static private INonViralNameParser nameParser = new NonViralNameParserImpl();
+       
+       
        /**
         * @param rank
         * @return
         */
        public static BotanicalName NewInstance(Rank rank){
-               return new BotanicalName(rank);
+               return new BotanicalName(rank, null);
+       }
+
+
+       /**
+        * @param rank
+        * @param homotypicalGroup
+        * @return
+        */
+       public static BotanicalName NewInstance(Rank rank, HomotypicalGroup homotypicalGroup){
+               return new BotanicalName(rank, homotypicalGroup);
+       }
+       
+       public static  BotanicalName NewInstance(Rank rank, String genusOrUninomial, String specificEpithet, String infraSpecificEpithet, TeamOrPersonBase combinationAuthorTeam, INomenclaturalReference nomenclaturalReference, String nomenclMicroRef, HomotypicalGroup homotypicalGroup) {
+               return new BotanicalName(rank, genusOrUninomial, specificEpithet, infraSpecificEpithet, combinationAuthorTeam, nomenclaturalReference, nomenclMicroRef, homotypicalGroup);
+       }
+       
+       /**
+        * Returns a parsed Name
+        * @param fullName
+        * @return
+        */
+       public static BotanicalName PARSED_NAME(String fullNameString){
+               return PARSED_NAME(fullNameString, Rank.GENUS());
+       }
+       
+       /**
+        * Returns a parsed Name
+        * @param fullName
+        * @return
+        */
+       public static BotanicalName PARSED_NAME(String fullNameString, Rank rank){
+               if (nameParser == null){
+                       nameParser = new NonViralNameParserImpl();
+               }
+               return (BotanicalName)nameParser.parseFullName(fullNameString, NomenclaturalCode.ICBN(),  rank);
        }
        
        /**
@@ -58,8 +94,8 @@ public class BotanicalName extends NonViralName {
         * @param fullName
         * @return
         */
-       public static BotanicalName PARSED_NAME(String fullName){
-               return PARSED_NAME(fullName, Rank.GENUS());
+       public static BotanicalName PARSED_REFERENCE(String fullNameAndReferenceString){
+               return PARSED_REFERENCE(fullNameAndReferenceString, Rank.GENUS());
        }
        
        /**
@@ -67,11 +103,11 @@ public class BotanicalName extends NonViralName {
         * @param fullName
         * @return
         */
-       public static BotanicalName PARSED_NAME(String fullName, Rank rank){
+       public static BotanicalName PARSED_REFERENCE(String fullNameAndReferenceString, Rank rank){
                if (nameParser == null){
-                       nameParser = new TaxonNameParserBotanicalNameImpl();
+                       nameParser = new NonViralNameParserImpl();
                }
-               return (BotanicalName)nameParser.parseFullName(fullName, rank);
+               return (BotanicalName)nameParser.parseFullReference(fullNameAndReferenceString, NomenclaturalCode.ICBN(), rank);
        }
        
        //needed by hibernate
@@ -79,12 +115,12 @@ public class BotanicalName extends NonViralName {
                super();
                this.cacheStrategy = BotanicNameDefaultCacheStrategy.NewInstance();
        }
-       public BotanicalName(Rank rank) {
-               super(rank);
+       protected BotanicalName(Rank rank, HomotypicalGroup homotypicalGroup) {
+               super(rank, homotypicalGroup);
                this.cacheStrategy = BotanicNameDefaultCacheStrategy.NewInstance();
        }
-       public BotanicalName(Rank rank, String genusOrUninomial, String specificEpithet, String infraSpecificEpithet, TeamOrPersonBase combinationAuthorTeam, INomenclaturalReference nomenclaturalReference, String nomenclMicroRef) {
-               super(rank, genusOrUninomial, specificEpithet, infraSpecificEpithet, combinationAuthorTeam, nomenclaturalReference, nomenclMicroRef);
+       protected BotanicalName(Rank rank, String genusOrUninomial, String specificEpithet, String infraSpecificEpithet, TeamOrPersonBase combinationAuthorTeam, INomenclaturalReference nomenclaturalReference, String nomenclMicroRef, HomotypicalGroup homotypicalGroup) {
+               super(rank, genusOrUninomial, specificEpithet, infraSpecificEpithet, combinationAuthorTeam, nomenclaturalReference, nomenclMicroRef, homotypicalGroup);
                this.cacheStrategy = BotanicNameDefaultCacheStrategy.NewInstance();
        }
 
@@ -115,7 +151,13 @@ public class BotanicalName extends NonViralName {
                return hybridRelationships;
        }
 
-
+       public void addRelationship(RelationshipBase relation) {
+               if (relation instanceof HybridRelationship){
+                       addHybridRelationship((HybridRelationship)relation);
+               }else {
+                       super.addRelationship(relation);
+               }
+       }
 
        public boolean isHybridFormula(){
                return this.isHybridFormula;
@@ -176,5 +218,13 @@ public class BotanicalName extends NonViralName {
        public void setAnamorphic(boolean isAnamorphic){
                this.isAnamorphic = isAnamorphic;
        }
+       
+       
+       @Transient
+       @Override
+       public NomenclaturalCode getNomeclaturalCode(){
+               return NomenclaturalCode.ICBN();
+
+       }
 
 }
\ No newline at end of file