1
18 package gate.creole.ontology;
19
20 import java.util.ArrayList;
21 import java.util.HashMap;
22 import java.util.List;
23 import java.util.Set;
24
25
31 public class OntologyResourceImpl implements OntologyResource {
32 protected String uri;
33 protected String comment;
34 protected String name;
35 protected Taxonomy taxonomy;
36 protected Ontology ontology;
37 protected HashMap instanceProperties;
38
39 public OntologyResourceImpl(String uri, String name, String comment,
40 Taxonomy taxonomy) {
41 this.comment = comment;
42 this.name = name;
43 this.taxonomy = taxonomy;
44 this.ontology = taxonomy instanceof Ontology ? (Ontology)taxonomy : null;
45 this.uri = uri;
46 this.instanceProperties = new HashMap();
47 }
48
49
56 public OntologyResourceImpl(String name, String comment, Taxonomy taxonomy) {
57 this(name, name, comment, taxonomy);
58 }
59
60 public boolean addPropertyValue(String propertyName, Object theValue) {
61 Property prop = ((Ontology)ontology)
65 .getPropertyDefinitionByName(propertyName);
66 if(prop == null) return false;
67 if(prop.isValidDomain(this)) {
68 List values = (List)instanceProperties.get(propertyName);
69 if(values == null) {
70 values = new ArrayList();
71 instanceProperties.put(propertyName, values);
72 }
73 values.add(theValue);
74 return true;
75 } else return false;
76 }
77
78 public Set getSetPropertiesNames() {
79 return instanceProperties.keySet();
80 }
81
82 public List getPropertyValues(String propertyName) {
83 return (List)instanceProperties.get(propertyName);
84 }
85
86 public boolean removePropertyValue(String propertyName, Object theValue) {
87 List values = (List)instanceProperties.get(propertyName);
88 if(values != null) {
89 return values.remove(theValue);
90 } else return false;
91 }
92
93 public void removePropertyValues(String propertyName) {
94 instanceProperties.remove(propertyName);
95 }
96
97 public Object getPropertyValue(String propertyName) {
98 if(instanceProperties == null || instanceProperties.isEmpty()) return null;
99 return instanceProperties.get(propertyName);
100 }
101
102
105 public String getComment() {
106 return comment;
107 }
108
109
113 public void setComment(String comment) {
114 this.comment = comment;
115 }
116
117
120 public String getName() {
121 return name;
122 }
123
124
128 public void setName(String name) {
129 this.name = name;
130 }
131
132
135 public Taxonomy getTaxonomy() {
136 return taxonomy;
137 }
138
139
142 public Ontology getOntology() {
143 return ontology;
144 }
145
146
150 public void setOntology(Taxonomy ontology) {
151 this.taxonomy = ontology;
152 }
153
154
157 public String getURI() {
158 return uri;
159 }
160
161
165 public void setURI(String uri) {
166 this.uri = uri;
167 }
168 }
169