merge hibernate4 migration branch into trunk
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / common / AnnotationType.java
index 30540be75f2fdb27ef6a188afc08bfac2c1af79a..ddecbdb71bd62c689c27044bb22217291da6f40f 100644 (file)
 package eu.etaxonomy.cdm.model.common;
 
 
-import org.apache.log4j.Logger;
-
-import java.util.*;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
 
-import javax.persistence.*;
+import javax.persistence.Entity;
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlType;
 
+import org.apache.log4j.Logger;
+import org.hibernate.envers.Audited;
+import org.hibernate.search.annotations.Indexed;
+import org.springframework.util.Assert;
+
 /**
  * Annotation types ...
  * @author a.mueller
@@ -26,14 +32,21 @@ import javax.xml.bind.annotation.XmlType;
  * @created 12-Nov-2008 15:37:33
  */
 @XmlAccessorType(XmlAccessType.FIELD)
-@XmlType(name = "MarkerType")
+@XmlType(name = "AnnotationType")
+@XmlRootElement(name = "AnnotationType")
 @Entity
-public class AnnotationType extends DefinedTermBase {
-       public static final Logger logger = Logger.getLogger(AnnotationType.class);
+@Indexed(index = "eu.etaxonomy.cdm.model.common.DefinedTermBase")
+@Audited
+public class AnnotationType extends DefinedTermBase<AnnotationType> {
+       private static final long serialVersionUID = 49629121282854575L;
+       @SuppressWarnings("unused")
+       private static final Logger logger = Logger.getLogger(AnnotationType.class);
 
-       private static final UUID uuidTechnical = UUID.fromString("6a5f9ea4-1bdd-4906-89ad-6e669f982d69");
-       private static final UUID uuidEditorial = UUID.fromString("34204192-b41d-4857-a1d4-28992bef2a2a");
+       protected static Map<UUID, AnnotationType> termMap = null;              
        
+       private static final UUID uuidTechnical = UUID.fromString("6a5f9ea4-1bdd-4906-89ad-6e669f982d69");
+       private static final UUID uuidEditorial = UUID.fromString("e780d5fd-abfc-4025-938a-46deb751d808");
+
        public static AnnotationType NewInstance(String term, String label, String labelAbbrev){
                return new AnnotationType(term, label, labelAbbrev);
        }
@@ -44,7 +57,6 @@ public class AnnotationType extends DefinedTermBase {
         * @param label
         */
        public AnnotationType() {
-               super();
        }
        
        /**
@@ -55,19 +67,39 @@ public class AnnotationType extends DefinedTermBase {
        protected AnnotationType(String term, String label, String labelAbbrev) {
                super(term, label, labelAbbrev);
        }
-       
-
-       public static final AnnotationType getByUuid(UUID uuid){
-               return (AnnotationType) findByUuid(uuid);
-       }       
-
 
+       
+//************************** METHODS ********************************
+       
+       /* (non-Javadoc)
+        * @see eu.etaxonomy.cdm.model.common.DefinedTermBase#resetTerms()
+        */
+       @Override
+       public void resetTerms(){
+               termMap = null;
+       }
+       
+       protected static AnnotationType getTermByUuid(UUID uuid){
+               if (termMap == null){
+                       return null;  //better return null then initialize the termMap in an unwanted way 
+               }
+               return (AnnotationType)termMap.get(uuid);
+       }
+       
+       
        public static final AnnotationType TECHNICAL(){
-               return getByUuid(uuidTechnical);
+               return getTermByUuid(uuidTechnical);
        }
 
        public static final AnnotationType EDITORIAL(){
-               return getByUuid(uuidEditorial);
+               return getTermByUuid(uuidEditorial);
+       }
+
+       protected void setDefaultTerms(TermVocabulary<AnnotationType> termVocabulary) {
+               termMap = new HashMap<UUID, AnnotationType>();
+               for (AnnotationType term : termVocabulary.getTerms()){
+                       termMap.put(term.getUuid(), (AnnotationType)term);
+               }       
        }
 
 }
\ No newline at end of file