View Javadoc

1   /* 
2    * Copyright (c) 2007, 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.remote;
36  
37  import java.util.Properties;
38  
39  import org.ogf.graap.wsag.api.AgreementOffer;
40  import org.ogf.graap.wsag.api.WsagConstants;
41  import org.ogf.graap.wsag.api.client.AgreementClient;
42  import org.ogf.graap.wsag.api.client.AgreementFactoryClient;
43  import org.ogf.graap.wsag.api.client.NegotiationClient;
44  import org.ogf.graap.wsag.api.client.WsClient;
45  import org.ogf.graap.wsag.api.exceptions.AgreementFactoryException;
46  import org.ogf.graap.wsag.api.exceptions.NegotiationFactoryException;
47  import org.ogf.graap.wsag.api.exceptions.ResourceUnavailableException;
48  import org.ogf.graap.wsag.api.exceptions.ResourceUnknownException;
49  import org.ogf.graap.wsag.api.security.ISecurityProperties;
50  import org.ogf.graap.wsag.client.impl.AgreementFactoryFacade;
51  import org.ogf.schemas.graap.wsAgreement.AgreementTemplateType;
52  import org.ogf.schemas.graap.wsAgreement.negotiation.NegotiationContextType;
53  import org.w3.x2005.x08.addressing.EndpointReferenceDocument;
54  import org.w3.x2005.x08.addressing.EndpointReferenceType;
55  
56  /**
57   * RemoteAgreementFactoryClientImpl
58   * 
59   * @author Oliver Waeldrich
60   * 
61   */
62  public class RemoteAgreementFactoryClientImpl
63      implements AgreementFactoryClient
64  {
65  
66      private AgreementFactoryFacade facade;
67  
68      /**
69       * Creates a new agreement factory client for a given endpoint using the given security properties.
70       * 
71       * @param epr
72       *            the agreement factory endpoint
73       * 
74       * @param securityProperties
75       *            the client security properties
76       */
77      public RemoteAgreementFactoryClientImpl( EndpointReferenceType epr, ISecurityProperties securityProperties )
78      {
79  
80          try
81          {
82              //
83              // generate the endpoint references for the registry service
84              //
85              String factoryURI = epr.getAddress().getStringValue();
86              String registryURI =
87                  factoryURI.substring( 0, factoryURI.indexOf( WsagConstants.AGREEMENT_FACTORY_SERVICE_URI ) )
88                      + WsagConstants.AGREEMENT_REGISTRY_SERVICE_URI;
89  
90              EndpointReferenceDocument registryEPR = EndpointReferenceDocument.Factory.newInstance();
91              registryEPR.addNewEndpointReference().addNewAddress().setStringValue( registryURI );
92              registryEPR.getEndpointReference().addNewReferenceParameters().set( epr.getReferenceParameters() );
93  
94              //
95              // initialize the service clients
96              //
97              RemoteAgreementFactoryServiceImpl factoryClient =
98                  new RemoteAgreementFactoryServiceImpl( epr, securityProperties );
99              RemoteAgreementRegistryServiceImpl registryClient =
100                 new RemoteAgreementRegistryServiceImpl( registryEPR.getEndpointReference(),
101                     securityProperties );
102 
103             facade = new AgreementFactoryFacade( factoryClient, registryClient, securityProperties );
104         }
105         catch ( Exception e )
106         {
107             throw new RuntimeException( e );
108         }
109 
110     }
111 
112     /**
113      * {@inheritDoc}
114      */
115     @Override
116     public AgreementFactoryClient clone() throws CloneNotSupportedException
117     {
118         return new RemoteAgreementFactoryClientImpl( getEndpoint(), getSecurityProperties().clone() );
119     }
120 
121     /**
122      * {@inheritDoc}
123      */
124     public WsClient getWebServiceClient()
125     {
126         return facade.getWebServiceClient();
127     }
128 
129     /**
130      * {@inheritDoc}
131      */
132     public AgreementClient createAgreement( AgreementOffer offer )
133         throws AgreementFactoryException, ResourceUnknownException, ResourceUnavailableException
134     {
135         return facade.createAgreement( offer );
136     }
137 
138     /**
139      * {@inheritDoc}
140      */
141     public AgreementClient createPendingAgreement( AgreementOffer offer )
142         throws AgreementFactoryException, ResourceUnknownException, ResourceUnavailableException
143     {
144         return facade.createPendingAgreement( offer );
145     }
146 
147     /**
148      * {@inheritDoc}
149      */
150     public AgreementClient createPendingAgreement( AgreementOffer offer, EndpointReferenceType acceptanceEPR )
151         throws AgreementFactoryException, ResourceUnknownException, ResourceUnavailableException
152     {
153         return facade.createPendingAgreement( offer, acceptanceEPR );
154     }
155 
156     /**
157      * {@inheritDoc}
158      */
159     public EndpointReferenceType getEndpoint()
160     {
161         return facade.getEndpoint();
162     }
163 
164     /**
165      * {@inheritDoc}
166      */
167     public Properties getProperties()
168     {
169         return facade.getProperties();
170     }
171 
172     /**
173      * {@inheritDoc}
174      */
175     public String getResourceId() throws ResourceUnknownException, ResourceUnavailableException
176     {
177         return facade.getResourceId();
178     }
179 
180     /**
181      * {@inheritDoc}
182      */
183     public ISecurityProperties getSecurityProperties()
184     {
185         return facade.getSecurityProperties();
186     }
187 
188     /**
189      * @param name
190      *            the requested template name
191      * 
192      * @param id
193      *            the requested template id
194      * 
195      * @return the template with the specified name and id. If no template exists with these properties, null
196      *         is returned.
197      * 
198      * @throws ResourceUnknownException
199      *             the remote resource is unknown
200      * 
201      * @throws ResourceUnavailableException
202      *             the remote resource is unavailable
203      * 
204      * @see org.ogf.graap.wsag.client.impl.AgreementFactoryFacade#getTemplate(String, String)
205      */
206     public AgreementTemplateType getTemplate( String name, String id )
207         throws ResourceUnknownException, ResourceUnavailableException
208     {
209         return facade.getTemplate( name, id );
210     }
211 
212     /**
213      * {@inheritDoc}
214      */
215     public AgreementTemplateType[] getTemplates()
216         throws ResourceUnknownException, ResourceUnavailableException
217     {
218         return facade.getTemplates();
219     }
220 
221     /**
222      * {@inheritDoc}
223      */
224     public boolean isUsingTrace()
225     {
226         return facade.isUsingTrace();
227     }
228 
229     /**
230      * {@inheritDoc}
231      */
232     public AgreementClient[] listAgreements() throws ResourceUnknownException, ResourceUnavailableException
233     {
234         return facade.listAgreements();
235     }
236 
237     /**
238      * {@inheritDoc}
239      */
240     public void setProperties( Properties properties )
241     {
242         facade.setProperties( properties );
243     }
244 
245     /**
246      * {@inheritDoc}
247      */
248     public void setTrace( boolean trace )
249     {
250         facade.setTrace( trace );
251     }
252 
253     /**
254      * Initiates a new negotiation process with the given context.
255      * 
256      * @param context
257      *            the negotiation context
258      * 
259      * @return a client to the new created negotiation process
260      * 
261      * @throws NegotiationFactoryException
262      *             The negotiation process was not initiated.
263      * 
264      * @throws ResourceUnknownException
265      *             the remote resource is unknown
266      * 
267      * @throws ResourceUnavailableException
268      *             the remote resource is unavailable
269      * 
270      * @see org.ogf.graap.wsag.client.impl.AgreementFactoryFacade#initiateNegotiation(NegotiationContextType)
271      */
272     public NegotiationClient initiateNegotiation( NegotiationContextType context )
273         throws NegotiationFactoryException, ResourceUnknownException, ResourceUnavailableException
274     {
275         return facade.initiateNegotiation( context );
276     }
277 
278 }