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.impl;
36  
37  import java.util.Properties;
38  
39  import org.ogf.graap.wsag.api.client.NegotiationClient;
40  import org.ogf.graap.wsag.api.client.NegotiationService;
41  import org.ogf.graap.wsag.api.exceptions.NegotiationException;
42  import org.ogf.graap.wsag.api.exceptions.ResourceUnavailableException;
43  import org.ogf.graap.wsag.api.exceptions.ResourceUnknownException;
44  import org.ogf.graap.wsag.api.security.ISecurityProperties;
45  import org.ogf.schemas.graap.wsAgreement.AgreementTemplateType;
46  import org.ogf.schemas.graap.wsAgreement.negotiation.NegotiationContextType;
47  import org.ogf.schemas.graap.wsAgreement.negotiation.NegotiationOfferType;
48  import org.w3.x2005.x08.addressing.EndpointReferenceType;
49  
50  /**
51   * NegotiationClientImpl
52   * 
53   * @author hrasheed
54   * 
55   */
56  public abstract class NegotiationClientImpl implements NegotiationClient
57  {
58  
59      private NegotiationService negotiationClient;
60  
61      /**
62       * Creates a new negotiation client for the given negotiation service implementation.
63       * 
64       * @param negotiationClient
65       *            the negotiation service client implemenation
66       */
67      protected NegotiationClientImpl( NegotiationService negotiationClient )
68      {
69          this.negotiationClient = negotiationClient;
70      }
71  
72      /**
73       * {@inheritDoc}
74       */
75      public abstract NegotiationClient clone() throws CloneNotSupportedException;
76  
77      /**
78       * {@inheritDoc}
79       */
80      public NegotiationContextType getNegotiationContext()
81          throws ResourceUnknownException, ResourceUnavailableException
82      {
83          return negotiationClient.getNegotiationContext();
84      }
85  
86      /**
87       * {@inheritDoc}
88       */
89      public AgreementTemplateType[] getNegotiableTemplates()
90          throws ResourceUnknownException, ResourceUnavailableException
91      {
92          return negotiationClient.getNegotiableTemplates();
93      }
94  
95      /**
96       * {@inheritDoc}
97       */
98      public NegotiationOfferType[] getNegotiationOffers()
99          throws ResourceUnknownException, ResourceUnavailableException
100     {
101         return negotiationClient.getNegotiationOffers();
102     }
103 
104     /**
105      * {@inheritDoc}
106      */
107     public NegotiationOfferType[] negotiate( NegotiationOfferType[] quotes )
108         throws NegotiationException, ResourceUnknownException, ResourceUnavailableException
109     {
110         return negotiationClient.negotiate( quotes );
111     }
112 
113     /**
114      * {@inheritDoc}
115      */
116     public void advertise( NegotiationOfferType[] quotes )
117         throws NegotiationException, ResourceUnknownException, ResourceUnavailableException
118     {
119         negotiationClient.advertise( quotes );
120     }
121 
122     /**
123      * {@inheritDoc}
124      */
125     public NegotiationOfferType getNegotiationOffer( String offerID )
126         throws ResourceUnknownException, ResourceUnavailableException
127     {
128         NegotiationOfferType[] offers = getNegotiationOffers();
129         for ( int i = 0; i < offers.length; i++ )
130         {
131             NegotiationOfferType offer = offers[i];
132             if ( offerID.equals( offer.getOfferId() ) )
133             {
134                 return offer;
135             }
136         }
137 
138         throw new ResourceUnavailableException( "no negotiationoffer found for offer id: " + offerID );
139     }
140 
141     /**
142      * {@inheritDoc}
143      */
144     public void terminate() throws ResourceUnknownException, ResourceUnavailableException
145     {
146         negotiationClient.terminate();
147     }
148 
149     /**
150      * {@inheritDoc}
151      */
152     public void destroy() throws ResourceUnknownException, ResourceUnavailableException
153     {
154         negotiationClient.destroy();
155     }
156 
157     /**
158      * {@inheritDoc}
159      */
160     public EndpointReferenceType getEndpoint()
161     {
162         return negotiationClient.getWebServiceClient().getEndpoint();
163     }
164 
165     /**
166      * {@inheritDoc}
167      */
168     public Properties getProperties()
169     {
170         return negotiationClient.getWebServiceClient().getProperties();
171     }
172 
173     /**
174      * {@inheritDoc}
175      */
176     public void setProperties( Properties properties )
177     {
178         negotiationClient.getWebServiceClient().setProperties( properties );
179     }
180 
181     /**
182      * {@inheritDoc}
183      */
184     public boolean isUsingTrace()
185     {
186         return negotiationClient.getWebServiceClient().isUsingTrace();
187     }
188 
189     /**
190      * {@inheritDoc}
191      */
192     public void setTrace( boolean trace )
193     {
194         negotiationClient.getWebServiceClient().setTrace( trace );
195     }
196 
197     /**
198      * {@inheritDoc}
199      * 
200      * @return the security properties for this client
201      * @see org.ogf.graap.wsag.client.remote.WsrfResourceClient#getSecurityProperties()
202      */
203     public ISecurityProperties getSecurityProperties()
204     {
205         return negotiationClient.getWebServiceClient().getSecurityProperties();
206     }
207 
208 }