1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package com.ontotext.wsmo4j.ontology;
20
21
22
23
24
25
26
27
28
29
30 import java.util.Collections;
31 import java.util.LinkedHashSet;
32 import java.util.Set;
33
34 import org.omwg.ontology.Attribute;
35 import org.omwg.ontology.Concept;
36 import org.omwg.ontology.Type;
37 import org.wsmo.common.Identifier;
38 import org.wsmo.common.exception.InvalidModelException;
39 import org.wsmo.common.exception.SynchronisationException;
40
41 import com.ontotext.wsmo4j.common.EntityImpl;
42
43
44 public class AttributeImpl extends EntityImpl
45 implements Attribute {
46
47 private Concept domain;
48
49 private LinkedHashSet <Type> ranges;
50
51 private int minCardinality = 0;
52
53 private int maxCardinality = Integer.MAX_VALUE;
54
55 private boolean constraining = false,
56 reflexive = false,
57 symmetric = false,
58 transitive = false;
59
60 private Identifier inverseAttribute = null;
61
62 public AttributeImpl(Identifier thisID, Concept domain) {
63 super(thisID);
64 this.domain = domain;
65
66 ranges = new LinkedHashSet <Type> ();
67 }
68
69 public Concept getConcept() throws SynchronisationException {
70 return this.domain;
71 }
72
73 public void removeFromConcept() throws InvalidModelException {
74 if (domain == null)
75 return;
76 Concept old = domain;
77 domain = null;
78 old.removeAttribute(this);
79 }
80
81 public boolean isConstraining() {
82 return constraining;
83 }
84
85 public void setConstraining(boolean constraining) {
86 this.constraining = constraining;
87 }
88
89 public int getMinCardinality() {
90 return this.minCardinality;
91 }
92
93 public void setMinCardinality(int min) {
94 this.minCardinality = min;
95 }
96
97 public int getMaxCardinality() {
98 return this.maxCardinality;
99 }
100
101 public void setMaxCardinality(int max) {
102 this.maxCardinality = max;
103 }
104
105 public Set <Type> listTypes() {
106 return Collections.unmodifiableSet(ranges);
107 }
108
109 public void addType(Type type) throws InvalidModelException {
110 if (type == null) {
111 throw new IllegalArgumentException();
112 }
113 ranges.add(type);
114 }
115
116 public void removeType(Type type) throws InvalidModelException {
117 if (type == null) {
118 throw new IllegalArgumentException();
119 }
120 ranges.remove(type);
121 }
122
123 public boolean isReflexive() {
124 return this.reflexive;
125 }
126
127 public void setReflexive(boolean reflexive) {
128 this.reflexive = reflexive;
129 }
130
131 public boolean isSymmetric() {
132 return symmetric;
133 }
134
135 public void setSymmetric(boolean symmetric) {
136 this.symmetric = symmetric;
137 }
138
139 public boolean isTransitive() {
140 return this.transitive;
141 }
142
143 public void setTransitive(boolean trans) {
144 this.transitive = trans;
145 }
146
147 public Identifier getInverseOf() {
148 return this.inverseAttribute;
149 }
150
151 public void setInverseOf(Identifier id) {
152 this.inverseAttribute = id;
153 }
154
155 public boolean equals(Object object) {
156 if (object == this) {
157 return true;
158 }
159 if (object == null
160 || false == object instanceof Attribute) {
161 return false;
162 }
163 Attribute anotherAttr = (Attribute)object;
164 if (getConcept() == null) {
165 if (anotherAttr.getConcept() != null) {
166 return false;
167 }
168 }
169 else {
170 if (!getConcept().equals(anotherAttr.getConcept())) {
171 return false;
172 }
173 }
174 return super.equals(object);
175 }
176
177 }
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238