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