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.wsrf.impl;
36  
37  import java.util.Properties;
38  
39  import org.apache.muse.util.xml.XmlUtils;
40  import org.apache.muse.ws.addressing.soap.SoapFault;
41  import org.apache.xmlbeans.XmlException;
42  import org.ogf.graap.wsag.api.WsagConstants;
43  import org.ogf.graap.wsag.api.exceptions.ResourceUnavailableException;
44  import org.ogf.graap.wsag.api.exceptions.ResourceUnknownException;
45  import org.ogf.graap.wsag.api.security.ISecurityProperties;
46  import org.ogf.graap.wsag.client.remote.WsrfResourceClient;
47  import org.ogf.graap.wsag.wsrf.AgreementAcceptanceClient;
48  import org.ogf.schemas.graap.wsAgreement.AcceptAgreementResponseDocument;
49  import org.ogf.schemas.graap.wsAgreement.RejectAgreementResponseDocument;
50  import org.w3.x2005.x08.addressing.EndpointReferenceType;
51  import org.w3c.dom.Element;
52  
53  /**
54   * Default implementation of an agreement acceptance client.
55   * 
56   * @author Oliver Waeldrich
57   * 
58   */
59  public class RemoteAgreementAcceptanceClientImpl implements AgreementAcceptanceClient
60  {
61  
62      private WsrfResourceClient client;
63  
64      /**
65       * Creates a new acceptance client for the given acceptance EPR.
66       * 
67       * @param epr
68       *            the acceptance EPR
69       * @param securityProperties
70       *            the client security properties
71       */
72      public RemoteAgreementAcceptanceClientImpl( EndpointReferenceType epr,
73                                                  ISecurityProperties securityProperties )
74      {
75          this( new WsrfResourceClient( epr, securityProperties ) );
76      }
77  
78      private RemoteAgreementAcceptanceClientImpl( WsrfResourceClient client )
79      {
80          this.client = client;
81      }
82  
83      /**
84       * {@inheritDoc}
85       */
86      public void accept() throws ResourceUnknownException, ResourceUnavailableException
87      {
88          try
89          {
90              Element inputType = XmlUtils.createElement( WsagConstants.WSAG_ACCEPT_AGREEMENT_INPUT_QNAME );
91              Element body = XmlUtils.createElement( WsagConstants.WSAG_ACCEPT_AGREEMENT_QNAME );
92              body.appendChild( body.getOwnerDocument().importNode( inputType, true ) );
93              Element response = client.invoke( WsagConstants.WSAG_ACCEPT_AGREEMENT_ACTION, body );
94  
95              AcceptAgreementResponseDocument respDoc =
96                  AcceptAgreementResponseDocument.Factory.parse( response );
97              respDoc.getAcceptAgreementResponse();
98          }
99          catch ( SoapFault e )
100         {
101             throw new ResourceUnavailableException( e );
102         }
103         catch ( XmlException e )
104         {
105             throw new ResourceUnavailableException( e );
106         }
107         catch ( Exception e )
108         {
109             throw new ResourceUnavailableException( e );
110         }
111     }
112 
113     /**
114      * {@inheritDoc}
115      */
116     public void reject() throws ResourceUnknownException, ResourceUnavailableException
117     {
118         try
119         {
120             Element inputType = XmlUtils.createElement( WsagConstants.WSAG_REJECT_AGREEMENT_INPUT_QNAME );
121             Element body = XmlUtils.createElement( WsagConstants.WSAG_REJECT_AGREEMENT_QNAME );
122             body.appendChild( body.getOwnerDocument().importNode( inputType, true ) );
123             Element response = client.invoke( WsagConstants.WSAG_REJECT_AGREEMENT_ACTION, body );
124 
125             RejectAgreementResponseDocument respDoc =
126                 RejectAgreementResponseDocument.Factory.parse( response );
127             respDoc.getRejectAgreementResponse();
128         }
129         catch ( SoapFault e )
130         {
131             throw new ResourceUnavailableException( e );
132         }
133         catch ( XmlException e )
134         {
135             throw new ResourceUnavailableException( e );
136         }
137         catch ( Exception e )
138         {
139             throw new ResourceUnavailableException( e );
140         }
141     }
142 
143     /**
144      * {@inheritDoc}
145      */
146     public EndpointReferenceType getEndpoint()
147     {
148         return client.getEndpoint();
149     }
150 
151     /**
152      * {@inheritDoc}
153      */
154     public Properties getProperties()
155     {
156         return client.getProperties();
157     }
158 
159     /**
160      * {@inheritDoc}
161      */
162     public ISecurityProperties getSecurityProperties()
163     {
164         return client.getSecurityProperties();
165     }
166 
167     /**
168      * {@inheritDoc}
169      */
170     public boolean isUsingTrace()
171     {
172         return client.isUsingTrace();
173     }
174 
175     /**
176      * {@inheritDoc}
177      */
178     public void setProperties( Properties properties )
179     {
180         client.setProperties( properties );
181     }
182 
183     /**
184      * {@inheritDoc}
185      */
186     public void setTrace( boolean trace )
187     {
188         client.setTrace( trace );
189     }
190 
191 }