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
.common
;
13 import org
.apache
.log4j
.Logger
;
14 import org
.hibernate
.annotations
.Cascade
;
15 import org
.hibernate
.annotations
.CascadeType
;
18 import javax
.persistence
.*;
21 * A single enumeration must only contain DefinedTerm instances of one kind
25 * @created 08-Nov-2007 13:06:23
28 public class TermVocabulary
extends TermBase
{
29 static Logger logger
= Logger
.getLogger(TermVocabulary
.class);
30 //The order of the enumeration list is a linear order that can be used for statistical purposes. Measurement scale =
32 private boolean isOrdinal
;
33 protected List
<DefinedTermBase
> terms
= new ArrayList();
34 //The vocabulary source (e.g. ontology) defining the terms to be loaded when a database is created for the first time.
35 // Software can go and grap these terms incl labels and description.
36 // UUID needed? Further vocs can be setup through our own ontology.
37 private String termSourceUri
;
38 private Class termClass
;
41 public TermVocabulary() {
44 public TermVocabulary(String term
, String label
, String termSourceUri
) {
46 setTermSourceUri(termSourceUri
);
50 public boolean isOrdinal(){
51 return this.isOrdinal
;
53 public void setOrdinal(boolean isOrdinal
){
54 this.isOrdinal
= isOrdinal
;
58 @OneToMany(mappedBy
="vocabulary")
59 @Cascade({CascadeType
.SAVE_UPDATE
, CascadeType
.DELETE
})
60 public List
<DefinedTermBase
> getTerms() {
63 protected void setTerms(List
<DefinedTermBase
> terms
) {
66 public void addTerm(DefinedTermBase term
) throws WrongTermTypeException
{
68 // no term yet in the list. First term defines the vocabulary kind
69 termClass
=term
.getClass();
70 }else if (term
.getClass()!=termClass
){
71 // check if new term in this vocabulary matches the previous ones
72 throw new WrongTermTypeException(term
.getClass().getCanonicalName());
74 term
.setVocabulary(this);
76 public void removeTerm(DefinedTermBase term
) {
77 term
.setVocabulary(null);
81 public List
<DefinedTermBase
> getPrecedingTerms(OrderedTermBase otb
) {
82 // FIXME: need to return only OrderedTermBase lists
83 return terms
.subList(0, terms
.indexOf(otb
));
85 public List
<DefinedTermBase
> getSucceedingTerms(OrderedTermBase otb
) {
86 // FIXME: need to return only OrderedTermBase lists
87 return terms
.subList(terms
.indexOf(otb
), terms
.size());
89 public OrderedTermBase
getPreviousTerm(OrderedTermBase otb
) {
90 int idx
= terms
.indexOf(otb
)-1;
91 return (OrderedTermBase
)terms
.get(idx
);
93 public OrderedTermBase
getNextTerm(OrderedTermBase otb
) {
94 int idx
= terms
.indexOf(otb
)+1;
95 return (OrderedTermBase
)terms
.get(idx
);
99 public String
getTermSourceUri() {
100 return termSourceUri
;
102 public void setTermSourceUri(String vocabularyUri
) {
103 this.termSourceUri
= vocabularyUri
;
107 protected Class
getTermClass() {
110 protected void setTermClass(Class termClass
) {
111 this.termClass
= termClass
;