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.impl;
36  
37  import java.util.Properties;
38  
39  import org.ogf.graap.wsag.api.client.AgreementClient;
40  import org.ogf.graap.wsag.api.client.AgreementService;
41  import org.ogf.graap.wsag.api.exceptions.ResourceUnavailableException;
42  import org.ogf.graap.wsag.api.exceptions.ResourceUnknownException;
43  import org.ogf.graap.wsag.api.security.ISecurityProperties;
44  import org.ogf.schemas.graap.wsAgreement.AgreementContextType;
45  import org.ogf.schemas.graap.wsAgreement.AgreementStateType;
46  import org.ogf.schemas.graap.wsAgreement.GuaranteeTermStateType;
47  import org.ogf.schemas.graap.wsAgreement.ServiceTermStateType;
48  import org.ogf.schemas.graap.wsAgreement.TermTreeType;
49  import org.ogf.schemas.graap.wsAgreement.TerminateInputType;
50  import org.w3.x2005.x08.addressing.EndpointReferenceType;
51  
52  /**
53   * AgreementImpl
54   * 
55   * @author Oliver Waeldrich
56   * 
57   */
58  public abstract class AgreementImpl implements AgreementClient
59  {
60  
61      private AgreementService agreementClient;
62  
63      /**
64       * Creates an agreement client for the given agreement service implementation.
65       * 
66       * @param agreementClient
67       *            the agreement service client
68       */
69      protected AgreementImpl( AgreementService agreementClient )
70      {
71          this.agreementClient = agreementClient;
72      }
73  
74      /**
75       * {@inheritDoc}
76       */
77      public abstract AgreementClient clone() throws CloneNotSupportedException;
78  
79      /**
80       * {@inheritDoc}
81       */
82      public AgreementContextType getContext() throws ResourceUnknownException, ResourceUnavailableException
83      {
84          return agreementClient.getContext();
85      }
86  
87      /**
88       * {@inheritDoc}
89       */
90      public GuaranteeTermStateType[] getGuaranteeTermStates()
91          throws ResourceUnknownException, ResourceUnavailableException
92      {
93          return agreementClient.getGuaranteeTermStates();
94      }
95  
96      /**
97       * {@inheritDoc}
98       */
99      public GuaranteeTermStateType getGuaranteeTermState( String name )
100         throws ResourceUnknownException, ResourceUnavailableException
101     {
102 
103         GuaranteeTermStateType[] states = getGuaranteeTermStates();
104         for ( int i = 0; i < states.length; i++ )
105         {
106             GuaranteeTermStateType state = states[i];
107             if ( name.equals( state.getTermName() ) )
108             {
109                 return state;
110             }
111         }
112 
113         return null;
114     }
115 
116     /**
117      * {@inheritDoc}
118      */
119     public String getAgreementId() throws ResourceUnknownException, ResourceUnavailableException
120     {
121         return agreementClient.getAgreementId();
122     }
123 
124     /**
125      * {@inheritDoc}
126      */
127     public String getName() throws ResourceUnknownException, ResourceUnavailableException
128     {
129         return agreementClient.getName();
130     }
131 
132     /**
133      * {@inheritDoc}
134      */
135     public ServiceTermStateType[] getServiceTermStates()
136         throws ResourceUnknownException, ResourceUnavailableException
137     {
138         return agreementClient.getServiceTermStates();
139     }
140 
141     /**
142      * {@inheritDoc}
143      */
144     public ServiceTermStateType getServiceTermState( String name )
145         throws ResourceUnknownException, ResourceUnavailableException
146     {
147 
148         ServiceTermStateType[] states = getServiceTermStates();
149         for ( int i = 0; i < states.length; i++ )
150         {
151             ServiceTermStateType state = states[i];
152             if ( name.equals( state.getTermName() ) )
153             {
154                 return state;
155             }
156         }
157 
158         return null;
159     }
160 
161     /**
162      * {@inheritDoc}
163      */
164     public AgreementStateType getState() throws ResourceUnknownException, ResourceUnavailableException
165     {
166         return agreementClient.getState();
167     }
168 
169     /**
170      * {@inheritDoc}
171      */
172     public TermTreeType getTerms() throws ResourceUnknownException, ResourceUnavailableException
173     {
174         return agreementClient.getTerms();
175     }
176 
177     /**
178      * {@inheritDoc}
179      */
180     public void terminate() throws ResourceUnknownException, ResourceUnavailableException
181     {
182         terminate( TerminateInputType.Factory.newInstance() );
183     }
184 
185     /**
186      * {@inheritDoc}
187      */
188     public void terminate( TerminateInputType reason )
189         throws ResourceUnknownException, ResourceUnavailableException
190     {
191         agreementClient.terminate( reason );
192     }
193 
194     /**
195      * {@inheritDoc}
196      */
197     public void destroy() throws ResourceUnknownException, ResourceUnavailableException
198     {
199         agreementClient.destroy();
200     }
201 
202     /**
203      * {@inheritDoc}
204      */
205     public EndpointReferenceType getEndpoint()
206     {
207         return agreementClient.getWebServiceClient().getEndpoint();
208     }
209 
210     /**
211      * {@inheritDoc}
212      */
213     public Properties getProperties()
214     {
215         return agreementClient.getWebServiceClient().getProperties();
216     }
217 
218     /**
219      * {@inheritDoc}
220      */
221     public void setProperties( Properties properties )
222     {
223         agreementClient.getWebServiceClient().setProperties( properties );
224     }
225 
226     /**
227      * {@inheritDoc}
228      */
229     public boolean isUsingTrace()
230     {
231         return agreementClient.getWebServiceClient().isUsingTrace();
232     }
233 
234     /**
235      * {@inheritDoc}
236      */
237     public void setTrace( boolean trace )
238     {
239         agreementClient.getWebServiceClient().setTrace( trace );
240     }
241 
242     /**
243      * {@inheritDoc}
244      * 
245      * @return the security properties for this client
246      * @see org.ogf.graap.wsag.client.remote.WsrfResourceClient#getSecurityProperties()
247      */
248     public ISecurityProperties getSecurityProperties()
249     {
250         return agreementClient.getWebServiceClient().getSecurityProperties();
251     }
252 
253 }