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.local;
36  
37  import java.util.HashMap;
38  import java.util.Map;
39  
40  import org.apache.xmlbeans.XmlObject;
41  import org.ogf.graap.wsag.api.AgreementFactory;
42  import org.ogf.graap.wsag.api.AgreementOffer;
43  import org.ogf.graap.wsag.api.client.AgreementClient;
44  import org.ogf.graap.wsag.api.client.AgreementFactoryService;
45  import org.ogf.graap.wsag.api.client.NegotiationClient;
46  import org.ogf.graap.wsag.api.exceptions.AgreementFactoryException;
47  import org.ogf.graap.wsag.api.exceptions.NegotiationFactoryException;
48  import org.ogf.graap.wsag.api.exceptions.ResourceUnavailableException;
49  import org.ogf.graap.wsag.api.exceptions.ResourceUnknownException;
50  import org.ogf.schemas.graap.wsAgreement.AgreementTemplateType;
51  import org.ogf.schemas.graap.wsAgreement.negotiation.NegotiationContextType;
52  import org.w3.x2005.x08.addressing.EndpointReferenceType;
53  
54  /**
55   * Client implementation of an {@link AgreementFactoryService} for local access.
56   * 
57   * @author Oliver Waeldrich
58   * 
59   */
60  public class LocalAgreementFactoryServiceImpl extends LocalWsClient
61      implements AgreementFactoryService
62  {
63  
64      private final AgreementFactory factory;
65  
66      /**
67       * Creates a client instance for the given agreement factory object.
68       * 
69       * @param factory
70       *            the factory to use
71       */
72      public LocalAgreementFactoryServiceImpl( AgreementFactory factory )
73      {
74          this.factory = factory;
75      }
76  
77      /**
78       * {@inheritDoc}
79       * 
80       * @see org.ogf.graap.wsag.api.client.AgreementFactoryService#createAgreement(org.ogf.graap.wsag.api.AgreementOffer)
81       */
82      public AgreementClient createAgreement( AgreementOffer offer )
83          throws AgreementFactoryException, ResourceUnknownException, ResourceUnavailableException
84      {
85          return new LocalAgreementClientImpl( factory.createAgreement( offer ) );
86      }
87  
88      /**
89       * {@inheritDoc}
90       * 
91       * @see org.ogf.graap.wsag.api.client.AgreementFactoryService#createAgreement(org.ogf.graap.wsag.api.AgreementOffer)
92       */
93      public AgreementClient createPendingAgreement( AgreementOffer offer )
94          throws AgreementFactoryException, ResourceUnknownException, ResourceUnavailableException
95      {
96          return new LocalAgreementClientImpl( factory.createAgreement( offer ) );
97      }
98  
99      /**
100      * {@inheritDoc}
101      * 
102      * @see org.ogf.graap.wsag.api.client.AgreementFactoryService#createAgreement(org.ogf.graap.wsag.api.AgreementOffer)
103      */
104     public AgreementClient createPendingAgreement( AgreementOffer offer, EndpointReferenceType acceptanceEPR )
105         throws AgreementFactoryException, ResourceUnknownException, ResourceUnavailableException
106     {
107         //
108         // not supported locally
109         //
110         return new LocalAgreementClientImpl( factory.createAgreement( offer ) );
111     }
112 
113     /**
114      * {@inheritDoc}
115      * 
116      * @see org.ogf.graap.wsag.api.client.AgreementFactoryService#getTemplates()
117      */
118     public AgreementTemplateType[] getTemplates()
119         throws ResourceUnknownException, ResourceUnavailableException
120     {
121         return factory.getTemplates();
122     }
123 
124     /**
125      * {@inheritDoc}
126      */
127     public NegotiationClient initiateNegotiation( NegotiationContextType context )
128         throws NegotiationFactoryException, ResourceUnknownException, ResourceUnavailableException
129     {
130         XmlObject[] criticalExtensions = new XmlObject[0];
131         XmlObject[] nonCriticalExtensions = new XmlObject[0];
132         Map<String, Object> environment = new HashMap<String, Object>();
133         return new LocalNegotiationClientImpl( factory.initiateNegotiation( context, criticalExtensions,
134             nonCriticalExtensions, environment ) );
135     }
136 
137     /**
138      * {@inheritDoc}
139      * 
140      * @see org.ogf.graap.wsag.api.client.WSDMResource#getResourceId()
141      */
142     public String getResourceId() throws ResourceUnknownException, ResourceUnavailableException
143     {
144         return "local_id";
145     }
146 
147 }