1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 package org.ogf.graap.wsag.api.types;
36
37 import org.ogf.graap.wsag.api.AgreementOffer;
38 import org.ogf.schemas.graap.wsAgreement.AgreementContextType;
39 import org.ogf.schemas.graap.wsAgreement.AgreementOfferDocument;
40 import org.ogf.schemas.graap.wsAgreement.AgreementTemplateType;
41 import org.ogf.schemas.graap.wsAgreement.AgreementType;
42 import org.ogf.schemas.graap.wsAgreement.CreateAgreementInputDocument;
43 import org.ogf.schemas.graap.wsAgreement.CreateAgreementInputType;
44 import org.ogf.schemas.graap.wsAgreement.NoncriticalExtensionType;
45 import org.ogf.schemas.graap.wsAgreement.TermTreeType;
46 import org.ogf.schemas.graap.wsAgreement.negotiation.NegotiationOfferType;
47 import org.w3.x2005.x08.addressing.EndpointReferenceType;
48
49
50
51
52
53
54 public class AgreementOfferType extends WSAGXmlType
55 implements AgreementOffer
56 {
57
58 private final CreateAgreementInputDocument agreementOfferDocument =
59 CreateAgreementInputDocument.Factory.newInstance();
60
61 private AgreementType offer;
62
63
64
65
66
67
68
69 public AgreementOfferType( AgreementTemplateType template )
70 {
71
72
73
74 AgreementType processed = processTemplate( template );
75
76
77
78
79 initialize( processed );
80 }
81
82
83
84
85
86
87
88 public AgreementOfferType( org.ogf.graap.wsag.api.types.NegotiationOfferTypeImpl negotiationOffer )
89 {
90 this( negotiationOffer.getXMLObject() );
91 }
92
93
94
95
96
97
98
99 public AgreementOfferType( NegotiationOfferType negotiationOffer )
100 {
101 AgreementOfferDocument offerDoc = AgreementOfferDocument.Factory.newInstance();
102 offerDoc.addNewAgreementOffer();
103
104 if ( negotiationOffer.isSetAgreementId() )
105 {
106 offerDoc.getAgreementOffer().setAgreementId( negotiationOffer.getAgreementId() );
107 }
108
109 if ( negotiationOffer.isSetName() )
110 {
111 offerDoc.getAgreementOffer().setName( negotiationOffer.getName() );
112 }
113
114 if ( negotiationOffer.getContext() != null )
115 {
116 offerDoc.getAgreementOffer().addNewContext().set( negotiationOffer.getContext().copy() );
117 }
118
119 if ( negotiationOffer.getTerms() != null )
120 {
121 offerDoc.getAgreementOffer().addNewTerms().set( negotiationOffer.getTerms().copy() );
122 }
123
124 initialize( offerDoc.getAgreementOffer() );
125 }
126
127
128
129
130
131
132
133 public AgreementOfferType( AgreementType offer )
134 {
135 initialize( (AgreementType) offer.copy() );
136 }
137
138 private void initialize( AgreementType offerTemplate )
139 {
140 if ( offerTemplate == null )
141 {
142 throw new IllegalStateException( "Parameter Template must not be null." );
143 }
144
145 if ( offerTemplate.getContext() == null )
146 {
147 throw new IllegalStateException( "Parameter Template#Context must not be null." );
148 }
149
150 if ( offerTemplate.getTerms() == null )
151 {
152 throw new IllegalStateException( "Parameter Template#Terms must not be null." );
153 }
154
155
156
157
158 CreateAgreementInputType input = agreementOfferDocument.addNewCreateAgreementInput();
159 offer = (AgreementType) input.addNewAgreementOffer().set( offerTemplate );
160
161 String agreementId =
162 ( offerTemplate.getAgreementId() != null ) ? offerTemplate.getAgreementId() : "1";
163 String agreementName =
164 ( offerTemplate.getName() != null ) ? offerTemplate.getName() : "AGREEMENT_OFFER";
165
166 setAgreementId( agreementId );
167 setName( agreementName );
168 }
169
170
171
172
173 public EndpointReferenceType getInitiatorEPR()
174 {
175 return getAgreementInput().getInitiatorAgreementEPR();
176 }
177
178
179
180
181 public NoncriticalExtensionType[] getNoncriticalExtensions()
182 {
183 return getAgreementInput().getNoncriticalExtensionArray();
184 }
185
186
187
188
189 public void setInitiatorEPR( EndpointReferenceType initiatorAgreementEPR )
190 {
191 getAgreementInput().setInitiatorAgreementEPR( initiatorAgreementEPR );
192 }
193
194
195
196
197 public void setNoncriticalExtensions( NoncriticalExtensionType[] noncriticalExtensionArray )
198 {
199 getAgreementInput().setNoncriticalExtensionArray( noncriticalExtensionArray );
200 }
201
202
203
204
205 public String getAgreementId()
206 {
207 return getAgreementOffer().getAgreementId();
208 }
209
210
211
212
213 public AgreementContextType getContext()
214 {
215 return getAgreementOffer().getContext();
216 }
217
218
219
220
221 public String getName()
222 {
223 return getAgreementOffer().getName();
224 }
225
226
227
228
229 public TermTreeType getTerms()
230 {
231 return getAgreementOffer().getTerms();
232 }
233
234
235
236
237 public void setAgreementId( String agreementId )
238 {
239 getAgreementOffer().setAgreementId( agreementId );
240 }
241
242
243
244
245 public void setContext( AgreementContextType context )
246 {
247 getAgreementOffer().setContext( context );
248 }
249
250
251
252
253 public void setName( String name )
254 {
255 getAgreementOffer().setName( name );
256 }
257
258
259
260
261 public void setTerms( TermTreeType terms )
262 {
263 getAgreementOffer().setTerms( terms );
264 }
265
266
267
268
269 @Override
270 public boolean validate()
271 {
272 return validate( agreementOfferDocument );
273 }
274
275 private CreateAgreementInputType getAgreementInput()
276 {
277 return agreementOfferDocument.getCreateAgreementInput();
278 }
279
280 private AgreementType getAgreementOffer()
281 {
282 return offer;
283 }
284
285
286
287
288 public AgreementType getXMLObject()
289 {
290 return offer;
291 }
292
293 }