View Javadoc

1   /* 
2    * Copyright (c) 2005-2011, Fraunhofer-Gesellschaft
3    * All rights reserved.
4    * 
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions are
7    * met:
8    * 
9    * (1) Redistributions of source code must retain the above copyright
10   *     notice, this list of conditions and the disclaimer at the end.
11   *     Redistributions in binary form must reproduce the above copyright
12   *     notice, this list of conditions and the following disclaimer in
13   *     the documentation and/or other materials provided with the
14   *     distribution.
15   * 
16   * (2) Neither the name of Fraunhofer nor the names of its
17   *     contributors may be used to endorse or promote products derived
18   *     from this software without specific prior written permission.
19   * 
20   * DISCLAIMER
21   * 
22   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23   * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24   * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25   * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26   * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29   * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30   * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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   * AgreementImpl
60   * 
61   * @author Oliver Waeldrich
62   * 
63   */
64  public class WsrfAgreementClient extends AgreementClientImpl
65  {
66  
67      private final WsrfResourceClient client;
68  
69      private final WsrfAgreementService agreementClient;
70  
71      /**
72       * Instantiates a new agreement client for the given EPR.
73       * 
74       * @param epr
75       *            the agreement endpoint reference.
76       * 
77       * @param securityProperties
78       *            the security properties
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       * {@inheritDoc}
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      * (non-Javadoc)
104      * 
105      * @see org.ogf.graap.wsag.client.api.impl.AbstractClient#getRemoteClient()
106      */
107     @Override
108     public WsrfResourceClient getRemoteClient()
109     {
110         return client;
111     }
112 
113     /**
114      * {@inheritDoc}
115      */
116     @Override
117     public AgreementContextType getContext() throws ResourceUnknownException, ResourceUnavailableException
118     {
119         return agreementClient.getContext();
120     }
121 
122     /**
123      * {@inheritDoc}
124      */
125     @Override
126     public GuaranteeTermStateType[] getGuaranteeTermStates()
127         throws ResourceUnknownException, ResourceUnavailableException
128     {
129         return agreementClient.getGuaranteeTermStates();
130     }
131 
132     /**
133      * {@inheritDoc}
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      * {@inheritDoc}
155      */
156     @Override
157     public String getAgreementId() throws ResourceUnknownException, ResourceUnavailableException
158     {
159         return agreementClient.getAgreementId();
160     }
161 
162     /**
163      * {@inheritDoc}
164      */
165     @Override
166     public String getName() throws ResourceUnknownException, ResourceUnavailableException
167     {
168         return agreementClient.getName();
169     }
170 
171     /**
172      * {@inheritDoc}
173      */
174     @Override
175     public ServiceTermStateType[] getServiceTermStates()
176         throws ResourceUnknownException, ResourceUnavailableException
177     {
178         return agreementClient.getServiceTermStates();
179     }
180 
181     /**
182      * {@inheritDoc}
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      * {@inheritDoc}
204      */
205     @Override
206     public AgreementStateType getState() throws ResourceUnknownException, ResourceUnavailableException
207     {
208         return agreementClient.getState();
209     }
210 
211     /**
212      * {@inheritDoc}
213      */
214     @Override
215     public TermTreeType getTerms() throws ResourceUnknownException, ResourceUnavailableException
216     {
217         return agreementClient.getTerms();
218     }
219 
220     /**
221      * {@inheritDoc}
222      */
223     @Override
224     public void terminate() throws ResourceUnknownException, ResourceUnavailableException
225     {
226         terminate( TerminateInputType.Factory.newInstance() );
227     }
228 
229     /**
230      * {@inheritDoc}
231      */
232     @Override
233     public void terminate( TerminateInputType reason )
234         throws ResourceUnknownException, ResourceUnavailableException
235     {
236         agreementClient.terminate( reason );
237     }
238 
239     /**
240      * {@inheritDoc}
241      */
242     @Override
243     public void destroy() throws ResourceUnknownException, ResourceUnavailableException
244     {
245         agreementClient.destroy();
246     }
247 
248     /**
249      * {@inheritDoc}
250      */
251     public EndpointReferenceType getEndpoint()
252     {
253         return agreementClient.getWebServiceClient().getEndpoint();
254     }
255 
256     /**
257      * {@inheritDoc}
258      */
259     @Override
260     public Properties getProperties()
261     {
262         return agreementClient.getWebServiceClient().getProperties();
263     }
264 
265     /**
266      * {@inheritDoc}
267      */
268     @Override
269     public void setProperties( Properties properties )
270     {
271         agreementClient.getWebServiceClient().setProperties( properties );
272     }
273 
274     /**
275      * {@inheritDoc}
276      */
277     @Override
278     public boolean isUsingTrace()
279     {
280         return agreementClient.getWebServiceClient().isUsingTrace();
281     }
282 
283     /**
284      * {@inheritDoc}
285      */
286     @Override
287     public void setTrace( boolean trace )
288     {
289         agreementClient.getWebServiceClient().setTrace( trace );
290     }
291 
292     /**
293      * {@inheritDoc}
294      * 
295      * @return the security properties for this client
296      * @see org.ogf.graap.wsag.client.wsrf.impl.WsrfResourceClient#getSecurityProperties()
297      */
298     @Override
299     public ISecurityProperties getSecurityProperties()
300     {
301         return agreementClient.getWebServiceClient().getSecurityProperties();
302     }
303 
304     /**
305      * {@inheritDoc}
306      * 
307      * @see org.ogf.graap.wsag.client.api.impl.AgreementClientImpl#getResourceProperties()
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 }