View Javadoc

1   /* 
2    * Copyright (c) 2005-2011, 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.api.impl;
36  
37  import org.ogf.graap.wsag.api.exceptions.ResourceUnavailableException;
38  import org.ogf.graap.wsag.api.exceptions.ResourceUnknownException;
39  import org.ogf.graap.wsag.client.api.AgreementClient;
40  import org.ogf.schemas.graap.wsAgreement.AgreementContextType;
41  import org.ogf.schemas.graap.wsAgreement.AgreementPropertiesType;
42  import org.ogf.schemas.graap.wsAgreement.AgreementStateType;
43  import org.ogf.schemas.graap.wsAgreement.GuaranteeTermStateType;
44  import org.ogf.schemas.graap.wsAgreement.ServiceTermStateType;
45  import org.ogf.schemas.graap.wsAgreement.TermTreeType;
46  import org.ogf.schemas.graap.wsAgreement.TerminateInputType;
47  
48  /**
49   * Default implementation of an agreement client. Concrete implementations must provide a proper
50   * implementation of the server interaction.
51   * 
52   * @author Oliver Waeldrich
53   */
54  public abstract class AgreementClientImpl extends AbstractClient
55      implements AgreementClient
56  {
57  
58      /**
59       * Creates an agreement client for the given agreement service implementation.
60       * 
61       * @param agreementClient
62       *            the agreement service client
63       */
64  
65      /**
66       * {@inheritDoc}
67       */
68      public abstract AgreementContextType getContext()
69          throws ResourceUnknownException, ResourceUnavailableException;
70  
71      /**
72       * {@inheritDoc}
73       */
74      public abstract GuaranteeTermStateType[] getGuaranteeTermStates()
75          throws ResourceUnknownException, ResourceUnavailableException;
76  
77      /**
78       * {@inheritDoc}
79       */
80      public GuaranteeTermStateType getGuaranteeTermState( String name )
81          throws ResourceUnknownException, ResourceUnavailableException
82      {
83  
84          GuaranteeTermStateType[] states = getGuaranteeTermStates();
85          for ( int i = 0; i < states.length; i++ )
86          {
87              GuaranteeTermStateType state = states[i];
88              if ( name.equals( state.getTermName() ) )
89              {
90                  return state;
91              }
92          }
93  
94          return null;
95      }
96  
97      /**
98       * {@inheritDoc}
99       */
100     public abstract String getAgreementId() throws ResourceUnknownException, ResourceUnavailableException;
101 
102     /**
103      * {@inheritDoc}
104      */
105     public abstract String getName() throws ResourceUnknownException, ResourceUnavailableException;
106 
107     /**
108      * {@inheritDoc}
109      */
110     public abstract ServiceTermStateType[] getServiceTermStates()
111         throws ResourceUnknownException, ResourceUnavailableException;
112 
113     /**
114      * {@inheritDoc}
115      */
116     public ServiceTermStateType getServiceTermState( String name )
117         throws ResourceUnknownException, ResourceUnavailableException
118     {
119 
120         ServiceTermStateType[] states = getServiceTermStates();
121         for ( int i = 0; i < states.length; i++ )
122         {
123             ServiceTermStateType state = states[i];
124             if ( name.equals( state.getTermName() ) )
125             {
126                 return state;
127             }
128         }
129 
130         return null;
131     }
132 
133     /**
134      * {@inheritDoc}
135      */
136     public abstract AgreementStateType getState()
137         throws ResourceUnknownException, ResourceUnavailableException;
138 
139     /**
140      * {@inheritDoc}
141      */
142     public abstract TermTreeType getTerms() throws ResourceUnknownException, ResourceUnavailableException;
143 
144     /**
145      * {@inheritDoc}
146      */
147     public abstract AgreementPropertiesType getResourceProperties()
148         throws ResourceUnknownException, ResourceUnavailableException;
149 
150     /**
151      * {@inheritDoc}
152      */
153     public void terminate() throws ResourceUnknownException, ResourceUnavailableException
154     {
155         terminate( TerminateInputType.Factory.newInstance() );
156     }
157 
158     /**
159      * {@inheritDoc}
160      */
161     public abstract void terminate( TerminateInputType reason )
162         throws ResourceUnknownException, ResourceUnavailableException;
163 
164     /**
165      * {@inheritDoc}
166      */
167     public abstract void destroy() throws ResourceUnknownException, ResourceUnavailableException;
168 
169     /**
170      * {@inheritDoc}
171      */
172     @Override
173     public abstract AgreementClient clone() throws CloneNotSupportedException;
174 }