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.client.wsrf;
36
37 import java.util.Properties;
38
39 import org.apache.xmlbeans.XmlObject;
40 import org.ogf.graap.wsag.api.exceptions.ResourceUnavailableException;
41 import org.ogf.graap.wsag.api.exceptions.ResourceUnknownException;
42 import org.ogf.graap.wsag.api.security.ISecurityProperties;
43 import org.ogf.graap.wsag.client.api.AgreementClient;
44 import org.ogf.graap.wsag.client.api.impl.AgreementClientImpl;
45 import org.ogf.graap.wsag.client.wsrf.impl.WsrfAgreementService;
46 import org.ogf.graap.wsag.client.wsrf.impl.WsrfResourceClient;
47 import org.ogf.schemas.graap.wsAgreement.AgreementContextType;
48 import org.ogf.schemas.graap.wsAgreement.AgreementPropertiesDocument;
49 import org.ogf.schemas.graap.wsAgreement.AgreementPropertiesType;
50 import org.ogf.schemas.graap.wsAgreement.AgreementStateType;
51 import org.ogf.schemas.graap.wsAgreement.GuaranteeTermStateType;
52 import org.ogf.schemas.graap.wsAgreement.ServiceTermStateType;
53 import org.ogf.schemas.graap.wsAgreement.TermTreeType;
54 import org.ogf.schemas.graap.wsAgreement.TerminateInputType;
55 import org.w3.x2005.x08.addressing.EndpointReferenceType;
56 import org.w3c.dom.Element;
57
58
59
60
61
62
63
64 public class WsrfAgreementClient extends AgreementClientImpl
65 {
66
67 private final WsrfResourceClient client;
68
69 private final WsrfAgreementService agreementClient;
70
71
72
73
74
75
76
77
78
79
80 public WsrfAgreementClient( EndpointReferenceType epr, Properties properties,
81 ISecurityProperties securityProperties )
82 {
83 this( new WsrfResourceClient( epr, properties, securityProperties ) );
84 }
85
86 private WsrfAgreementClient( WsrfResourceClient client )
87 {
88 this.client = client;
89 agreementClient = new WsrfAgreementService( client );
90 }
91
92
93
94
95 @Override
96 public AgreementClient clone() throws CloneNotSupportedException
97 {
98 ISecurityProperties securityProperties = client.getSecurityProperties().clone();
99 return new WsrfAgreementClient( client.getEndpoint(), getProperties(), securityProperties );
100 }
101
102
103
104
105
106
107 @Override
108 public WsrfResourceClient getRemoteClient()
109 {
110 return client;
111 }
112
113
114
115
116 @Override
117 public AgreementContextType getContext() throws ResourceUnknownException, ResourceUnavailableException
118 {
119 return agreementClient.getContext();
120 }
121
122
123
124
125 @Override
126 public GuaranteeTermStateType[] getGuaranteeTermStates()
127 throws ResourceUnknownException, ResourceUnavailableException
128 {
129 return agreementClient.getGuaranteeTermStates();
130 }
131
132
133
134
135 @Override
136 public GuaranteeTermStateType getGuaranteeTermState( String name )
137 throws ResourceUnknownException, ResourceUnavailableException
138 {
139
140 GuaranteeTermStateType[] states = getGuaranteeTermStates();
141 for ( int i = 0; i < states.length; i++ )
142 {
143 GuaranteeTermStateType state = states[i];
144 if ( name.equals( state.getTermName() ) )
145 {
146 return state;
147 }
148 }
149
150 return null;
151 }
152
153
154
155
156 @Override
157 public String getAgreementId() throws ResourceUnknownException, ResourceUnavailableException
158 {
159 return agreementClient.getAgreementId();
160 }
161
162
163
164
165 @Override
166 public String getName() throws ResourceUnknownException, ResourceUnavailableException
167 {
168 return agreementClient.getName();
169 }
170
171
172
173
174 @Override
175 public ServiceTermStateType[] getServiceTermStates()
176 throws ResourceUnknownException, ResourceUnavailableException
177 {
178 return agreementClient.getServiceTermStates();
179 }
180
181
182
183
184 @Override
185 public ServiceTermStateType getServiceTermState( String name )
186 throws ResourceUnknownException, ResourceUnavailableException
187 {
188
189 ServiceTermStateType[] states = getServiceTermStates();
190 for ( int i = 0; i < states.length; i++ )
191 {
192 ServiceTermStateType state = states[i];
193 if ( name.equals( state.getTermName() ) )
194 {
195 return state;
196 }
197 }
198
199 return null;
200 }
201
202
203
204
205 @Override
206 public AgreementStateType getState() throws ResourceUnknownException, ResourceUnavailableException
207 {
208 return agreementClient.getState();
209 }
210
211
212
213
214 @Override
215 public TermTreeType getTerms() throws ResourceUnknownException, ResourceUnavailableException
216 {
217 return agreementClient.getTerms();
218 }
219
220
221
222
223 @Override
224 public void terminate() throws ResourceUnknownException, ResourceUnavailableException
225 {
226 terminate( TerminateInputType.Factory.newInstance() );
227 }
228
229
230
231
232 @Override
233 public void terminate( TerminateInputType reason )
234 throws ResourceUnknownException, ResourceUnavailableException
235 {
236 agreementClient.terminate( reason );
237 }
238
239
240
241
242 @Override
243 public void destroy() throws ResourceUnknownException, ResourceUnavailableException
244 {
245 agreementClient.destroy();
246 }
247
248
249
250
251 public EndpointReferenceType getEndpoint()
252 {
253 return agreementClient.getWebServiceClient().getEndpoint();
254 }
255
256
257
258
259 @Override
260 public Properties getProperties()
261 {
262 return agreementClient.getWebServiceClient().getProperties();
263 }
264
265
266
267
268 @Override
269 public void setProperties( Properties properties )
270 {
271 agreementClient.getWebServiceClient().setProperties( properties );
272 }
273
274
275
276
277 @Override
278 public boolean isUsingTrace()
279 {
280 return agreementClient.getWebServiceClient().isUsingTrace();
281 }
282
283
284
285
286 @Override
287 public void setTrace( boolean trace )
288 {
289 agreementClient.getWebServiceClient().setTrace( trace );
290 }
291
292
293
294
295
296
297
298 @Override
299 public ISecurityProperties getSecurityProperties()
300 {
301 return agreementClient.getWebServiceClient().getSecurityProperties();
302 }
303
304
305
306
307
308
309 @Override
310 public AgreementPropertiesType getResourceProperties()
311 throws ResourceUnknownException, ResourceUnavailableException
312 {
313 try
314 {
315 WsrfResourceClient wsrf = agreementClient.getWebServiceClient();
316 Element doc = wsrf.getResourcePropertyDocument();
317 AgreementPropertiesDocument propertiesDoc =
318 (AgreementPropertiesDocument) XmlObject.Factory.parse( doc );
319 return propertiesDoc.getAgreementProperties();
320 }
321 catch ( Exception e )
322 {
323 throw new ResourceUnavailableException( "Failed to parse server response.", e );
324 }
325 }
326
327 }