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.util.StructureUtils;
11 import net.kwfgrid.gworkflowdl.protocol.xml.GWDLNamespace;
12
13 /***
14 * Protocol implementation of GenericProperties.
15 */
16 public class ProtocolProperties extends AbstractChildObject implements GenericProperties, GWDLNamespace {
17 /*** The namespace of this object. Used for event notification. */
18 public static final String NAMESPACE = GWDL_NS;
19 /*** The name of this object. Used for event notification. */
20 public static final String NAME = "properties";
21
22 protected GenericProperties _delegate;
23
24 protected ProtocolProperties(GenericProperties delegate) {
25 super();
26 _delegate = delegate;
27 }
28
29
30
31
32
33 public void setProperty(int i, Property prop) {
34 getMethodCallStrategy().execute(new GenericPropertiesSetProperty(this, i, (ProtocolProperty)prop));
35 }
36
37 public void setProperties(Property[] props) {
38 getMethodCallStrategy().execute(new GenericPropertiesSetProperties(this, (ProtocolProperty[])StructureUtils.castArray(ProtocolProperty.class, props)));
39 }
40
41 public String put(String key, String value) {
42 return (String)getMethodCallStrategy().execute(new GenericPropertiesPut(this, key, value));
43 }
44
45 public String remove(String key) {
46 return (String)getMethodCallStrategy().execute(new GenericPropertiesRemove(this, key));
47 }
48
49 public void addProperty(Property prop) {
50 getMethodCallStrategy().execute(new GenericPropertiesAddProperty(this, (ProtocolProperty)prop));
51 }
52
53 public void removeProperty(int i) {
54 getMethodCallStrategy().execute(new GenericPropertiesRemoveProperty(this, i));
55 }
56
57
58
59
60
61 /***
62 This method is only to be used by the protocol.
63 */
64 public void __setProperty(int i, ProtocolProperty prop) {
65 ProtocolProperty old = (ProtocolProperty)_delegate.getProperty(i);
66 _delegate.setProperty(i, prop);
67 prop.setParent(this);
68 if (old != null) {
69 old.setParent(null);
70 fireObjectRemoved(ProtocolProperty.NAMESPACE, ProtocolProperty.NAME, old);
71 }
72 fireObjectAdded(ProtocolProperty.NAMESPACE, ProtocolProperty.NAME, prop);
73 }
74
75 /***
76 This method is only to be used by the protocol.
77 */
78 public void __setProperties(ProtocolProperty[] props) {
79 Property[] old = _delegate.getProperties();
80 _delegate.setProperties(props);
81 if (old.length>0) {
82 StructureUtils.setParent(old, null);
83 fireObjectsRemoved(ProtocolProperty.NAMESPACE, ProtocolProperty.NAME, old);
84 }
85 if (props.length>0) {
86 StructureUtils.setParent(props, this);
87 fireObjectsAdded(ProtocolProperty.NAMESPACE, ProtocolProperty.NAME, props);
88 }
89 }
90
91 private ProtocolProperty find(String key) {
92 if (key == null) return null;
93 Property[] ps = _delegate.getProperties();
94 if (ps == null) return null;
95 for (int i=0; i<ps.length; i++) {
96 if (key.equals(ps[i].getKey())) {
97 return (ProtocolProperty)ps[i];
98 }
99 }
100 return null;
101 }
102
103 /***
104 This method is only to be used by the protocol.
105 */
106 public String __put(String key, String value) {
107 ProtocolProperty old = find(key);
108 if (old == null) {
109 old = (ProtocolProperty)Factory.newProperty(key, value);
110 _delegate.addProperty(old);
111 old.setParent(this);
112 fireObjectAdded(ProtocolProperty.NAMESPACE, ProtocolProperty.NAME, old);
113 return null;
114 } else {
115 String ret = old.getValue();
116 old.__setValue(value);
117 return ret;
118 }
119 }
120
121 /***
122 This method is only to be used by the protocol.
123 */
124 public String __remove(String key) {
125 Property[] old = _delegate.getProperties();
126 String ret = _delegate.remove(key);
127 if (old.length > _delegate.size()) {
128 ProtocolProperty theproperty = null;
129 for (int i=0; i<old.length; i++) {
130 if (old[i].getKey().equals(key)) {
131 theproperty = (ProtocolProperty)old[i];
132 break;
133 }
134 }
135 theproperty.setParent(null);
136 fireObjectRemoved(ProtocolProperty.NAMESPACE, ProtocolProperty.NAME, theproperty);
137 }
138 return ret;
139 }
140
141 /***
142 This method is only to be used by the protocol.
143 */
144 public void __addProperty(ProtocolProperty prop) {
145 _delegate.addProperty(prop);
146 prop.setParent(this);
147 fireObjectAdded(ProtocolProperty.NAMESPACE, ProtocolProperty.NAME, prop);
148 }
149
150 /***
151 This method is only to be used by the protocol.
152 */
153 public void __removeProperty(int i) {
154 ProtocolProperty old = (ProtocolProperty)_delegate.getProperty(i);
155 _delegate.removeProperty(i);
156 old.setParent(null);
157 fireObjectRemoved(ProtocolProperty.NAMESPACE, ProtocolProperty.NAME, old);
158 }
159
160
161
162
163
164 public String get(String key) {
165 return _delegate.get(key);
166 }
167
168 public int size() {
169 return _delegate.size();
170 }
171
172 public Property getProperty(int i) {
173 return _delegate.getProperty(i);
174 }
175
176 public Property[] getProperties() {
177 return _delegate.getProperties();
178 }
179
180 public String[] keys() {
181 return _delegate.keys();
182 }
183
184 public GenericProperties deepCopy() {
185 return _delegate.deepCopy();
186 }
187 }