1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 /***
19 * <p>Title: WSMO Studio</p>
20 * <p>Description: Semantic Web Service Editor</p>
21 * <p>Copyright: Copyright (c) 2004-2006</p>
22 * <p>Company: OntoText Lab. / SIRMA </p>
23 */
24
25 package org.wsmostudio.ui.editors.model;
26
27 import java.util.Set;
28
29 import org.omwg.ontology.*;
30 import org.wsmo.common.*;
31 import org.wsmo.common.exception.InvalidModelException;
32 import org.wsmostudio.ui.Utils;
33
34 public class AttributeModel extends EntityModel {
35
36 public AttributeModel(Attribute wsmoAttr) {
37 super(wsmoAttr);
38 }
39
40 public Attribute getAttribute() {
41 return (Attribute)getAdapter(Attribute.class);
42 }
43
44 public void addType(Type type) throws InvalidModelException {
45 getAttribute().addType(type);
46 setChanged();
47 }
48
49 public void removeType(Type type) throws InvalidModelException {
50 getAttribute().removeType(type);
51 setChanged();
52 }
53
54 public void setConstraining(boolean constraining) {
55 getAttribute().setConstraining(constraining);
56 setChanged();
57 }
58
59 public void setInverseOf(Identifier attrRef) {
60 getAttribute().setInverseOf(attrRef);
61 setChanged();
62 }
63
64 public void setMaxCardinality(int max) {
65 getAttribute().setMaxCardinality(max);
66 setChanged();
67 }
68
69 public void setMinCardinality(int min) {
70 getAttribute().setMinCardinality(min);
71 setChanged();
72 }
73
74 public void setReflexive(boolean reflexive) {
75 getAttribute().setReflexive(reflexive);
76 setChanged();
77 }
78
79 public void setSymmetric(boolean symmetric) {
80 getAttribute().setSymmetric(symmetric);
81 setChanged();
82 }
83
84 public void setTransitive(boolean transitive) {
85 getAttribute().setTransitive(transitive);
86 setChanged();
87 }
88
89 public void setConcept(Concept newConcept) throws InvalidModelException {
90
91 Attribute thisAttr = this.getAttribute();
92 Attribute newAttr = newConcept.createAttribute(thisAttr.getIdentifier());
93 newAttr.setConstraining(thisAttr.isConstraining());
94 newAttr.setInverseOf(thisAttr.getInverseOf());
95 newAttr.setMaxCardinality(thisAttr.getMaxCardinality());
96 newAttr.setMinCardinality(thisAttr.getMinCardinality());
97 newAttr.setReflexive(thisAttr.isReflexive());
98 newAttr.setSymmetric(thisAttr.isSymmetric());
99 newAttr.setTransitive(thisAttr.isTransitive());
100 for(Type range : thisAttr.listTypes()) {
101 newAttr.addType(range);
102 }
103 for(IRI key : thisAttr.listNFPValues().keySet()) {
104 for(Object value : thisAttr.listNFPValues(key)) {
105 if (value instanceof Identifier) {
106 newAttr.addNFPValue(key, (Identifier)value);
107 }
108 else if (value instanceof Value) {
109 newAttr.addNFPValue(key, (Value)value);
110 }
111 }
112 }
113 if (getMasterModel() instanceof ConceptModel) {
114 ((ConceptModel)getMasterModel()).removeAttribute(thisAttr);
115 }
116 else {
117 thisAttr.getConcept().removeAttribute(thisAttr);
118 getMasterModel().setChanged();
119 }
120
121 this.wsmoDelegate = newAttr;
122 Set<ObservableModel> uiModels = Utils.findModelsForEntity(newConcept);
123 if (uiModels.size() > 0) {
124 setMasterModel(uiModels.iterator().next());
125 }
126 setChanged();
127 }
128
129 }
130
131
132
133
134
135
136
137
138
139
140
141
142
143