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.api.types;
36  
37  import org.ogf.graap.wsag.api.NegotiationOffer;
38  import org.ogf.schemas.graap.wsAgreement.AgreementContextType;
39  import org.ogf.schemas.graap.wsAgreement.AgreementTemplateType;
40  import org.ogf.schemas.graap.wsAgreement.AgreementType;
41  import org.ogf.schemas.graap.wsAgreement.TermTreeType;
42  import org.ogf.schemas.graap.wsAgreement.negotiation.NegotiationConstraintSectionType;
43  import org.ogf.schemas.graap.wsAgreement.negotiation.NegotiationOfferContextType;
44  import org.ogf.schemas.graap.wsAgreement.negotiation.NegotiationOfferDocument;
45  import org.ogf.schemas.graap.wsAgreement.negotiation.NegotiationOfferType;
46  
47  /**
48   * NegotiationOfferType
49   * 
50   * @author hrasheed
51   */
52  public class NegotiationOfferTypeImpl extends WSAGXmlType implements NegotiationOffer
53  {
54  
55      private org.ogf.schemas.graap.wsAgreement.negotiation.NegotiationOfferType negotiationOffer =
56          org.ogf.schemas.graap.wsAgreement.negotiation.NegotiationOfferType.Factory.newInstance();
57  
58      /**
59       * Initializes an negotiation offer from a template.
60       * 
61       * @param template
62       *            the template used to create the negotiation offer
63       */
64      public NegotiationOfferTypeImpl( AgreementTemplateType template )
65      {
66          //
67          // process the agreement template
68          //
69          AgreementType processed = processTemplate( template );
70  
71          //
72          // initialize the negotiation offer
73          //
74          initialize( (NegotiationOfferType) processed.changeType( NegotiationOfferType.type ) );
75      }
76  
77      /**
78       * Initializes a negotiation offer from a negotiation offer.
79       * 
80       * @param negotiationOffer
81       *            the negotiation offer used to create this type
82       */
83      public NegotiationOfferTypeImpl( NegotiationOfferType negotiationOffer )
84      {
85          initialize( (NegotiationOfferType) negotiationOffer.copy() );
86      }
87  
88      private void initialize( org.ogf.schemas.graap.wsAgreement.negotiation.NegotiationOfferType negOffer )
89      {
90          //
91          // make sure that negotiation offer is not a document fragment
92          //
93          NegotiationOfferDocument negotiationOfferDoc = NegotiationOfferDocument.Factory.newInstance();
94          negotiationOfferDoc.addNewNegotiationOffer().set( negOffer.copy() );
95          negOffer = negotiationOfferDoc.getNegotiationOffer();
96  
97          if ( negOffer == null )
98          {
99              throw new IllegalStateException( "Parameter negotiationOffer must not be null." );
100         }
101 
102         //
103         // check required parameter
104         //
105         if ( negOffer.getContext() == null )
106         {
107             throw new IllegalStateException( "Parameter negotiationOffer#Context must not be null." );
108         }
109 
110         if ( negOffer.getTerms() == null )
111         {
112             throw new IllegalStateException( "Parameter negotiationOffer#Terms must not be null." );
113         }
114 
115         this.negotiationOffer = negOffer;
116 
117         String offerId = ( negOffer.getOfferId() != null ) ? negOffer.getOfferId() : "1";
118         String offerName = ( negOffer.getName() != null ) ? negOffer.getName() : "NEGOTIATIONOFFER";
119 
120         setOfferId( offerId );
121         setName( offerName );
122     }
123 
124     /**
125      * @return the offer id
126      */
127     public String getOfferId()
128     {
129         return getNegotiationOffer().getOfferId();
130     }
131 
132     /**
133      * @param id
134      *            offer id
135      */
136     public void setOfferId( String id )
137     {
138         getNegotiationOffer().setOfferId( id );
139     }
140 
141     /**
142      * @return the offer name
143      */
144     public String getName()
145     {
146         return getNegotiationOffer().getName();
147     }
148 
149     /**
150      * @param name
151      *            the offer name to set
152      */
153     public void setName( String name )
154     {
155         getNegotiationOffer().setName( name );
156     }
157 
158     /**
159      * @return the agreement id
160      */
161     public String getAgreementId()
162     {
163         return getNegotiationOffer().getAgreementId();
164     }
165 
166     /**
167      * @param id
168      *            agreement id
169      */
170     public void setAgreementId( String id )
171     {
172         getNegotiationOffer().setAgreementId( id );
173     }
174 
175     /**
176      * The context of the agreement to negotiate.
177      * 
178      * @return the agreement context
179      */
180     public AgreementContextType getContext()
181     {
182         return getNegotiationOffer().getContext();
183     }
184 
185     /**
186      * @param context
187      *            the agreement context to set
188      */
189     public void setContext( AgreementContextType context )
190     {
191         getNegotiationOffer().setContext( context );
192     }
193 
194     /**
195      * @return the negotiation terms
196      */
197     public TermTreeType getTerms()
198     {
199         return getNegotiationOffer().getTerms();
200     }
201 
202     /**
203      * @param terms
204      *            the negotiation terms to set
205      */
206     public void setTerms( TermTreeType terms )
207     {
208         getNegotiationOffer().setTerms( terms );
209     }
210 
211     /**
212      * @return the negotiation offer context
213      */
214     public NegotiationOfferContextType getNegotiationOfferContext()
215     {
216         return getNegotiationOffer().getNegotiationOfferContext();
217     }
218 
219     /**
220      * @param negOffercontext
221      *            the negotiation offer context to set
222      */
223     public void setNegotiationOfferContext( NegotiationOfferContextType negOffercontext )
224     {
225         getNegotiationOffer().setNegotiationOfferContext( negOffercontext );
226     }
227 
228     /**
229      * @return the negotiation constraints
230      */
231     public NegotiationConstraintSectionType getNegotiationConstraints()
232     {
233         return getNegotiationOffer().getNegotiationConstraints();
234     }
235 
236     /**
237      * @param constraints
238      *            the negotiation constraints to set
239      */
240     public void setNegotiationConstraints( NegotiationConstraintSectionType constraints )
241     {
242         getNegotiationOffer().setNegotiationConstraints( constraints );
243     }
244 
245     private org.ogf.schemas.graap.wsAgreement.negotiation.NegotiationOfferType getNegotiationOffer()
246     {
247         return negotiationOffer;
248     }
249 
250     /**
251      * @return the XML representation of the negotiation offer
252      */
253     public org.ogf.schemas.graap.wsAgreement.negotiation.NegotiationOfferType getXMLObject()
254     {
255         return this.negotiationOffer;
256     }
257 
258     /**
259      * Validates the internal XML representation of this object.
260      * 
261      * {@inheritDoc}
262      */
263     public boolean validate()
264     {
265         return validate( negotiationOffer );
266     }
267 
268 }