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.remote;
36
37 import org.apache.muse.util.xml.XmlUtils;
38 import org.apache.muse.ws.addressing.soap.SoapFault;
39 import org.apache.xmlbeans.XmlException;
40 import org.apache.xmlbeans.XmlNCName;
41 import org.apache.xmlbeans.XmlObject;
42 import org.apache.xmlbeans.XmlOptions;
43 import org.ogf.graap.wsag.api.WsagConstants;
44 import org.ogf.graap.wsag.api.client.AgreementService;
45 import org.ogf.graap.wsag.api.client.WsClient;
46 import org.ogf.graap.wsag.api.exceptions.ResourceUnavailableException;
47 import org.ogf.graap.wsag.api.exceptions.ResourceUnknownException;
48 import org.ogf.schemas.graap.wsAgreement.AgreementContextType;
49 import org.ogf.schemas.graap.wsAgreement.AgreementIdDocument;
50 import org.ogf.schemas.graap.wsAgreement.AgreementStateDocument;
51 import org.ogf.schemas.graap.wsAgreement.AgreementStatePropertiesType;
52 import org.ogf.schemas.graap.wsAgreement.AgreementStateType;
53 import org.ogf.schemas.graap.wsAgreement.GuaranteeTermStateType;
54 import org.ogf.schemas.graap.wsAgreement.ServiceTermStateType;
55 import org.ogf.schemas.graap.wsAgreement.TermTreeType;
56 import org.ogf.schemas.graap.wsAgreement.TerminateInputType;
57 import org.ogf.schemas.graap.wsAgreement.TerminateResponseDocument;
58 import org.w3c.dom.Element;
59
60
61
62
63
64
65
66 public class RemoteAgreementServiceImpl implements AgreementService
67 {
68
69 private WsrfResourceClient client;
70
71
72
73
74
75
76 public RemoteAgreementServiceImpl( WsrfResourceClient client )
77 {
78 this.client = client;
79 }
80
81
82
83
84 public WsClient getWebServiceClient()
85 {
86 return client;
87 }
88
89
90
91
92 public AgreementContextType getContext() throws ResourceUnavailableException
93 {
94 try
95 {
96 Element body =
97 XmlUtils.createElement( WsagConstants.WSRF_GET_RESOURCE_PROPERTY_QNAME, "wsag:Context" );
98 body.setAttribute( WsagConstants.WSAG_PREFIX_DECLARATION, WsagConstants.NAMESPACE_URI );
99
100 Element response = client.invoke( WsagConstants.WSRF_GET_RESOURCE_PROPERTY_ACTION, body );
101
102 AgreementContextType respDoc =
103 AgreementContextType.Factory.parse( XmlUtils.getFirstElement( response ),
104 new XmlOptions().setLoadReplaceDocumentElement( null ) );
105
106 return respDoc;
107 }
108 catch ( SoapFault e )
109 {
110 throw new ResourceUnavailableException( e );
111 }
112 catch ( XmlException e )
113 {
114 throw new ResourceUnavailableException( e );
115 }
116 }
117
118
119
120
121 public GuaranteeTermStateType[] getGuaranteeTermStates() throws ResourceUnavailableException
122 {
123 try
124 {
125 Element body =
126 XmlUtils.createElement( WsagConstants.WSRF_GET_RESOURCE_PROPERTY_QNAME,
127 "wsag:GuaranteeTermState" );
128 body.setAttribute( WsagConstants.WSAG_PREFIX_DECLARATION, WsagConstants.NAMESPACE_URI );
129
130 Element response = client.invoke( WsagConstants.WSRF_GET_RESOURCE_PROPERTY_ACTION, body );
131
132 AgreementStatePropertiesType props =
133 AgreementStatePropertiesType.Factory.parse( response,
134 new XmlOptions().setLoadReplaceDocumentElement( null ) );
135
136 GuaranteeTermStateType[] states = props.getGuaranteeTermStateArray();
137
138 return states;
139
140 }
141 catch ( SoapFault e )
142 {
143 throw new ResourceUnavailableException( e );
144 }
145 catch ( XmlException e )
146 {
147 throw new ResourceUnavailableException( e );
148 }
149 }
150
151
152
153
154 public String getAgreementId() throws ResourceUnavailableException
155 {
156 try
157 {
158 Element body =
159 XmlUtils.createElement( WsagConstants.WSRF_GET_RESOURCE_PROPERTY_QNAME, "wsag:AgreementId" );
160 body.setAttribute( WsagConstants.WSAG_PREFIX_DECLARATION, WsagConstants.NAMESPACE_URI );
161
162 Element response = client.invoke( WsagConstants.WSRF_GET_RESOURCE_PROPERTY_ACTION, body );
163
164 AgreementIdDocument id =
165 AgreementIdDocument.Factory.parse( response,
166 new XmlOptions().setLoadReplaceDocumentElement( null ) );
167
168 return id.getAgreementId();
169 }
170 catch ( SoapFault e )
171 {
172 throw new ResourceUnavailableException( e );
173 }
174 catch ( XmlException e )
175 {
176 throw new ResourceUnavailableException( e );
177 }
178 }
179
180
181
182
183 public String getName() throws ResourceUnavailableException
184 {
185 try
186 {
187 Element body =
188 XmlUtils.createElement( WsagConstants.WSRF_GET_RESOURCE_PROPERTY_QNAME, "wsag:Name" );
189 body.setAttribute( WsagConstants.WSAG_PREFIX_DECLARATION, WsagConstants.NAMESPACE_URI );
190
191 Element response = client.invoke( WsagConstants.WSRF_GET_RESOURCE_PROPERTY_ACTION, body );
192
193 XmlNCName respDoc =
194 XmlNCName.Factory.parse( response, new XmlOptions().setLoadReplaceDocumentElement( null ) );
195
196 return respDoc.getStringValue();
197 }
198 catch ( SoapFault e )
199 {
200 throw new ResourceUnavailableException( e );
201 }
202 catch ( XmlException e )
203 {
204 throw new ResourceUnavailableException( e );
205 }
206 }
207
208
209
210
211 public ServiceTermStateType[] getServiceTermStates() throws ResourceUnavailableException
212 {
213 try
214 {
215 Element body =
216 XmlUtils.createElement( WsagConstants.WSRF_GET_RESOURCE_PROPERTY_QNAME,
217 "wsag:ServiceTermState" );
218 body.setAttribute( WsagConstants.WSAG_PREFIX_DECLARATION, WsagConstants.NAMESPACE_URI );
219
220 Element response = client.invoke( WsagConstants.WSRF_GET_RESOURCE_PROPERTY_ACTION, body );
221
222 AgreementStatePropertiesType props =
223 AgreementStatePropertiesType.Factory.parse( response,
224 new XmlOptions().setLoadReplaceDocumentElement( null ) );
225
226 ServiceTermStateType[] states = props.getServiceTermStateArray();
227
228 return states;
229
230 }
231 catch ( SoapFault e )
232 {
233 throw new ResourceUnavailableException( e );
234 }
235 catch ( XmlException e )
236 {
237 throw new ResourceUnavailableException( e );
238 }
239 }
240
241
242
243
244 public AgreementStateType getState() throws ResourceUnavailableException
245 {
246 try
247 {
248 Element body =
249 XmlUtils.createElement( WsagConstants.WSRF_GET_RESOURCE_PROPERTY_QNAME, "wsag:AgreementState" );
250 body.setAttribute( WsagConstants.WSAG_PREFIX_DECLARATION, WsagConstants.NAMESPACE_URI );
251
252 Element response = client.invoke( WsagConstants.WSRF_GET_RESOURCE_PROPERTY_ACTION, body );
253
254 AgreementStateDocument respDoc =
255 (AgreementStateDocument) XmlObject.Factory.parse( XmlUtils.getFirstElement( response ) );
256
257 return respDoc.getAgreementState();
258
259 }
260 catch ( SoapFault e )
261 {
262 throw new ResourceUnavailableException( e );
263 }
264 catch ( XmlException e )
265 {
266 throw new ResourceUnavailableException( e );
267 }
268 }
269
270
271
272
273 public TermTreeType getTerms() throws ResourceUnavailableException
274 {
275 try
276 {
277 Element body =
278 XmlUtils.createElement( WsagConstants.WSRF_GET_RESOURCE_PROPERTY_QNAME, "wsag:Terms" );
279 body.setAttribute( WsagConstants.WSAG_PREFIX_DECLARATION, WsagConstants.NAMESPACE_URI );
280
281 Element response = client.invoke( WsagConstants.WSRF_GET_RESOURCE_PROPERTY_ACTION, body );
282
283 TermTreeType respDoc =
284 TermTreeType.Factory.parse( XmlUtils.getFirstElement( response ),
285 new XmlOptions().setLoadReplaceDocumentElement( null ) );
286
287 return respDoc;
288 }
289 catch ( SoapFault e )
290 {
291 throw new ResourceUnavailableException( e );
292 }
293 catch ( XmlException e )
294 {
295 throw new ResourceUnavailableException( e );
296 }
297 }
298
299
300
301
302 public void terminate( TerminateInputType reason ) throws ResourceUnavailableException
303 {
304 try
305 {
306 Element inputType =
307 XmlUtils.createElement( WsagConstants.WSAG_TERMINATE_AGREEMENT_INPUT_QNAME,
308 reason.getDomNode() );
309 Element body = XmlUtils.createElement( WsagConstants.WSAG_TERMINATE_AGREEMENT_QNAME );
310 body.appendChild( body.getOwnerDocument().importNode( inputType, true ) );
311 Element response = client.invoke( WsagConstants.WSAG_TERMINATE_AGREEMENT_ACTION, body );
312
313 TerminateResponseDocument respDoc = TerminateResponseDocument.Factory.parse( response );
314 respDoc.getTerminateResponse();
315 }
316 catch ( SoapFault e )
317 {
318 throw new ResourceUnavailableException( e );
319 }
320 catch ( XmlException e )
321 {
322 throw new ResourceUnavailableException( e );
323 }
324 catch ( Exception e )
325 {
326 throw new ResourceUnavailableException( e );
327 }
328 }
329
330
331
332
333 public void destroy() throws ResourceUnknownException, ResourceUnavailableException
334 {
335 try
336 {
337 client.destroy();
338 }
339 catch ( SoapFault e )
340 {
341 throw new ResourceUnavailableException( e );
342 }
343 }
344 }