1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 package org.ogf.graap.wsag.server.monitoring;
36
37 import java.util.HashMap;
38 import java.util.Map;
39 import java.util.Vector;
40
41 import org.apache.xmlbeans.XmlObject;
42 import org.ogf.graap.wsag.server.accounting.IAccountingSystem;
43 import org.ogf.graap.wsag.server.accounting.SimpleAccountingSystemLogger;
44 import org.ogf.schemas.graap.wsAgreement.ServiceTermStateDefinition;
45 import org.ogf.schemas.graap.wsAgreement.ServiceTermStateDocument;
46 import org.ogf.schemas.graap.wsAgreement.ServiceTermStateType;
47
48
49
50
51
52
53
54 public class MonitoringContext implements IMonitoringContext
55 {
56
57 private Vector<ServiceTermStateType> serviceTermStates = new Vector<ServiceTermStateType>();
58
59 private Vector<IServiceTermMonitoringHandler> monitoringHandler =
60 new Vector<IServiceTermMonitoringHandler>();
61
62 private IAccountingSystem accountingSystem = new SimpleAccountingSystemLogger();
63
64
65
66
67 private HashMap<String, XmlObject> executionProperties = new HashMap<String, XmlObject>();
68
69
70
71
72 private Map<String, Object> transientExecutionProperties = new HashMap<String, Object>();
73
74
75
76
77
78
79
80
81 public void addServiceTemState( String name )
82 {
83 ServiceTermStateType state = ServiceTermStateDocument.Factory.newInstance().addNewServiceTermState();
84 state.setTermName( name );
85 state.setState( ServiceTermStateDefinition.NOT_READY );
86 addServiceTemState( state );
87 }
88
89
90
91
92
93
94
95 public void addServiceTemState( ServiceTermStateType state )
96 {
97 serviceTermStates.add( state );
98 }
99
100
101
102
103
104
105 public ServiceTermStateType[] getServiceTermStates()
106 {
107 return serviceTermStates.toArray( new ServiceTermStateType[serviceTermStates.size()] );
108 }
109
110
111
112
113
114
115
116 public void removeServiceTemState( ServiceTermStateType state )
117 {
118 serviceTermStates.remove( state );
119 }
120
121
122
123
124
125
126 public void setServiceTemState( ServiceTermStateType[] states )
127 {
128 serviceTermStates.clear();
129 for ( int i = 0; i < states.length; i++ )
130 {
131 serviceTermStates.add( states[i] );
132 }
133 }
134
135
136
137
138
139
140
141
142
143 public ServiceTermStateType getServiceTermStateByName( String name )
144 {
145 for ( int i = 0; i < serviceTermStates.size(); i++ )
146 {
147 ServiceTermStateType termState = serviceTermStates.get( i );
148
149 if ( name.equals( termState.getTermName() ) )
150 {
151 return termState;
152 }
153 }
154
155 return null;
156 }
157
158
159
160
161
162
163 public Map<String, XmlObject> getProperties()
164 {
165 return executionProperties;
166 }
167
168
169
170
171
172
173 public void setProperties( Map<String, XmlObject> properties )
174 {
175 executionProperties.clear();
176 executionProperties.putAll( properties );
177 }
178
179
180
181
182
183
184 public Map<String, Object> getTransientProperties()
185 {
186 return transientExecutionProperties;
187 }
188
189
190
191
192
193
194 public void setTransientProperties( Map<String, Object> properties )
195 {
196 transientExecutionProperties = properties;
197 }
198
199
200
201
202
203
204 public void addMonitoringHandler( IServiceTermMonitoringHandler handler )
205 {
206 monitoringHandler.add( handler );
207 }
208
209
210
211
212
213
214 public IServiceTermMonitoringHandler[] getMonitoringHandler()
215 {
216 return monitoringHandler.toArray( new IServiceTermMonitoringHandler[monitoringHandler.size()] );
217 }
218
219
220
221
222
223
224 public void removeMonitoringHandler( IServiceTermMonitoringHandler handler )
225 {
226 monitoringHandler.remove( handler );
227 }
228
229
230
231
232
233
234 public void setMonitoringHandler( IServiceTermMonitoringHandler[] handler )
235 {
236 monitoringHandler.clear();
237 for ( int i = 0; i < handler.length; i++ )
238 {
239 monitoringHandler.add( handler[i] );
240 }
241 }
242
243
244
245
246
247
248 public Object clone()
249 {
250 IMonitoringContext currentMonitoringContext = new MonitoringContext();
251
252 currentMonitoringContext.setProperties( getProperties() );
253 currentMonitoringContext.setTransientProperties( getTransientProperties() );
254
255 for ( int i = 0; i < serviceTermStates.size(); i++ )
256 {
257 ServiceTermStateType state = (ServiceTermStateType) serviceTermStates.get( i );
258 currentMonitoringContext.addServiceTemState( (ServiceTermStateType) state.copy() );
259 }
260
261 for ( int i = 0; i < monitoringHandler.size(); i++ )
262 {
263 IServiceTermMonitoringHandler handler = (IServiceTermMonitoringHandler) monitoringHandler.get( i );
264 currentMonitoringContext.addMonitoringHandler( handler );
265 }
266
267 currentMonitoringContext.setAccountingSystem( getAccountingSystem() );
268
269 return currentMonitoringContext;
270 }
271
272
273
274
275
276
277
278 public void setAccountingSystem( IAccountingSystem accountingSystem )
279 {
280 this.accountingSystem = accountingSystem;
281 }
282
283
284
285
286 public IAccountingSystem getAccountingSystem()
287 {
288 return accountingSystem;
289 }
290
291 }