root/trunk/cdmlib/cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/name/BotanicalName.java

Revision 12902, 16.3 kB (checked in by a.mueller, 9 months ago)

Cleaning up name cache strategies and updating javadoc

  • Property svn:keywords set to Id
Line 
1/**
2* Copyright (C) 2007 EDIT
3* European Distributed Institute of Taxonomy
4* http://www.e-taxonomy.eu
5*
6* The contents of this file are subject to the Mozilla Public License Version 1.1
7* See LICENSE.TXT at the top of this package for the full license terms.
8*/
9
10package eu.etaxonomy.cdm.model.name;
11
12
13import java.util.Map;
14
15import javax.persistence.Entity;
16import javax.xml.bind.annotation.XmlAccessType;
17import javax.xml.bind.annotation.XmlAccessorType;
18import javax.xml.bind.annotation.XmlElement;
19import javax.xml.bind.annotation.XmlRootElement;
20import javax.xml.bind.annotation.XmlType;
21
22import org.apache.log4j.Logger;
23import org.hibernate.envers.Audited;
24import org.hibernate.search.annotations.Indexed;
25import org.springframework.beans.factory.annotation.Configurable;
26
27import eu.etaxonomy.cdm.common.CdmUtils;
28import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
29import eu.etaxonomy.cdm.model.common.CdmBase;
30import eu.etaxonomy.cdm.model.reference.INomenclaturalReference;
31import eu.etaxonomy.cdm.strategy.cache.name.BotanicNameDefaultCacheStrategy;
32import eu.etaxonomy.cdm.strategy.parser.INonViralNameParser;
33import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl;
34
35/**
36 * The taxon name class for plants and fungi.
37 * <P>
38 * This class corresponds to: NameBotanical according to the ABCD schema.
39 *
40 * @author m.doering
41 * @version 1.0
42 * @created 08-Nov-2007 13:06:15
43 */
44@XmlAccessorType(XmlAccessType.FIELD)
45@XmlType(name = "BotanicalName", propOrder = {
46    "anamorphic"
47})
48@XmlRootElement(name = "BotanicalName")
49@Entity
50@Indexed(index = "eu.etaxonomy.cdm.model.name.TaxonNameBase")
51@Audited
52@Configurable
53public class BotanicalName extends NonViralName<BotanicalName> implements Cloneable /*, IMergable*/ {
54        private static final long serialVersionUID = 6818651572463497727L;
55        private static final Logger logger = Logger.getLogger(BotanicalName.class);
56       
57        //Only for fungi: to indicate that the type of the name is asexual or not
58    @XmlElement(name ="IsAnamorphic")
59        private boolean anamorphic;
60
61        static private INonViralNameParser nameParser = new NonViralNameParserImpl();
62       
63        // ************* CONSTRUCTORS *************/   
64        //needed by hibernate
65        /**
66         * Class constructor: creates a new botanical taxon name instance
67         * only containing the {@link eu.etaxonomy.cdm.strategy.cache.name.BotanicNameDefaultCacheStrategy default cache strategy}.
68         *
69         * @see #BotanicalName(Rank, HomotypicalGroup)
70         * @see #BotanicalName(Rank, String, String, String, String, TeamOrPersonBase, INomenclaturalReference, String, HomotypicalGroup)
71         * @see eu.etaxonomy.cdm.strategy.cache.name.BotanicNameDefaultCacheStrategy
72         */
73        protected BotanicalName(){
74                super();
75                this.cacheStrategy = BotanicNameDefaultCacheStrategy.NewInstance();
76        }
77        /**
78         * Class constructor: creates a new botanical taxon name instance
79         * only containing its {@link Rank rank},
80         * its {@link HomotypicalGroup homotypical group} and
81         * the {@link eu.etaxonomy.cdm.strategy.cache.name.BotanicNameDefaultCacheStrategy default cache strategy}.
82         * The new botanical taxon name instance will be also added to the set of
83         * botanical taxon names belonging to this homotypical group.
84         *
85         * @param       rank  the rank to be assigned to <i>this</i> botanical taxon name
86         * @param       homotypicalGroup  the homotypical group to which <i>this</i> botanical taxon name belongs
87         * @see         #BotanicalName()
88         * @see         #BotanicalName(Rank, String, String, String, TeamOrPersonBase, INomenclaturalReference, String, HomotypicalGroup)
89         * @see         eu.etaxonomy.cdm.strategy.cache.name.BotanicNameDefaultCacheStrategy
90         */
91        protected BotanicalName(Rank rank, HomotypicalGroup homotypicalGroup) {
92                super(rank, homotypicalGroup);
93                this.cacheStrategy = BotanicNameDefaultCacheStrategy.NewInstance();
94        }
95        /**
96         * Class constructor: creates a new botanical taxon name instance
97         * containing its {@link Rank rank},
98         * its {@link HomotypicalGroup homotypical group},
99         * its scientific name components, its {@link eu.etaxonomy.cdm.model.agent.TeamOrPersonBase author(team)},
100         * its {@link eu.etaxonomy.cdm.model.reference.INomenclaturalReference nomenclatural reference} and
101         * the {@link eu.etaxonomy.cdm.strategy.cache.name.BotanicNameDefaultCacheStrategy default cache strategy}.
102         * The new botanical taxon name instance will be also added to the set of
103         * botanical taxon names belonging to this homotypical group.
104         *
105         * @param       rank  the rank to be assigned to <i>this</i> botanical taxon name
106         * @param       genusOrUninomial the string for <i>this</i> botanical taxon name
107         *                      if its rank is genus or higher or for the genus part
108         *                      if its rank is lower than genus
109         * @param       infraGenericEpithet  the string for the first epithet of
110         *                      <i>this</i> botanical taxon name if its rank is lower than genus
111         *                      and higher than species aggregate
112         * @param       specificEpithet  the string for the first epithet of
113         *                      <i>this</i> botanical taxon name if its rank is species aggregate or lower
114         * @param       infraSpecificEpithet  the string for the second epithet of
115         *                      <i>this</i> botanical taxon name if its rank is lower than species
116         * @param       combinationAuthorTeam  the author or the team who published <i>this</i> botanical taxon name
117         * @param       nomenclaturalReference  the nomenclatural reference where <i>this</i> botanical taxon name was published
118         * @param       nomenclMicroRef  the string with the details for precise location within the nomenclatural reference
119         * @param       homotypicalGroup  the homotypical group to which <i>this</i> botanical taxon name belongs
120         * @see         #BotanicalName()
121         * @see         #BotanicalName(Rank, HomotypicalGroup)
122         * @see         #NewInstance(Rank, String, String, String, String, TeamOrPersonBase, INomenclaturalReference, String, HomotypicalGroup)
123         * @see         eu.etaxonomy.cdm.strategy.cache.name.BotanicNameDefaultCacheStrategy
124         * @see         eu.etaxonomy.cdm.strategy.cache.name.INonViralNameCacheStrategy
125         * @see         eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy
126         */
127        protected BotanicalName(Rank rank, String genusOrUninomial, String infraGenericEpithet, String specificEpithet, String infraSpecificEpithet, TeamOrPersonBase combinationAuthorTeam, INomenclaturalReference nomenclaturalReference, String nomenclMicroRef, HomotypicalGroup homotypicalGroup) {
128                super(rank, genusOrUninomial, infraGenericEpithet, specificEpithet, infraSpecificEpithet, combinationAuthorTeam, nomenclaturalReference, nomenclMicroRef, homotypicalGroup);
129                this.cacheStrategy = BotanicNameDefaultCacheStrategy.NewInstance();
130        }
131
132       
133        //********* METHODS **************************************/
134       
135        /**
136         * Creates a new botanical taxon name instance
137         * only containing its {@link Rank rank} and
138         * the {@link eu.etaxonomy.cdm.strategy.cache.name.BotanicNameDefaultCacheStrategy default cache strategy}.
139         *
140         * @param       rank    the rank to be assigned to <i>this</i> botanical taxon name
141         * @see                         #BotanicalName(Rank, HomotypicalGroup)
142         * @see                         #NewInstance(Rank, HomotypicalGroup)
143         * @see                         #NewInstance(Rank, String, String, String, String, TeamOrPersonBase, INomenclaturalReference, String, HomotypicalGroup)
144         * @see                         eu.etaxonomy.cdm.strategy.cache.name.BotanicNameDefaultCacheStrategy
145         */
146        public static BotanicalName NewInstance(Rank rank){
147                return new BotanicalName(rank, null);
148        }
149        /**
150         * Creates a new botanical taxon name instance
151         * only containing its {@link Rank rank},
152         * its {@link HomotypicalGroup homotypical group} and
153         * the {@link eu.etaxonomy.cdm.strategy.cache.name.BotanicNameDefaultCacheStrategy default cache strategy}.
154         * The new botanical taxon name instance will be also added to the set of
155         * botanical taxon names belonging to this homotypical group.
156         *
157         * @param  rank  the rank to be assigned to <i>this</i> botanical taxon name
158         * @param  homotypicalGroup  the homotypical group to which <i>this</i> botanical taxon name belongs
159         * @see    #NewInstance(Rank)
160         * @see    #NewInstance(Rank, String, String, String, String, TeamOrPersonBase, INomenclaturalReference, String, HomotypicalGroup)
161         * @see    #BotanicalName(Rank, HomotypicalGroup)
162         * @see    eu.etaxonomy.cdm.strategy.cache.name.BotanicNameDefaultCacheStrategy
163         */
164        public static BotanicalName NewInstance(Rank rank, HomotypicalGroup homotypicalGroup){
165                return new BotanicalName(rank, homotypicalGroup);
166        }
167        /**
168         * Creates a new botanical taxon name instance
169         * containing its {@link Rank rank},
170         * its {@link HomotypicalGroup homotypical group},
171         * its scientific name components, its {@link eu.etaxonomy.cdm.model.agent.TeamOrPersonBase author(team)},
172         * its {@link eu.etaxonomy.cdm.model.reference.INomenclaturalReference nomenclatural reference} and
173         * the {@link eu.etaxonomy.cdm.strategy.cache.name.BotanicNameDefaultCacheStrategy default cache strategy}.
174         * The new botanical taxon name instance will be also added to the set of
175         * botanical taxon names belonging to this homotypical group.
176         *
177         * @param       rank  the rank to be assigned to <i>this</i> botanical taxon name
178         * @param       genusOrUninomial the string for <i>this</i> botanical taxon name
179         *                      if its rank is genus or higher or for the genus part
180         *                      if its rank is lower than genus
181         * @param       infraGenericEpithet  the string for the first epithet of
182         *                      <i>this</i> botanical taxon name if its rank is lower than genus
183         *                      and higher than species aggregate
184         * @param       specificEpithet  the string for the first epithet of
185         *                      <i>this</i> botanical taxon name if its rank is species aggregate or lower
186         * @param       infraSpecificEpithet  the string for the second epithet of
187         *                      <i>this</i> botanical taxon name if its rank is lower than species
188         * @param       combinationAuthorTeam  the author or the team who published <i>this</i> botanical taxon name
189         * @param       nomenclaturalReference  the nomenclatural reference where <i>this</i> botanical taxon name was published
190         * @param       nomenclMicroRef  the string with the details for precise location within the nomenclatural reference
191         * @param       homotypicalGroup  the homotypical group to which <i>this</i> botanical taxon name belongs
192         * @see         #NewInstance(Rank)
193         * @see         #NewInstance(Rank, HomotypicalGroup)
194         * @see         ZoologicalName#ZoologicalName(Rank, String, String, String, String, TeamOrPersonBase, INomenclaturalReference, String, HomotypicalGroup)
195         * @see         eu.etaxonomy.cdm.strategy.cache.name.BotanicNameDefaultCacheStrategy
196         */
197        public static  BotanicalName NewInstance(Rank rank, String genusOrUninomial, String infraGenericEpithet, String specificEpithet, String infraSpecificEpithet, TeamOrPersonBase combinationAuthorTeam, INomenclaturalReference nomenclaturalReference, String nomenclMicroRef, HomotypicalGroup homotypicalGroup) {
198                return new BotanicalName(rank, genusOrUninomial, infraGenericEpithet, specificEpithet, infraSpecificEpithet, combinationAuthorTeam, nomenclaturalReference, nomenclMicroRef, homotypicalGroup);
199        }
200       
201        /**
202         * Returns a botanical taxon name based on parsing a string representing
203         * all elements (according to the ICBN) of a botanical taxon name (where
204         * the scientific name is an uninomial) including authorship but without
205         * nomenclatural reference. If the {@link Rank rank} is not "Genus" it should be
206         * set afterwards with the {@link TaxonNameBase#setRank(Rank) setRank} methode.
207         *
208         * @param       fullNameString  the string to be parsed
209         * @return                                      the new botanical taxon name
210         */
211        public static BotanicalName PARSED_NAME(String fullNameString){
212                return PARSED_NAME(fullNameString, Rank.GENUS());
213        }
214       
215        /**
216         * Returns a botanical taxon name based on parsing a string representing
217         * all elements (according to the ICBN) of a botanical taxon name including
218         * authorship but without nomenclatural reference. The parsing result
219         * depends on the given rank of the botanical taxon name to be created.
220         *
221         * @param       fullNameString  the string to be parsed
222         * @param   rank                        the rank of the taxon name
223         * @return                                      the new botanical taxon name
224         */
225        public static BotanicalName PARSED_NAME(String fullNameString, Rank rank){
226                if (nameParser == null){
227                        nameParser = new NonViralNameParserImpl();
228                }
229                return (BotanicalName)nameParser.parseFullName(fullNameString, NomenclaturalCode.ICBN,  rank);
230        }
231       
232        /**
233         * Returns a botanical taxon name based on parsing a string representing
234         * all elements (according to the ICBN) of a botanical taxon name (where
235         * the scientific name is an uninomial) including authorship and
236         * nomenclatural reference. Eventually a new {@link eu.etaxonomy.cdm.model.reference.INomenclaturalReference nomenclatural reference}
237         * instance will also be created. If the {@link Rank rank} is not "Genus" it should be
238         * set afterwards with the {@link TaxonNameBase#setRank(Rank) setRank} methode.
239         *
240         * @param       fullNameAndReferenceString  the string to be parsed
241         * @return                                                              the new botanical taxon name
242         */
243        public static BotanicalName PARSED_REFERENCE(String fullNameAndReferenceString){
244                return PARSED_REFERENCE(fullNameAndReferenceString, Rank.GENUS());
245        }
246       
247        /**
248         * Returns a botanical taxon name based on parsing a string representing
249         * all elements (according to the ICBN) of a botanical taxon name including
250         * authorship and nomenclatural reference. The parsing result depends on
251         * the given rank of the botanical taxon name to be created.
252         * Eventually a new {@link eu.etaxonomy.cdm.model.reference.INomenclaturalReference nomenclatural reference}
253         * instance will also be created.
254         *
255         * @param       fullNameAndReferenceString  the string to be parsed
256         * @param   rank                                                the rank of the taxon name
257         * @return                                                              the new botanical taxon name
258         */
259        public static BotanicalName PARSED_REFERENCE(String fullNameAndReferenceString, Rank rank){
260                if (nameParser == null){
261                        nameParser = new NonViralNameParserImpl();
262                }
263                return (BotanicalName)nameParser.parseReferencedName(fullNameAndReferenceString, NomenclaturalCode.ICBN, rank);
264        }
265
266//***********************       
267
268        private static Map<String, java.lang.reflect.Field> allFields = null;
269        @Override
270    protected Map<String, java.lang.reflect.Field> getAllFields(){
271        if (allFields == null){
272                        allFields = CdmUtils.getAllFields(this.getClass(), CdmBase.class, false, false, false, true);
273                }
274        return allFields;
275    }
276
277//*************************
278       
279        /**
280         * Returns the boolean value of the flag indicating whether the specimen
281         * type of <i>this</i> botanical taxon name for a fungus is asexual (true) or not
282         * (false). This applies only in case of fungi. The Article 59 of the ICBN
283         * permits mycologists to give asexually reproducing fungi (anamorphs)
284         * separate names from their sexual states (teleomorphs).
285         * 
286         * @return  the boolean value of the isAnamorphic flag
287         */
288        public boolean isAnamorphic(){
289                return this.anamorphic;
290        }
291
292        /**
293         * @see  #isAnamorphic()
294         */
295        public void setAnamorphic(boolean anamorphic){
296                this.anamorphic = anamorphic;
297        }
298       
299       
300        /**
301         * Returns the {@link NomenclaturalCode nomenclatural code} that governs
302         * the construction of <i>this</i> botanical taxon name, that is the
303         * International Code of Botanical Nomenclature. This method overrides
304         * the getNomeclaturalCode method from {@link NonViralName NonViralName}.
305         *
306         * @return  the nomenclatural code for plants
307         * @see         NonViralName#isCodeCompliant()
308         * @see         TaxonNameBase#getHasProblem()
309         */
310        @Override
311        public NomenclaturalCode getNomenclaturalCode(){
312                return NomenclaturalCode.ICBN;
313        }
314
315       
316        /**
317         * Checks if this name is an autonym.<BR>
318         * An autonym is a taxon name that has equal specific and infra specific epithets.<BR>
319         * {@link http://ibot.sav.sk/icbn/frameset/0010Ch2Sec1a006.htm#6.8. Vienna Code �6.8}
320         * @return true, if name has Rank, Rank is below species and species epithet equals infraSpeciesEpithtet, else false
321         */
322        @Override
323        public boolean isAutonym(){
324                if (this.getRank() != null && this.getSpecificEpithet() != null && this.getInfraSpecificEpithet() != null && 
325                                this.getRank().isInfraSpecific() && this.getSpecificEpithet().trim().equals(this.getInfraSpecificEpithet().trim())){
326                        return true;
327                }else{
328                        return false;
329                }
330        }
331       
332//*********************** CLONE ********************************************************/
333       
334        /**
335         * Clones <i>this</i> botanical name. This is a shortcut that enables to create
336         * a new instance that differs only slightly from <i>this</i> botanical name by
337         * modifying only some of the attributes.
338         *
339         * @see eu.etaxonomy.cdm.model.name.NonViralName#clone()
340         * @see java.lang.Object#clone()
341         */
342        @Override
343        public Object clone() {
344                BotanicalName result = (BotanicalName)super.clone();
345                //no changes to: title, authorTeam, hasProblem, nomenclaturallyRelevant, uri
346                return result;
347        }
348
349
350}
Note: See TracBrowser for help on using the browser.