import org.hibernate.annotations.CascadeType;
import eu.etaxonomy.cdm.model.agent.Person;
-import eu.etaxonomy.cdm.model.name.TaxonNameBase;
+
return this.getClass().getSimpleName()+"#"+this.getId()+"<"+this.getUuid()+">";
}
- protected void useSetMethod(Method method, Object object){
+ protected void invokeSetMethod(Method method, Object object){
try {
method.invoke(object, this);
} catch (Exception e) {
public void addTaxonBase(TaxonBase taxonBase){
taxonBases.add(taxonBase);
initMethods();
- useSetMethod(methodTaxonBaseSetName, taxonBase);
+ invokeSetMethod(methodTaxonBaseSetName, taxonBase);
}
private void initMethods(){
public static Synonym NewInstance(TaxonNameBase taxonName, ReferenceBase sec){
- Synonym result = new Synonym();
- result.setTaxonName(taxonName);
- result.setSec(sec);
+ Synonym result = new Synonym(taxonName, sec);
return result;
}
public Synonym(){
}
-
+ public Synonym(TaxonNameBase taxonNameBase, ReferenceBase sec){
+ super(taxonNameBase, sec);
+ }
+
@OneToMany(mappedBy="relatedFrom", fetch=FetchType.EAGER)
@Cascade({CascadeType.SAVE_UPDATE, CascadeType.DELETE})
public Set<SynonymRelationship> getSynonymRelations() {
// shortcut to the taxonomicIncluded (parent) taxon. Managed by the taxonRelations setter
private Taxon taxonomicParentCache;
- static Method methodDescriptionSetTaxon;
+ private static Method methodDescriptionSetTaxon;
* @return
*/
public static Taxon NewInstance(TaxonNameBase taxonNameBase, ReferenceBase sec){
- Taxon result = new Taxon();
- result.setTaxonName(taxonNameBase);
- result.setSec(sec);
+ Taxon result = new Taxon(taxonNameBase, sec);
return result;
}
//TODO should be private, but still produces Spring init errors
+ @Deprecated
public Taxon(){
}
+ public Taxon(TaxonNameBase taxonNameBase, ReferenceBase sec){
+ super(taxonNameBase, sec);
+ }
+
@OneToMany(mappedBy="taxon", fetch= FetchType.EAGER)
@Cascade({CascadeType.SAVE_UPDATE})
package eu.etaxonomy.cdm.model.taxon;
-
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
import eu.etaxonomy.cdm.model.reference.ReferenceBase;
import org.apache.log4j.Logger;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
-import org.hibernate.collection.PersistentSet;
-
-import java.lang.reflect.Field;
-import java.util.*;
+import java.lang.reflect.Method;
import javax.persistence.*;
public abstract class TaxonBase extends IdentifiableEntity {
static Logger logger = Logger.getLogger(TaxonBase.class);
- //TODO make static for performance reasons
- private static Field taxonBaseField;
+ private static Method methodTaxonNameAddTaxonBase;
+
+ private static void initMethods() {
+ if (methodTaxonNameAddTaxonBase == null){
+ try {
+ methodTaxonNameAddTaxonBase = TaxonNameBase.class.getDeclaredMethod("addTaxonBase", TaxonBase.class);
+ methodTaxonNameAddTaxonBase.setAccessible(true);
+ } catch (Exception e) {
+ e.printStackTrace();
+ //TODO handle exception
+ }
+ }
+ }
protected TaxonBase(){
super();
}
+ protected TaxonBase(TaxonNameBase taxonNameBase, ReferenceBase sec){
+ super();
+ if (taxonNameBase != null){
+ initMethods();
+ this.invokeSetMethod(methodTaxonNameAddTaxonBase, taxonNameBase);
+ }
+ this.setSec(sec);
+ }
//The assignment to the Taxon or to the Synonym class is not definitive
private boolean isDoubtful;
this.name = newName;
}
- @Transient
- public TaxonNameBase getTaxonName(){
- return this.name;
- }
- public void setTaxonName(TaxonNameBase newName){
- if (newName != null){
- newName.addTaxonBase(this);
- }else{
- //FIXME implement
- //this.name.removeTaxonBase(this);
- }
- }
-
@Transient
public HomotypicalGroup getHomotypicGroup(){
if (this.getName() == null){
-"fa032b1a-1ad2-4fb0-a1d9-3016399a80fa",,"NomenclaturalCodeTerm","NomenclaturalCodeTerm",\r
+"fa032b1a-1ad2-4fb0-a1d9-3016399a80fa",,"NomenclaturalCode","NomenclaturalCode",\r
"ff4b0979-7abf-4b40-95c0-8b8b1e8a4d5e",,"Bacteriological","Bacteriological",\r
"540fc02a-8a8e-4813-89d2-581dad4dd482",,"ICBN","ICBN",\r
"65a432b5-92b1-4c9a-8090-2a185e423d2e",,"ICNCP","ICNCP",\r
*/\r
@Before\r
public void setUp() throws Exception {\r
- sec=new Book();\r
+ sec= Book.NewInstance();\r
sec.setTitleCache("Schoenes saftiges Allg�u");\r
name1 = ZoologicalName.NewInstance(Rank.SPECIES(),"Panthera","onca",null,null,null,"p.1467", null);\r
HomotypicalGroup homotypicalGroup = HomotypicalGroup.NewInstance();\r
assertEquals(name1.getTitleCache(), taxon1.getName().getTitleCache());\r
assertNull(freeT.getName());\r
}\r
-\r
- /**\r
- * Test method for {@link eu.etaxonomy.cdm.model.taxon.TaxonBase#setName(eu.etaxonomy.cdm.model.name.TaxonNameBase)}.\r
- */\r
- @Test\r
- public final void testSetName() {\r
- assertNull(freeT.getName());\r
- freeT.setTaxonName(name2);\r
- assertNotNull(freeT.getName());\r
- assertSame(freeT.getName(), name2);\r
- assertTrue(name1.getTaxa().contains(taxon1));\r
- assertTrue(name2.getSynonyms().contains(synonym1));\r
- }\r
+//\r
+// /**\r
+// * Test method for {@link eu.etaxonomy.cdm.model.taxon.TaxonBase#setName(eu.etaxonomy.cdm.model.name.TaxonNameBase)}.\r
+// */\r
+// @Test\r
+// public final void testSetName() {\r
+// assertNull(freeT.getName());\r
+// freeT.setName(name2);\r
+// assertNotNull(freeT.getName());\r
+// assertSame(freeT.getName(), name2);\r
+// assertTrue(name1.getTaxa().contains(taxon1));\r
+// assertTrue(name2.getSynonyms().contains(synonym1));\r
+// }\r
\r
/**\r
* Test method for {@link eu.etaxonomy.cdm.model.taxon.TaxonBase#isDoubtful()}.\r
public final void testIsSaveable() {\r
assertFalse(freeT.isSaveable());\r
assertTrue(taxon1.isSaveable());\r
- freeT.setTaxonName(name1);\r
assertFalse(freeT.isSaveable());\r
freeT.setSec(sec);\r
- assertTrue(freeT.isSaveable());\r
- freeT.setTaxonName(null);\r
assertFalse(freeT.isSaveable());\r
}\r
\r