2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.model
.reference
;
12 import java
.beans
.PropertyChangeEvent
;
13 import java
.beans
.PropertyChangeListener
;
15 import java
.util
.List
;
17 import javax
.persistence
.Column
;
18 import javax
.persistence
.Embedded
;
19 import javax
.persistence
.Entity
;
20 import javax
.persistence
.FetchType
;
21 import javax
.persistence
.Inheritance
;
22 import javax
.persistence
.InheritanceType
;
23 import javax
.persistence
.Lob
;
24 import javax
.persistence
.ManyToOne
;
25 import javax
.persistence
.Transient
;
26 import javax
.validation
.constraints
.NotNull
;
27 import javax
.validation
.constraints
.Pattern
;
28 import javax
.xml
.bind
.annotation
.XmlAccessType
;
29 import javax
.xml
.bind
.annotation
.XmlAccessorType
;
30 import javax
.xml
.bind
.annotation
.XmlAttribute
;
31 import javax
.xml
.bind
.annotation
.XmlElement
;
32 import javax
.xml
.bind
.annotation
.XmlIDREF
;
33 import javax
.xml
.bind
.annotation
.XmlRootElement
;
34 import javax
.xml
.bind
.annotation
.XmlSchemaType
;
35 import javax
.xml
.bind
.annotation
.XmlType
;
37 import org
.apache
.commons
.lang
.StringUtils
;
38 import org
.apache
.log4j
.Logger
;
39 import org
.hibernate
.annotations
.Cascade
;
40 import org
.hibernate
.annotations
.CascadeType
;
41 import org
.hibernate
.annotations
.Table
;
42 import org
.hibernate
.annotations
.Type
;
43 import org
.hibernate
.envers
.Audited
;
44 import org
.hibernate
.search
.annotations
.Analyze
;
45 import org
.hibernate
.search
.annotations
.Field
;
46 import org
.hibernate
.search
.annotations
.FieldBridge
;
47 import org
.hibernate
.search
.annotations
.IndexedEmbedded
;
49 import eu
.etaxonomy
.cdm
.common
.DOI
;
50 import eu
.etaxonomy
.cdm
.hibernate
.search
.DoiBridge
;
51 import eu
.etaxonomy
.cdm
.model
.agent
.Institution
;
52 import eu
.etaxonomy
.cdm
.model
.agent
.TeamOrPersonBase
;
53 import eu
.etaxonomy
.cdm
.model
.common
.TimePeriod
;
54 import eu
.etaxonomy
.cdm
.model
.media
.IdentifiableMediaEntity
;
55 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
56 import eu
.etaxonomy
.cdm
.strategy
.cache
.reference
.ArticleDefaultCacheStrategy
;
57 import eu
.etaxonomy
.cdm
.strategy
.cache
.reference
.BookDefaultCacheStrategy
;
58 import eu
.etaxonomy
.cdm
.strategy
.cache
.reference
.BookSectionDefaultCacheStrategy
;
59 import eu
.etaxonomy
.cdm
.strategy
.cache
.reference
.GenericDefaultCacheStrategy
;
60 import eu
.etaxonomy
.cdm
.strategy
.cache
.reference
.INomenclaturalReferenceCacheStrategy
;
61 import eu
.etaxonomy
.cdm
.strategy
.cache
.reference
.IReferenceBaseCacheStrategy
;
62 import eu
.etaxonomy
.cdm
.strategy
.cache
.reference
.JournalDefaultCacheStrategy
;
63 import eu
.etaxonomy
.cdm
.strategy
.cache
.reference
.ReferenceDefaultCacheStrategy
;
64 import eu
.etaxonomy
.cdm
.strategy
.match
.Match
;
65 import eu
.etaxonomy
.cdm
.strategy
.match
.MatchMode
;
66 import eu
.etaxonomy
.cdm
.strategy
.merge
.Merge
;
67 import eu
.etaxonomy
.cdm
.strategy
.merge
.MergeMode
;
68 import eu
.etaxonomy
.cdm
.strategy
.parser
.ParserProblem
;
69 import eu
.etaxonomy
.cdm
.validation
.Level2
;
70 import eu
.etaxonomy
.cdm
.validation
.Level3
;
71 import eu
.etaxonomy
.cdm
.validation
.annotation
.InReference
;
72 import eu
.etaxonomy
.cdm
.validation
.annotation
.NoRecursiveInReference
;
73 import eu
.etaxonomy
.cdm
.validation
.annotation
.NullOrNotEmpty
;
74 import eu
.etaxonomy
.cdm
.validation
.annotation
.ReferenceCheck
;
77 * The upmost (abstract) class for references (information sources).
79 * This class corresponds to: <ul>
80 * <li> PublicationCitation according to the TDWG ontology
81 * <li> Publication according to the TCS
82 * <li> Reference according to the ABCD schema
86 * @created 08-Nov-2007 13:06:47
88 @XmlAccessorType(XmlAccessType
.FIELD
)
89 @XmlType(name
= "Reference", propOrder
= {
93 "protectedAbbrevTitleCache",
94 "nomenclaturallyRelevant",
115 @XmlRootElement(name
= "Reference")
117 @Inheritance(strategy
=InheritanceType
.SINGLE_TABLE
)
119 @Table(appliesTo
="Reference", indexes
= { @org.hibernate
.annotations
.Index(name
= "ReferenceTitleCacheIndex", columnNames
= { "titleCache" }) })
120 //@InReference(groups=Level3.class)
121 @ReferenceCheck(groups
=Level2
.class)
122 @InReference(groups
=Level3
.class)
123 @NoRecursiveInReference(groups
=Level3
.class) //may become Level1 in future #
124 public class Reference
<S
extends IReferenceBaseCacheStrategy
>
125 extends IdentifiableMediaEntity
<S
>
126 implements INomenclaturalReference
, IArticle
, IBook
, IPatent
, IDatabase
, IJournal
, IBookSection
,ICdDvd
,IGeneric
,IInProceedings
, IProceedings
, IPrintSeries
, IReport
, IThesis
,IWebPage
, IPersonalCommunication
, IReference
, Cloneable
{
128 private static final long serialVersionUID
= -2034764545042691295L;
129 private static final Logger logger
= Logger
.getLogger(Reference
.class);
131 @XmlAttribute(name
="type")
132 @Column(name
="refType")
134 @Type(type
= "eu.etaxonomy.cdm.hibernate.EnumUserType",
135 parameters
= {@org.hibernate
.annotations
.Parameter(name
= "enumClass", value
= "eu.etaxonomy.cdm.model.reference.ReferenceType")}
138 protected ReferenceType type
;
140 //Title of the reference
141 @XmlElement(name
="Title" )
142 @Column(length
=4096, name
="title")
145 @Match(MatchMode
.EQUAL_REQUIRED
)
148 private String title
;
150 //Title of the reference
151 @XmlElement(name
="AbbrevTitle" )
153 @Match(MatchMode
.EQUAL
) //TODO check if this is correct
156 private String abbrevTitle
;
158 //Title of the reference
159 @XmlElement(name
="AbbrevTitleCache" )
161 @Match(MatchMode
.CACHE
)
165 private String abbrevTitleCache
;
167 @XmlElement(name
= "protectedAbbrevTitleCache")
169 private boolean protectedAbbrevTitleCache
;
171 //********************************************************/
174 @XmlElement(name
= "Editor")
179 protected String editor
;
181 @XmlElement(name
= "Volume")
186 protected String volume
;
188 @XmlElement(name
= "Pages")
193 protected String pages
;
195 @XmlElement(name
= "Edition")
200 protected String edition
;
202 @XmlElement(name
= "ISBN")
207 @Pattern(regexp
= "(?=.{13}$)\\d{1,5}([- ])\\d{1,7}\\1\\d{1,6}\\1(\\d|X)$", groups
= Level2
.class, message
= "{eu.etaxonomy.cdm.model.reference.Reference.isbn.message}")
208 protected String isbn
;
210 @XmlElement(name
= "Doi")
212 @FieldBridge(impl
= DoiBridge
.class)
213 @Type(type
="doiUserType")
214 @Column(length
=DOI
.MAX_LENGTH
)
218 @XmlElement(name
= "ISSN")
223 @Pattern(regexp
= "(?=.{9}$)\\d{4}([- ])\\d{4} (\\d|X)$", groups
= Level2
.class, message
= "{eu.etaxonomy.cdm.model.reference.Reference.issn.message}")
224 protected String issn
;
226 @XmlElement(name
= "SeriesPart")
231 protected String seriesPart
;
233 @XmlElement(name
= "Organization")
238 protected String organization
;
240 @XmlElement(name
= "Publisher")
245 protected String publisher
;
248 @XmlElement(name
= "PlacePublished")
253 protected String placePublished
;
255 @XmlElement(name
= "Institution")
257 @XmlSchemaType(name
= "IDREF")
258 @ManyToOne(fetch
= FetchType
.LAZY
)
260 @Cascade({CascadeType
.SAVE_UPDATE
,CascadeType
.MERGE
})
261 protected Institution institution
;
263 @XmlElement(name
= "School")
265 @XmlSchemaType(name
= "IDREF")
266 @ManyToOne(fetch
= FetchType
.LAZY
)
268 @Cascade({CascadeType
.SAVE_UPDATE
,CascadeType
.MERGE
})
269 protected Institution school
;
271 @XmlElement(name
= "InReference")
273 @XmlSchemaType(name
= "IDREF")
274 @ManyToOne(fetch
= FetchType
.LAZY
)
276 @Cascade({CascadeType
.SAVE_UPDATE
,CascadeType
.MERGE
})
277 // @InReference(groups=Level2.class)
279 protected Reference
<?
> inReference
;
281 // @XmlElement(name = "FullReference")
283 // @XmlSchemaType(name = "IDREF")
284 // @ManyToOne(fetch = FetchType.LAZY)
285 //// @IndexedEmbedded
286 // @Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
287 // protected Reference fullReference;
289 // @XmlElement(name = "AbbreviatedReference")
291 // @XmlSchemaType(name = "IDREF")
292 // @ManyToOne(fetch = FetchType.LAZY)
293 //// @IndexedEmbedded
294 // @Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
295 // protected Reference abbreviatedReference;
298 //********************************************************/
300 //The date range assigned to the reference. ISO Date range like. Flexible, year can be left out, etc
301 @XmlElement(name
="DatePublished" )
304 private TimePeriod datePublished
= TimePeriod
.NewInstance();
306 @XmlElement(name
="Abstract" )
307 @Column(length
=65536, name
="referenceAbstract")
312 private String referenceAbstract
; //abstract is a reserved term in Java
315 //URIs like DOIs, LSIDs or Handles for this reference
316 @XmlElement(name
= "URI")
317 @Field(analyze
= Analyze
.NO
)
318 @Type(type
="uriUserType")
321 //flag to subselect only references that could be useful for nomenclatural citations. If a reference is used as a
322 //nomenclatural reference in a name this flag should be automatically set
323 @XmlElement(name
= "IsNomenclaturallyRelevant")
325 private boolean nomenclaturallyRelevant
;
327 @XmlElement(name
= "Authorship")
329 @XmlSchemaType(name
= "IDREF")
330 @ManyToOne(fetch
= FetchType
.LAZY
)
332 @Cascade({CascadeType
.SAVE_UPDATE
,CascadeType
.MERGE
})
333 private TeamOrPersonBase
<?
> authorship
;
336 // @XmlElement(name = "ReferenceIdentity")
338 // @XmlSchemaType(name = "IDREF")
339 // @ManyToOne(fetch = FetchType.LAZY)
340 // //@IndexedEmbedded
341 // @Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
343 // private ReferenceIdentity referenceIdentity;
346 @Match(MatchMode
.IGNORE
)
347 private int parsingProblem
= 0;
350 @Match(MatchMode
.IGNORE
)
351 private int problemStarts
= -1;
354 @Match(MatchMode
.IGNORE
)
355 private int problemEnds
= -1;
359 @Match(MatchMode
.IGNORE
)
360 private boolean cacheStrategyRectified
= false;
362 protected Reference(){
363 this(ReferenceType
.Generic
); //just in case someone uses constructor
366 protected Reference(ReferenceType type
) {
368 this.type
= ReferenceType
.Generic
;
375 public void initListener(){
376 PropertyChangeListener listener
= new PropertyChangeListener() {
378 public void propertyChange(PropertyChangeEvent ev
) {
379 if (!ev
.getPropertyName().equals("titleCache") && !ev
.getPropertyName().equals("abbrevTitleCache") && !ev
.getPropertyName().equals("cacheStrategy")){
380 if (! isProtectedTitleCache()){
383 if (! isProtectedAbbrevTitleCache()){
384 abbrevTitleCache
= null;
389 addPropertyChangeListener(listener
);
393 //*************************** GETTER / SETTER ******************************************/
397 public String
getAbbrevTitleCache() {
398 if (protectedAbbrevTitleCache
){
399 return this.abbrevTitleCache
;
401 // is title dirty, i.e. equal NULL?
402 if (abbrevTitleCache
== null){
403 this.abbrevTitleCache
= generateAbbrevTitle();
404 this.abbrevTitleCache
= getTruncatedCache(this.abbrevTitleCache
) ;
406 return abbrevTitleCache
;
411 public void setAbbrevTitleCache(String abbrevTitleCache
) {
412 this.abbrevTitleCache
= abbrevTitleCache
;
416 public void setAbbrevTitleCache(String abbrevTitleCache
, boolean isProtected
) {
417 this.protectedAbbrevTitleCache
= isProtected
;
418 setAbbrevTitleCache(abbrevTitleCache
);
422 public boolean isProtectedAbbrevTitleCache() {
423 return protectedAbbrevTitleCache
;
427 public void setProtectedAbbrevTitleCache(boolean protectedAbbrevTitleCache
) {
428 this.protectedAbbrevTitleCache
= protectedAbbrevTitleCache
;
432 public String
getAbbrevTitle() {
437 public void setAbbrevTitle(String abbrevTitle
) {
438 this.abbrevTitle
= StringUtils
.isBlank(abbrevTitle
) ?
null : abbrevTitle
;
443 public String
getEditor() {
449 public void setEditor(String editor
) {
450 this.editor
= StringUtils
.isBlank(editor
)?
null : editor
;
454 // public String getSeries() {
459 // public void setSeries(String series) {
460 // this.series = series;
464 public String
getVolume() {
469 public void setVolume(String volume
) {
470 this.volume
= StringUtils
.isBlank(volume
)?
null : volume
;
474 public String
getPages() {
479 public void setPages(String pages
) {
480 this.pages
= StringUtils
.isBlank(pages
)?
null : pages
;
484 public String
getEdition() {
489 public void setEdition(String edition
) {
490 this.edition
= StringUtils
.isBlank(edition
)?
null : edition
;
494 public String
getIsbn() {
499 public void setIsbn(String isbn
) {
500 this.isbn
= StringUtils
.isBlank(isbn
)?
null : isbn
;
504 public String
getIssn() {
509 public void setIssn(String issn
) {
510 this.issn
= StringUtils
.isBlank(issn
)?
null : issn
;
514 public DOI
getDoi() {
519 public void setDoi(DOI doi
) {
524 public String
getSeriesPart() {
529 public void setSeriesPart(String seriesPart
) {
530 this.seriesPart
= StringUtils
.isBlank(seriesPart
)?
null : seriesPart
;
534 public String
getOrganization() {
539 public void setOrganization(String organization
) {
540 this.organization
= StringUtils
.isBlank(organization
)?
null : organization
;
544 public String
getPublisher() {
549 public void setPublisher(String publisher
) {
550 this.publisher
= StringUtils
.isBlank(publisher
)?
null : publisher
;
554 public void setPublisher(String publisher
, String placePublished
){
555 this.publisher
= publisher
;
556 this.placePublished
= placePublished
;
560 public String
getPlacePublished() {
561 return placePublished
;
565 public void setPlacePublished(String placePublished
) {
566 this.placePublished
= StringUtils
.isBlank(placePublished
)?
null: placePublished
;
570 public Institution
getInstitution() {
575 public void setInstitution(Institution institution
) {
576 this.institution
= institution
;
580 public Institution
getSchool() {
585 public void setSchool(Institution school
) {
586 this.school
= school
;
590 public Reference
getInReference() {
595 public void setInReference(Reference inReference
) {
596 this.inReference
= inReference
;
600 public void setType(ReferenceType type
) {
601 this.setCacheStrategy(type
.getCacheStrategy());
603 this.type
= ReferenceType
.Generic
;
614 public ReferenceType
getType() {
619 * Whether this reference is of the given type
625 public boolean isOfType(ReferenceType type
){
626 return type
== getType();
630 * Returns a string representing the title of <i>this</i> reference. If a
631 * reference has different titles (for instance abbreviated and not
632 * abbreviated) then for each title a new instance must be created.
634 * @return the title string of <i>this</i> reference
635 * @see #getCitation()
638 public String
getTitle(){
645 public void setTitle(String title
){
646 this.title
= StringUtils
.isBlank(title
)?
null : title
;
650 * Returns the date (mostly only the year) of publication / creation of
651 * <i>this</i> reference.
654 public TimePeriod
getDatePublished(){
655 return this.datePublished
;
658 * @see #getDatePublished()
661 public void setDatePublished(TimePeriod datePublished
){
662 this.datePublished
= datePublished
;
665 public boolean hasDatePublished(){
666 boolean result
= ! ( (this.datePublished
== null) || StringUtils
.isBlank(datePublished
.toString()));
671 * Returns the {@link eu.etaxonomy.cdm.model.agent.TeamOrPersonBase author (team)} who created the
672 * content of <i>this</i> reference.
674 * @return the author (team) of <i>this</i> reference
675 * @see eu.etaxonomy.cdm.model.agent.TeamOrPersonBase
678 public TeamOrPersonBase
getAuthorship(){
679 return this.authorship
;
683 * @see #getAuthorship()
686 public void setAuthorship(TeamOrPersonBase authorship
){
687 this.authorship
= authorship
;
691 * Returns the Uniform Resource Identifier (URI) corresponding to <i>this</i>
692 * reference. An URI is a string of characters used to identify a resource
695 * @return the URI of <i>this</i> reference
705 public void setUri(URI uri
){
710 * @return the referenceAbstract
713 public String
getReferenceAbstract() {
714 return referenceAbstract
;
718 * @param referenceAbstract the referenceAbstract to set
721 public void setReferenceAbstract(String referenceAbstract
) {
722 this.referenceAbstract
= StringUtils
.isBlank(referenceAbstract
)?
null : referenceAbstract
;
729 * Returns "true" if the isNomenclaturallyRelevant flag is set. This
730 * indicates that a {@link TaxonNameBase taxon name} has been originally
731 * published in <i>this</i> reference following the rules of a
732 * {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode nomenclature code} and is therefore used for
733 * nomenclatural citations. This flag will be set as soon as <i>this</i>
734 * reference is used as a nomenclatural reference for any taxon name.<BR>
735 * FIXME what happens if the only taxon name referencing this reference is not
736 * any longer using this reference as a nomenclatural reference. How does the
737 * reference get informed about the fact that it is not nomenclaturally relevant
740 public boolean isNomenclaturallyRelevant(){
741 return this.nomenclaturallyRelevant
;
745 * @see #isNomenclaturallyRelevant()
747 public void setNomenclaturallyRelevant(boolean nomenclaturallyRelevant
){
748 this.nomenclaturallyRelevant
= nomenclaturallyRelevant
;
753 // * Returns the full reference that belongs to this abbreviated reference. If this
754 // * reference is not abbreviated the full reference should be <code>null</code>.<BR>
755 // * A full reference should be added to a reference
756 // * which represents the abbreviated form of a reference. The full reference can be used
757 // * by publication tools to link to the unabbreviated and therefore more complete version
758 // * of the reference.
760 // * @see #getAbbreviatedReference()
761 // * @return the full reference
763 // public Reference getFullReference() {
764 // return fullReference;
768 // * @see #getFullReference()
769 // * @param fullReference
771 // public void setFullReference(Reference fullReference) {
772 // this.fullReference = fullReference;
776 // * Returns the abbreviated reference that belongs to this full reference. If this
777 // * reference is not a full reference the abbeviated referece must be <code>null</code>.<BR>
778 // * An abbreviated reference should be added to a reference which represents the long (full)
779 // * form of a reference.
780 // * In future this may become a set or handled differently as there are multiple
782 // * @see #getFullReference()
783 // * @return the full reference
785 // public Reference getAbbreviatedReference() {
786 // return abbreviatedReference;
790 // * @see #getAbbreviatedReference()
791 // * @param abbreviatedReference
794 // public void setAbbreviatedReference(Reference abbreviatedReference) {
795 // this.abbreviatedReference = abbreviatedReference;
798 //**************************************************** /
801 // * Returns the string representing the name of the editor of <i>this</i>
802 // * generic reference. An editor is mostly a person (team) who assumed the
803 // * responsibility for the content of the publication as a whole without
804 // * being the author of this content.<BR>
805 // * If there is an editor then the generic reference must be some
806 // * kind of {@link PrintedUnitBase physical printed unit}.
808 // * @return the string identifying the editor of <i>this</i>
809 // * generic reference
810 // * @see #getPublisher()
812 // protected String getEditor(){
813 // return this.editor;
817 // * @see #getEditor()
819 // protected void setEditor(String editor){
820 // this.editor = editor;
824 // * Returns the string representing the series (for instance for books or
825 // * within journals) - and series part - in which <i>this</i> generic reference
826 // * was published.<BR>
827 // * If there is a series then the generic reference must be some
828 // * kind of {@link PrintedUnitBase physical printed unit} or an {@link Article article}.
830 // * @return the string identifying the series for <i>this</i>
831 // * generic reference
833 // protected String getSeries(){
834 // return this.series;
838 // * @see #getSeries()
840 // protected void setSeries(String series){
841 // this.series = series;
845 // * Returns the string representing the volume (for instance for books or
846 // * within journals) in which <i>this</i> generic reference was published.<BR>
847 // * If there is a volume then the generic reference must be some
848 // * kind of {@link PrintedUnitBase physical printed unit} or an {@link Article article}.
850 // * @return the string identifying the volume for <i>this</i>
851 // * generic reference
853 // protected String getVolume(){
854 // return this.volume;
858 // * @see #getVolume()
860 // protected void setVolume(String volume){
861 // this.volume = volume;
865 // * Returns the string representing the page(s) where the content of
866 // * <i>this</i> generic reference is located.<BR>
867 // * If there is a pages information then the generic reference must be some
868 // * kind of {@link PrintedUnitBase physical printed unit} or an {@link Article article}.
870 // * @return the string containing the pages corresponding to <i>this</i>
871 // * generic reference
873 // protected String getPages(){
874 // return this.pages;
878 // * @see #getPages()
880 // protected void setPages(String pages){
881 // this.pages = pages;
886 * Returns a formatted string containing the entire reference citation,
887 * including authors, corresponding to <i>this</i> reference.
889 * @see #generateTitle()
893 public String
getCitation(){
894 rectifyCacheStrategy();
895 if (getCacheStrategy() == null){
896 logger
.warn("No CacheStrategy defined for "+ this.getClass() + ": " + this.getUuid());
899 return getCacheStrategy().getTitleCache(this);
905 public String
generateTitle() {
906 rectifyCacheStrategy();
907 return super.generateTitle();
910 public String
generateAbbrevTitle() {
911 rectifyCacheStrategy(); //TODO needed, is called by getCacheStrategy already
912 return getCacheStrategy().getAbbrevTitleCache(this);
916 * Returns a string representation for the year of publication / creation
917 * of <i>this</i> reference. If the {@link #getDatePublished() datePublished}
918 * of this reference contains more date information then (starting) year
919 * only the year is returned.
924 public String
getYear(){
925 TimePeriod datePublished
= this.getDatePublished();
926 if (datePublished
!= null ){
927 String result
= getDatePublished().getYear();
935 * Convenience method that returns a string representation for the publication date / creation
936 * of <i>this</i> reference. The string is obtained by
937 * {@link #getDatePublished()#toString() the string representation
938 * of the date published}.
941 public String
getDatePublishedString(){
942 TimePeriod datePublished
= this.getDatePublished();
943 if (datePublished
!= null ){
944 return getDatePublished().toString();
952 public int getParsingProblem(){
953 return this.parsingProblem
;
957 public void setParsingProblem(int parsingProblem
){
958 this.parsingProblem
= parsingProblem
;
962 public boolean hasProblem(){
963 return parsingProblem
!= 0;
967 public boolean hasProblem(ParserProblem problem
) {
968 return getParsingProblems().contains(problem
);
972 public int getProblemStarts(){
973 return this.problemStarts
;
977 public void setProblemStarts(int start
) {
978 this.problemStarts
= start
;
982 public int getProblemEnds(){
983 return this.problemEnds
;
987 public void setProblemEnds(int end
) {
988 this.problemEnds
= end
;
992 public void addParsingProblem(ParserProblem warning
){
993 parsingProblem
= ParserProblem
.addProblem(parsingProblem
, warning
);
997 public void removeParsingProblem(ParserProblem problem
) {
998 parsingProblem
= ParserProblem
.removeProblem(parsingProblem
, problem
);
1003 public List
<ParserProblem
> getParsingProblems() {
1004 return ParserProblem
.warningList(this.parsingProblem
);
1010 public String
getNomenclaturalCitation(String microReference
) {
1011 rectifyCacheStrategy();
1012 String typeName
= this.getType()== null ?
"(no type defined)" : this.getType().getMessage();
1013 if (getCacheStrategy() == null){
1014 logger
.warn("No CacheStrategy defined for "+ typeName
+ ": " + this.getUuid());
1017 if (getCacheStrategy() instanceof INomenclaturalReferenceCacheStrategy
){
1018 return ((INomenclaturalReferenceCacheStrategy
)cacheStrategy
).getNomenclaturalCitation(this, microReference
);
1020 logger
.warn("No INomenclaturalReferenceCacheStrategy defined for "+ typeName
+ ": " + this.getUuid());
1028 * Generates, according to the {@link eu.etaxonomy.cdm.strategy.strategy.cache.reference.IReferenceBaseCacheStrategy cache strategy}
1029 * assigned to <i>this</i> reference, a string that identifies <i>this</i>
1030 * reference and returns it. This string may be stored in the inherited
1031 * {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity#getTitleCache() titleCache} attribute.<BR>
1032 * This method overrides the generic and inherited generateTitle method
1033 * from {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity IdentifiableEntity}.
1035 * @return the string identifying <i>this</i> reference
1036 * @see #getCitation()
1037 * @see eu.etaxonomy.cdm.model.common.IdentifiableEntity#getTitleCache()
1038 * @see eu.etaxonomy.cdm.model.common.IdentifiableEntity#generateTitle()
1039 * @see eu.etaxonomy.cdm.strategy.strategy.cache.common.IIdentifiableEntityCacheStrategy#getTitleCache()
1042 // public String generateTitle(){
1043 // if (cacheStrategy == null){
1044 // logger.warn("No CacheStrategy defined for Reference: " + this.getUuid());
1047 // return cacheStrategy.getTitleCache(this);
1054 // * Returns the reference identity object
1055 // * @return the referenceIdentity
1057 // public ReferenceIdentity getReferenceIdentity() {
1058 // return referenceIdentity;
1062 // * For bidirectional use only
1063 // * @param referenceIdentity the referenceIdentity to set
1065 // protected void setReferenceIdentity(ReferenceIdentity referenceIdentity) {
1066 // this.referenceIdentity = referenceIdentity;
1070 // * Returns the set of all identical references. Same as getReferenceIdentity().getReferences()
1073 // public Set<Reference> identicalReferences(){
1074 // return referenceIdentity.getReferences();
1078 //********** Casting methods ***********************************/
1083 public IArticle
castReferenceToArticle(){
1084 setType(ReferenceType
.Article
);
1088 public IBook
castReferenceToBook(){
1089 setType(ReferenceType
.Book
);
1093 public IBookSection
castReferenceToBookSection(){
1094 setType(ReferenceType
.BookSection
);
1098 public ICdDvd
castReferenceToCdDvd(){
1099 setType(ReferenceType
.CdDvd
);
1103 public IDatabase
castReferenceToDatabase(){
1104 setType(ReferenceType
.Database
);
1108 public IGeneric
castReferenceToGeneric(){
1109 setType(ReferenceType
.Generic
);
1113 public IInProceedings
castReferenceToInProceedings(){
1114 setType(ReferenceType
.InProceedings
);
1118 public IJournal
castReferenceToJournal(){
1119 setType(ReferenceType
.Journal
);
1123 public IMap
castReferenceToMap(){
1124 setType(ReferenceType
.Map
);
1128 public IPatent
castReferenceToPatent(){
1129 setType(ReferenceType
.Patent
);
1133 public IPersonalCommunication
castReferenceToPersonalCommunication(){
1134 setType(ReferenceType
.PersonalCommunication
);
1138 public IPrintSeries
castReferenceToPrintSeries(){
1139 setType(ReferenceType
.PrintSeries
);
1143 public IWebPage
castReferenceToWebPage(){
1144 setType(ReferenceType
.WebPage
);
1148 public IProceedings
castReferenceToProceedings(){
1149 setType(ReferenceType
.Proceedings
);
1153 public IReport
castReferenceToReport(){
1154 setType(ReferenceType
.Report
);
1158 public IThesis
castReferenceToThesis(){
1159 setType(ReferenceType
.Thesis
);
1165 @Transient // prevent from being serialized by webservice
1166 public IJournal
getInJournal() {
1167 IJournal journal
= this.inReference
;
1172 public void setInJournal(IJournal journal
) {
1173 this.inReference
= (Reference
<JournalDefaultCacheStrategy
>) journal
;
1178 @Transient // prevent from being serialized by webservice
1179 public IPrintSeries
getInSeries() {
1180 IPrintSeries printSeries
= this.inReference
;
1185 public void setInSeries(IPrintSeries inSeries
) {
1186 this.inReference
= (Reference
<IReferenceBaseCacheStrategy
>) inSeries
;
1190 @Transient // prevent from being serialized by webservice
1191 public IBook
getInBook() {
1192 IBook book
= this.inReference
;
1196 //********************** In-References *****************************************
1199 public void setInBook(IBook book
) {
1200 this.inReference
= (Reference
<BookDefaultCacheStrategy
>) book
;
1204 @Transient // prevent from being serialized by webservice
1205 public IProceedings
getInProceedings() {
1206 IProceedings proceedings
= this.inReference
;
1211 public void setInProceedings(IProceedings proceeding
) {
1212 this.inReference
= (Reference
<BookDefaultCacheStrategy
>) proceeding
;
1215 //*************************** CACHE STRATEGIES ******************************/
1218 public S
getCacheStrategy() {
1219 rectifyCacheStrategy();
1220 return this.cacheStrategy
;
1224 * The type property of this class is mapped on the field level to the data base column, so
1225 * Hibernate will consequently use the {@link org.hibernate.property.DirectPropertyAccessor}
1226 * to set the property. This PropertyAccessor directly sets the field instead of using the according setter so
1227 * the CacheStrategy is not correctly set after the initialization of the bean. Thus we need to
1228 * validate the CacheStrategy before it is to be used.
1230 private void rectifyCacheStrategy() {
1231 if(!cacheStrategyRectified
){
1233 cacheStrategyRectified
= true;
1238 //public void setCacheStrategy(S cacheStrategy){
1239 // this.cacheStrategy = cacheStrategy;
1243 public void setCacheStrategy(IReferenceBaseCacheStrategy iReferenceBaseCacheStrategy
) {
1244 this.cacheStrategy
= (S
) iReferenceBaseCacheStrategy
;
1249 public void setCacheStrategy(ArticleDefaultCacheStrategy cacheStrategy
) {
1250 this.cacheStrategy
= (S
) cacheStrategy
;
1254 public void setCacheStrategy(BookDefaultCacheStrategy cacheStrategy
) {
1255 this.cacheStrategy
= (S
) cacheStrategy
;
1259 public void setCacheStrategy(JournalDefaultCacheStrategy cacheStrategy
) {
1260 this.cacheStrategy
= (S
) cacheStrategy
;
1264 public void setCacheStrategy(BookSectionDefaultCacheStrategy cacheStrategy
) {
1265 this.cacheStrategy
= (S
) cacheStrategy
;
1269 public void setCacheStrategy(GenericDefaultCacheStrategy cacheStrategy
) {
1270 this.cacheStrategy
= (S
) cacheStrategy
;
1273 public void setCacheStrategy(ReferenceDefaultCacheStrategy cacheStrategy
) {
1274 this.cacheStrategy
= (S
)cacheStrategy
;
1281 // protected void initListener(){
1282 // PropertyChangeListener listener = new PropertyChangeListener() {
1284 // public void propertyChange(PropertyChangeEvent e) {
1285 // boolean protectedByLowerCache = false;
1286 // //authorship cache
1287 // if (fieldHasCacheUpdateProperty(e.getPropertyName(), "authorshipCache")){
1288 // if (protectedAuthorshipCache){
1289 // protectedByLowerCache = true;
1291 // authorshipCache = null;
1296 // if (! fieldHasNoUpdateProperty(e.getPropertyName(), "titleCache")){
1297 // if (isProtectedTitleCache()|| protectedByLowerCache == true ){
1298 // protectedByLowerCache = true;
1300 // titleCache = null;
1303 // //full title cache
1304 // if (! fieldHasNoUpdateProperty(e.getPropertyName(), "fullTitleCache")){
1305 // if (isProtectedFullTitleCache()|| protectedByLowerCache == true ){
1306 // protectedByLowerCache = true;
1308 // fullTitleCache = null;
1313 // addPropertyChangeListener(listener); //didn't use this.addXXX to make lsid.AssemblerTest run in cdmlib-remote
1317 //*********************** CLONE ********************************************************/
1320 * Clones <i>this</i> reference. This is a shortcut that enables to create
1321 * a new instance that differs only slightly from <i>this</i> reference by
1322 * modifying only some of the attributes.
1324 * @see eu.etaxonomy.cdm.model.media.IdentifiableMediaEntity#clone()
1325 * @see java.lang.Object#clone()
1328 public Object
clone() {
1330 Reference
<?
> result
= (Reference
<?
>)super.clone();
1331 result
.setDatePublished(datePublished
!= null?
(TimePeriod
)datePublished
.clone(): null);
1332 //no changes to: title, authorship, hasProblem, nomenclaturallyRelevant, uri
1334 } catch (CloneNotSupportedException e
) {
1335 logger
.warn("Object does not implement cloneable");
1336 e
.printStackTrace();
1341 //******************************* toString *****************************/
1344 public String
toString() {
1346 String result
= "Reference [type=" + type
+ ", id= " + this.getId() + ", uuid=" + this.uuid
;
1347 result
+= title
== null ?
"" : ", title=" + title
;
1348 result
+= abbrevTitle
== null ?
"" : ", abbrevTitle=" + abbrevTitle
;
1352 return super.toString();