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.AgreementOffer;
41 import org.ogf.graap.wsag.api.WsagConstants;
42 import org.ogf.graap.wsag.api.exceptions.AgreementFactoryException;
43 import org.ogf.graap.wsag.api.exceptions.NegotiationFactoryException;
44 import org.ogf.graap.wsag.api.exceptions.ResourceUnavailableException;
45 import org.ogf.graap.wsag.api.exceptions.ResourceUnknownException;
46 import org.ogf.graap.wsag.api.security.ISecurityProperties;
47 import org.ogf.graap.wsag.client.api.AgreementClient;
48 import org.ogf.graap.wsag.client.api.AgreementFactoryClient;
49 import org.ogf.graap.wsag.client.api.NegotiationClient;
50 import org.ogf.graap.wsag.client.api.RemoteClient;
51 import org.ogf.graap.wsag.client.wsrf.impl.WsrfAgreementFactoryService;
52 import org.ogf.graap.wsag.client.wsrf.impl.WsrfAgreementRegistryService;
53 import org.ogf.graap.wsag.client.wsrf.impl.WsrfResourceClient;
54 import org.ogf.schemas.graap.wsAgreement.AgreementFactoryPropertiesDocument;
55 import org.ogf.schemas.graap.wsAgreement.AgreementFactoryPropertiesType;
56 import org.ogf.schemas.graap.wsAgreement.AgreementTemplateType;
57 import org.ogf.schemas.graap.wsAgreement.negotiation.NegotiationContextType;
58 import org.w3.x2005.x08.addressing.EndpointReferenceDocument;
59 import org.w3.x2005.x08.addressing.EndpointReferenceType;
60 import org.w3c.dom.Element;
61
62
63
64
65
66
67
68 public class WsrfAgreementFactoryClient extends RemoteClient
69 implements AgreementFactoryClient
70 {
71
72
73
74
75 private final WsrfAgreementFactoryService factoryClient;
76
77
78
79
80 private final WsrfAgreementRegistryService registryClient;
81
82
83
84
85
86
87
88
89
90
91 public WsrfAgreementFactoryClient( EndpointReferenceType epr, Properties properties,
92 ISecurityProperties securityProperties )
93 {
94 super( epr, properties, securityProperties );
95 try
96 {
97
98
99
100 String factoryURI = epr.getAddress().getStringValue();
101 String registryURI =
102 factoryURI.substring( 0, factoryURI.indexOf( WsagConstants.AGREEMENT_FACTORY_SERVICE_URI ) )
103 + WsagConstants.AGREEMENT_REGISTRY_SERVICE_URI;
104
105 EndpointReferenceDocument registryEPR = EndpointReferenceDocument.Factory.newInstance();
106 registryEPR.addNewEndpointReference().addNewAddress().setStringValue( registryURI );
107 registryEPR.getEndpointReference().addNewReferenceParameters().set( epr.getReferenceParameters() );
108
109
110
111
112 factoryClient = new WsrfAgreementFactoryService( epr, getProperties(), getSecurityProperties() );
113
114 registryClient =
115 new WsrfAgreementRegistryService( registryEPR.getEndpointReference(), getProperties(),
116 getSecurityProperties() );
117 }
118 catch ( Exception e )
119 {
120 throw new RuntimeException( e );
121 }
122
123 }
124
125
126
127
128 @Override
129 public AgreementFactoryClient clone() throws CloneNotSupportedException
130 {
131 return new WsrfAgreementFactoryClient( getEndpoint(), getProperties(),
132 getSecurityProperties().clone() );
133 }
134
135
136
137
138 public RemoteClient getWebServiceClient()
139 {
140 return this;
141 }
142
143
144
145
146 public EndpointReferenceType getEndpoint()
147 {
148 return getRemoteReference();
149 }
150
151
152
153
154
155
156 public RemoteClient getRemoteClient()
157 {
158 return this;
159 }
160
161
162
163
164
165
166 public AgreementTemplateType[] getTemplates()
167 throws ResourceUnknownException, ResourceUnavailableException
168 {
169 return factoryClient.getTemplates();
170 }
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189 public AgreementClient createAgreement( AgreementOffer offer )
190 throws AgreementFactoryException, ResourceUnknownException, ResourceUnavailableException
191 {
192 return factoryClient.createAgreement( offer );
193 }
194
195
196
197
198
199
200 public AgreementClient createPendingAgreement( AgreementOffer offer )
201 throws AgreementFactoryException, ResourceUnknownException, ResourceUnavailableException
202 {
203 return factoryClient.createPendingAgreement( offer );
204 }
205
206
207
208
209
210
211 public AgreementClient createPendingAgreement( AgreementOffer offer, EndpointReferenceType acceptanceEPR )
212 throws AgreementFactoryException, ResourceUnknownException, ResourceUnavailableException
213 {
214 return factoryClient.createPendingAgreement( offer, acceptanceEPR );
215 }
216
217
218
219
220
221
222 public NegotiationClient initiateNegotiation( NegotiationContextType context )
223 throws NegotiationFactoryException, ResourceUnknownException, ResourceUnavailableException
224 {
225 return factoryClient.initiateNegotiation( context );
226 }
227
228
229
230
231 public String getResourceId() throws ResourceUnknownException, ResourceUnavailableException
232 {
233 return factoryClient.getResourceId();
234 }
235
236
237
238
239
240
241
242 public AgreementTemplateType getTemplate( String name, String id )
243 throws ResourceUnknownException, ResourceUnavailableException
244 {
245 if ( name == null )
246 {
247 return null;
248 }
249
250 id = ( id != null ) ? id : "";
251
252 AgreementTemplateType[] templates = getTemplates();
253
254 for ( int i = 0; i < templates.length; i++ )
255 {
256 if ( name.equalsIgnoreCase( templates[i].getName() ) )
257 {
258
259 String actualId =
260 ( templates[i].getTemplateId() != null ) ? templates[i].getTemplateId() : "";
261
262 if ( id.equalsIgnoreCase( actualId ) )
263 {
264 return templates[i];
265 }
266 }
267 }
268
269 return null;
270 }
271
272
273
274
275
276
277
278
279
280
281
282
283 public AgreementClient[] listAgreements() throws ResourceUnknownException, ResourceUnavailableException
284 {
285 return registryClient.listAgreements();
286 }
287
288
289
290
291
292
293
294 @Override
295 public void setTrace( boolean trace )
296 {
297 factoryClient.getWebServiceClient().setTrace( trace );
298 registryClient.getWebServiceClient().setTrace( trace );
299 }
300
301
302
303
304
305 @Override
306 public void setProperties( Properties properties )
307 {
308 super.setProperties( properties );
309 factoryClient.getWebServiceClient().setProperties( properties );
310 registryClient.getWebServiceClient().setProperties( properties );
311 }
312
313
314
315
316 public WsrfAgreementFactoryService getAgreementFactoryClient()
317 {
318 return factoryClient;
319 }
320
321
322
323
324 public WsrfAgreementRegistryService getAgreementRegistryClient()
325 {
326 return registryClient;
327 }
328
329
330
331
332
333
334 public AgreementFactoryPropertiesType getResourceProperties()
335 throws ResourceUnknownException, ResourceUnavailableException
336 {
337 try
338 {
339 WsrfResourceClient wsrf = getAgreementFactoryClient().getWebServiceClient();
340 Element doc = wsrf.getResourcePropertyDocument();
341 AgreementFactoryPropertiesDocument propertiesDoc =
342 (AgreementFactoryPropertiesDocument) XmlObject.Factory.parse( doc );
343 return propertiesDoc.getAgreementFactoryProperties();
344 }
345 catch ( Exception e )
346 {
347 throw new ResourceUnavailableException( "Failed to parse server response.", e );
348 }
349 }
350
351 }