1
2
3
4
5
6 package net.kwfgrid.gworkflowdl.protocol.structure;
7
8 import net.kwfgrid.gworkflowdl.structure.*;
9 import net.kwfgrid.gworkflowdl.protocol.calls.*;
10 import net.kwfgrid.gworkflowdl.protocol.xml.GWDLNamespace;
11 import net.kwfgrid.gworkflowdl.protocol.util.StructureUtils;
12
13 /***
14 * Protocol implementation of Place.
15 */
16 public class ProtocolPlace extends ProtocolChildOwls implements Place, GWDLNamespace {
17 /*** The namespace of this object. Used for event notification. */
18 public static final String NAMESPACE = GWDL_NS;
19 /*** The namespace of the properties of this object. Used for event notification. */
20 public static final String NAMESPACE_PROPERTIES = GWDL_ATTRIBUTE_NS;
21 /*** The name of this object. Used for event notification. */
22 public static final String NAME = "place";
23 /*** The name of the owl properties of this object. Used for event notification. */
24 public static final String NAME_OWL = "owl";
25 /*** The name of the token-type property of this object. Used for event notification. */
26 public static final String NAME_TOKENTYPE = "type";
27 /*** The name of the ID property of this object. Used for event notification. */
28 public static final String NAME_ID = "ID";
29 /*** The name of the capacity property of this object. Used for event notification. */
30 public static final String NAME_CAPACITY = "capacity";
31 /*** The name of the description property of this object. Used for event notification. */
32 public static final String NAME_DESCRIPTION = "description";
33
34 protected Place _delegate;
35
36 protected ProtocolPlace(Place delegate) {
37 super(delegate);
38 _delegate = delegate;
39 ((ProtocolProperties)_delegate.getProperties()).setParent(this);
40 }
41
42
43
44 public String getOwlNamespace() {
45 return NAMESPACE;
46 }
47
48 public String getOwlName() {
49 return NAME_OWL;
50 }
51
52
53
54
55
56 public void setID(String id) {
57 getMethodCallStrategy().execute(new PlaceSetID(this, id));
58 }
59
60 public void setTokenType(String type) {
61 getMethodCallStrategy().execute(new PlaceSetTokenType(this, type));
62 }
63
64 public void addToken(Token token) throws CapacityException {
65 try {
66 getMethodCallStrategy().execute(new PlaceAddToken(this, (ProtocolToken)token));
67 } catch (MethodCallException mx) {
68 Throwable cause = mx.getCause();
69 throw (CapacityException)cause;
70 }
71 }
72
73 public void setTokens(Token[] tokens) throws CapacityException {
74 try {
75 getMethodCallStrategy().execute(new PlaceSetTokens(this, (ProtocolToken[])tokens));
76 } catch (MethodCallException mx) {
77 Throwable cause = mx.getCause();
78 throw (CapacityException)cause;
79 }
80 }
81
82 public void removeToken(int i) {
83 getMethodCallStrategy().execute(new PlaceRemoveToken(this, i));
84 }
85
86 public void removeToken(Token token) {
87 getMethodCallStrategy().execute(new PlaceRemoveToken(this, (ProtocolToken)token));
88 }
89
90 public void removeAllTokens() {
91 getMethodCallStrategy().execute(new PlaceRemoveAllTokens(this));
92 }
93
94 public void setCapacity(int capacity) throws CapacityException {
95 try {
96 getMethodCallStrategy().execute(new PlaceSetCapacity(this, capacity));
97 } catch (MethodCallException mx) {
98 Throwable cause = mx.getCause();
99 throw (CapacityException)cause;
100 }
101 }
102
103 public void setDescription(String d) {
104 getMethodCallStrategy().execute(new PlaceSetDescription(this, d));
105 }
106
107 public void setProperties(GenericProperties props) {
108 getMethodCallStrategy().execute(new PlaceSetProperties(this, (ProtocolProperties)props));
109 }
110
111
112
113
114
115 /***
116 This method is only to be used by the protocol.
117 */
118 public void __setID(String id) {
119 _delegate.setID(id);
120 firePropertyChanged(NAMESPACE_PROPERTIES, NAME_ID, id);
121 }
122
123 /***
124 This method is only to be used by the protocol.
125 */
126 public void __setTokenType(String type) {
127 _delegate.setTokenType(type);
128 firePropertyChanged(NAMESPACE_PROPERTIES, NAME_TOKENTYPE, type);
129 }
130
131 /***
132 This method is only to be used by the protocol.
133 */
134 public void __addToken(ProtocolToken token) throws CapacityException {
135 _delegate.addToken(token);
136 token.setParent(this);
137 fireObjectAdded(ProtocolToken.NAMESPACE, ProtocolToken.NAME, token);
138 }
139
140 /***
141 This method is only to be used by the protocol.
142 */
143 public void __setTokens(ProtocolToken[] tokens) throws CapacityException {
144 Token[] old = _delegate.getTokens();
145 _delegate.setTokens(tokens);
146
147 if (old.length>0) {
148 StructureUtils.setParent(old, null);
149 fireObjectsRemoved(ProtocolToken.NAMESPACE, ProtocolToken.NAME, old);
150 }
151 if (tokens.length>0) {
152 StructureUtils.setParent(tokens, this);
153 fireObjectsAdded(ProtocolToken.NAMESPACE, ProtocolToken.NAME, tokens);
154 }
155 }
156
157 /***
158 This method is only to be used by the protocol.
159 */
160 public void __removeToken(int i) {
161 ProtocolToken old = (ProtocolToken)_delegate.getTokens()[i];
162 _delegate.removeToken(i);
163 old.setParent(null);
164 fireObjectRemoved(ProtocolToken.NAMESPACE, ProtocolToken.NAME, old);
165 }
166
167 /***
168 This method is only to be used by the protocol.
169 */
170 public void __removeToken(Token t) {
171 ProtocolToken token = (ProtocolToken)t;
172 if (token.getParent()==this) {
173 _delegate.removeToken(token);
174 ((ProtocolToken)token).setParent(null);
175 fireObjectRemoved(ProtocolToken.NAMESPACE, ProtocolToken.NAME, token);
176 }
177 }
178
179 /***
180 This method is only to be used by the protocol.
181 */
182 public void __removeAllTokens() {
183 Token[] old = _delegate.getTokens();
184 _delegate.removeAllTokens();
185 if (old.length>0) {
186 StructureUtils.setParent(old, null);
187 fireObjectsRemoved(ProtocolToken.NAMESPACE, ProtocolToken.NAME, old);
188 }
189 }
190
191 /***
192 This method is only to be used by the protocol.
193 */
194 public void __setCapacity(int capacity) throws CapacityException {
195 _delegate.setCapacity(capacity);
196 firePropertyChanged(NAMESPACE_PROPERTIES, NAME_CAPACITY, new Integer(capacity));
197 }
198
199 /***
200 This method is only to be used by the protocol.
201 */
202 public void __setDescription(String d) {
203 _delegate.setDescription(d);
204 firePropertyChanged(NAMESPACE_PROPERTIES, NAME_DESCRIPTION, d);
205 }
206
207 /***
208 This method is only to be used by the protocol.
209 */
210 public void __setProperties(ProtocolProperties props) {
211 ProtocolProperties old = (ProtocolProperties)_delegate.getProperties();
212 _delegate.setProperties(props);
213 old.setParent(null);
214 fireObjectRemoved(ProtocolProperties.NAMESPACE, ProtocolProperties.NAME, old);
215 props.setParent(this);
216 fireObjectAdded(ProtocolProperties.NAMESPACE, ProtocolProperties.NAME, props);
217 }
218
219
220
221
222
223 public String getID() {
224 return _delegate.getID();
225 }
226
227 public String getTokenType() {
228 return _delegate.getTokenType();
229 }
230
231 public boolean isEmpty() {
232 return _delegate.isEmpty();
233 }
234
235 public Token[] getTokens() {
236 return _delegate.getTokens();
237 }
238
239 public int getCapacity() {
240 return _delegate.getCapacity();
241 }
242
243 public int getTokenNumber() {
244 return _delegate.getTokenNumber();
245 }
246
247 public String getDescription() {
248 return _delegate.getDescription();
249 }
250
251 public GenericProperties getProperties() {
252 return _delegate.getProperties();
253 }
254 }