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.wsrf;
36  
37  import java.util.Properties;
38  
39  import org.ogf.graap.wsag.api.exceptions.NegotiationException;
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.impl.NegotiationClientImpl;
44  import org.ogf.graap.wsag.client.wsrf.impl.WsrfNegotiationService;
45  import org.ogf.graap.wsag.client.wsrf.impl.WsrfResourceClient;
46  import org.ogf.schemas.graap.wsAgreement.AgreementTemplateType;
47  import org.ogf.schemas.graap.wsAgreement.negotiation.NegotiationContextType;
48  import org.ogf.schemas.graap.wsAgreement.negotiation.NegotiationOfferType;
49  import org.w3.x2005.x08.addressing.EndpointReferenceType;
50  
51  /**
52   * Default implementation of an agreement negotiation client.
53   * 
54   * @author hrasheed
55   * 
56   */
57  public class WsrfNegotiationClient extends NegotiationClientImpl
58  {
59  
60      private final WsrfResourceClient client;
61  
62      private final WsrfNegotiationService negotiationService;
63  
64      /**
65       * Instantiates a negotiation client for the given EPR.
66       * 
67       * @param epr
68       *            the negotiation endpoint reference
69       * 
70       * @param securityProperties
71       *            the security properties to use
72       */
73      public WsrfNegotiationClient( EndpointReferenceType epr, Properties properties,
74                                    ISecurityProperties securityProperties )
75      {
76          this( new WsrfResourceClient( epr, properties, securityProperties ) );
77      }
78  
79      private WsrfNegotiationClient( WsrfResourceClient client )
80      {
81          this.client = client;
82          this.negotiationService = new WsrfNegotiationService( client );
83      }
84  
85      /**
86       * {@inheritDoc}
87       */
88      public WsrfResourceClient getWebServiceClient()
89      {
90          return client;
91      }
92  
93      /**
94       * {@inheritDoc}
95       */
96      @Override
97      public WsrfNegotiationClient clone() throws CloneNotSupportedException
98      {
99          Properties properties = client.getProperties();
100         ISecurityProperties securityProperties = client.getSecurityProperties().clone();
101         return new WsrfNegotiationClient( client.getEndpoint(), properties, securityProperties );
102     }
103 
104     /*
105      * (non-Javadoc)
106      * 
107      * @see org.ogf.graap.wsag.client.api.impl.NegotiationClientImpl#getNegotiationContext()
108      */
109     @Override
110     public NegotiationContextType getNegotiationContext()
111         throws ResourceUnknownException, ResourceUnavailableException
112     {
113         return negotiationService.getNegotiationContext();
114     }
115 
116     /*
117      * (non-Javadoc)
118      * 
119      * @see org.ogf.graap.wsag.client.api.impl.NegotiationClientImpl#getNegotiableTemplates()
120      */
121     @Override
122     public AgreementTemplateType[] getNegotiableTemplates()
123         throws ResourceUnknownException, ResourceUnavailableException
124     {
125         return negotiationService.getNegotiableTemplates();
126     }
127 
128     /*
129      * (non-Javadoc)
130      * 
131      * @see org.ogf.graap.wsag.client.api.impl.NegotiationClientImpl#getNegotiationOffers()
132      */
133     @Override
134     public NegotiationOfferType[] getNegotiationOffers()
135         throws ResourceUnknownException, ResourceUnavailableException
136     {
137         return negotiationService.getNegotiationOffers();
138     }
139 
140     /*
141      * (non-Javadoc)
142      * 
143      * @see
144      * org.ogf.graap.wsag.client.api.impl.NegotiationClientImpl#negotiate(org.ogf.schemas.graap.wsAgreement
145      * .negotiation.NegotiationOfferType[])
146      */
147     @Override
148     public NegotiationOfferType[] negotiate( NegotiationOfferType[] quotes )
149         throws NegotiationException, ResourceUnknownException, ResourceUnavailableException
150     {
151         return negotiationService.negotiate( quotes );
152     }
153 
154     /*
155      * (non-Javadoc)
156      * 
157      * @see
158      * org.ogf.graap.wsag.client.api.impl.NegotiationClientImpl#advertise(org.ogf.schemas.graap.wsAgreement
159      * .negotiation.NegotiationOfferType[])
160      */
161     @Override
162     public void advertise( NegotiationOfferType[] quotes )
163         throws NegotiationException, ResourceUnknownException, ResourceUnavailableException
164     {
165         negotiationService.advertise( quotes );
166     }
167 
168     /*
169      * (non-Javadoc)
170      * 
171      * @see org.ogf.graap.wsag.client.api.impl.NegotiationClientImpl#terminate()
172      */
173     @Override
174     public void terminate() throws ResourceUnknownException, ResourceUnavailableException
175     {
176         negotiationService.terminate();
177     }
178 
179     /*
180      * (non-Javadoc)
181      * 
182      * @see org.ogf.graap.wsag.client.api.impl.NegotiationClientImpl#destroy()
183      */
184     @Override
185     public void destroy() throws ResourceUnknownException, ResourceUnavailableException
186     {
187         negotiationService.destroy();
188     }
189 
190     /*
191      * (non-Javadoc)
192      * 
193      * @see org.ogf.graap.wsag.client.api.impl.AbstractClient#getRemoteClient()
194      */
195     @Override
196     public WsrfResourceClient getRemoteClient()
197     {
198         return client;
199     }
200 
201 }