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.samples.actions;
36  
37  import org.ggf.schemas.jsdl.x2005.x11.jsdl.ResourcesType;
38  import org.ogf.graap.wsag.api.pattern.AdvanceReservationPattern;
39  import org.ogf.graap.wsag.api.pattern.ComputeResourcePattern;
40  import org.ogf.graap.wsag.api.types.TemplateType;
41  import org.ogf.graap.wsag4j.types.scheduling.TimeConstraintType;
42  import org.ogf.schemas.graap.wsAgreement.AgreementTemplateType;
43  
44  //@formatter:off
45  /**
46   *
47   * SampleTemplate
48   * 
49   * <pre>
50   * {@code
51   * <?xml version="1.0" encoding="UTF-8"?>
52   * <wsag:Template wsag:TemplateId="1"
53   *     xmlns:wsag="http://schemas.ggf.org/graap/2007/03/ws-agreement">
54   *     <wsag:Name>SAMPLE-TEMPLATE</wsag:Name>
55   *     <wsag:Context>
56   *         <wsag:ServiceProvider>AgreementResponder</wsag:ServiceProvider>
57   *         <wsag:TemplateId>1</wsag:TemplateId>
58   *         <wsag:TemplateName>SAMPLE-TEMPLATE</wsag:TemplateName>
59   *     </wsag:Context>
60   *     <wsag:Terms>
61   *         <wsag:All>
62   *             <wsag:ServiceDescriptionTerm wsag:Name="RESOURCE_STD"
63   *                 wsag:ServiceName="SAMPLE_SERVICE">
64   *                 <jsdl:JobDefinition xmlns:jsdl="http://schemas.ggf.org/jsdl/2005/11/jsdl">
65   *                     <jsdl:JobDescription>
66   *                         <jsdl:Resources>
67   *                             <jsdl:CandidateHosts>
68   *                                 <jsdl:HostName>some_host</jsdl:HostName>
69   *                             </jsdl:CandidateHosts>
70   *                             <jsdl:TotalResourceCount>
71   *                                 <jsdl:Exact>$TOTALRESOURCES</jsdl:Exact>
72   *                             </jsdl:TotalResourceCount>
73   *                         </jsdl:Resources>
74   *                     </jsdl:JobDescription>
75   *                 </jsdl:JobDefinition>
76   *             </wsag:ServiceDescriptionTerm>
77   *             <wsag:ServiceDescriptionTerm wsag:Name="TIME_CONSTRAINT_SDT"
78   *                 wsag:ServiceName="SAMPLE_SERVICE">
79   *                 <wsag4jt:TimeConstraint
80   *                     xmlns:wsag4jt="http://schemas.wsag4j.org/2009/07/wsag4j-scheduling-extensions">
81   *                     <wsag4jt:StartTime>$STARTTIME</wsag4jt:StartTime>
82   *                     <wsag4jt:EndTime>$ENDTIME</wsag4jt:EndTime>
83   *                     <wsag4jt:Duration>$DURATION</wsag4jt:Duration>
84   *                 </wsag4jt:TimeConstraint>
85   *             </wsag:ServiceDescriptionTerm>
86   *         </wsag:All>
87   *     </wsag:Terms>
88   *     <!-- The following creation constraints section is optional, however, if 
89   *         defined then agreement offer is validated against the defined creation constraints -->
90   *     <wsag:CreationConstraints>
91   *         <!-- Resources_SDT -->
92   *         <wsag:Item wsag:Name="ResourcesSDT_JobDefinition">
93   *             <wsag:Location>
94   *                 declare namespace jsdl='http://schemas.ggf.org/jsdl/2005/11/jsdl';
95   *                 declare namespace wsag='http://schemas.ggf.org/graap/2007/03/ws-agreement';
96   *                 $this/wsag:AgreementOffer/wsag:Terms/wsag:All/wsag:ServiceDescriptionTerm[@wsag:Name='RESOURCE_STD']
97   *                 /jsdl:JobDefinition
98   *             </wsag:Location>
99   *             <wsag:ItemConstraint>
100  *                 <xs:sequence xmlns:xs="http://www.w3.org/2001/XMLSchema">
101  *                     <xs:element name="JobDescription" minOccurs="1"
102  *                         maxOccurs="1" type="jsdl:JobDescription_Type" 
103  *                         xmlns:jsdl="http://schemas.ggf.org/jsdl/2005/11/jsdl" />
104  *                 </xs:sequence>
105  *             </wsag:ItemConstraint>
106  *         </wsag:Item>
107  *         <wsag:Item wsag:Name="ResourcesSDT_JobDefinition_JobDescription">
108  *             <wsag:Location>
109  *                  declare namespace jsdl='http://schemas.ggf.org/jsdl/2005/11/jsdl';
110  *                  declare namespace wsag='http://schemas.ggf.org/graap/2007/03/ws-agreement';
111  *                  $this/wsag:AgreementOffer/wsag:Terms/wsag:All/wsag:ServiceDescriptionTerm[@wsag:Name='RESOURCE_STD']
112  *                  /jsdl:JobDefinition/jsdl:JobDescription
113  *             </wsag:Location>
114  *             <wsag:ItemConstraint>
115  *                 <xs:sequence xmlns:xs="http://www.w3.org/2001/XMLSchema">
116  *                     <xs:element name="JobIdentification" minOccurs="0"
117  *                         maxOccurs="1" type="jsdl:JobIdentification_Type" 
118  *                         xmlns:jsdl="http://schemas.ggf.org/jsdl/2005/11/jsdl" />
119  *                     <xs:element name="Application" minOccurs="0" maxOccurs="0"
120  *                         type="jsdl:Application_Type" 
121  *                         xmlns:jsdl="http://schemas.ggf.org/jsdl/2005/11/jsdl" />
122  *                     <xs:element name="Resources" minOccurs="1" maxOccurs="1"
123  *                         type="jsdl:Resources_Type" 
124  *                         xmlns:jsdl="http://schemas.ggf.org/jsdl/2005/11/jsdl" />
125  *                     <xs:element name="DataStaging" minOccurs="0" maxOccurs="0"
126  *                         type="jsdl:DataStaging_Type" 
127  *                         xmlns:jsdl="http://schemas.ggf.org/jsdl/2005/11/jsdl" />
128  *                 </xs:sequence>
129  *             </wsag:ItemConstraint>
130  *         </wsag:Item>
131  *         <wsag:Item wsag:Name="ResourcesSDT_JobDefinition_JobDescription_Resources">
132  *             <wsag:Location>
133  *                 declare namespace jsdl='http://schemas.ggf.org/jsdl/2005/11/jsdl';
134  *                 declare namespace wsag='http://schemas.ggf.org/graap/2007/03/ws-agreement';
135  *                 $this/wsag:AgreementOffer/wsag:Terms/wsag:All/wsag:ServiceDescriptionTerm[@wsag:Name='RESOURCE_STD']
136  *                 /jsdl:JobDefinition/jsdl:JobDescription/jsdl:Resources
137  *             </wsag:Location>
138  *             <wsag:ItemConstraint>
139  *                 <xs:sequence xmlns:xs="http://www.w3.org/2001/XMLSchema">
140  *                     <xs:element name="CandidateHosts" minOccurs="1"
141  *                         maxOccurs="1" type="jsdl:CandidateHosts_Type" 
142  *                         xmlns:jsdl="http://schemas.ggf.org/jsdl/2005/11/jsdl" />
143  *                     <xs:element name="TotalResourceCount" minOccurs="1"
144  *                         maxOccurs="1" type="jsdl:RangeValue_Type" 
145  *                         xmlns:jsdl="http://schemas.ggf.org/jsdl/2005/11/jsdl" />
146  *                 </xs:sequence>
147  *             </wsag:ItemConstraint>
148  *         </wsag:Item>
149  *         <wsag:Item
150  *             wsag:Name="ResourcesSDT_JobDefinition_JobDescription_Resources_TotalResourceCount">
151  *             <wsag:Location>
152  *                  declare namespace jsdl='http://schemas.ggf.org/jsdl/2005/11/jsdl';
153  *                  declare namespace wsag='http://schemas.ggf.org/graap/2007/03/ws-agreement';
154  *                  $this/wsag:AgreementOffer/wsag:Terms/wsag:All/wsag:ServiceDescriptionTerm[@wsag:Name='RESOURCE_STD']
155  *                  /jsdl:JobDefinition/jsdl:JobDescription/jsdl:Resources/jsdl:TotalResourceCount
156  *             </wsag:Location>
157  *             <wsag:ItemConstraint>
158  *                 <xs:sequence xmlns:xs="http://www.w3.org/2001/XMLSchema">
159  *                     <xs:element name="UpperBoundedRange" minOccurs="0"
160  *                         maxOccurs="0" type="jsdl:Boundary_Type" 
161  *                         xmlns:jsdl="http://schemas.ggf.org/jsdl/2005/11/jsdl" />
162  *                     <xs:element name="LowerBoundedRange" minOccurs="0"
163  *                         maxOccurs="0" type="jsdl:Boundary_Type" 
164  *                         xmlns:jsdl="http://schemas.ggf.org/jsdl/2005/11/jsdl" />
165  *                     <xs:element name="Exact" minOccurs="1" maxOccurs="1"
166  *                         type="jsdl:Exact_Type" 
167  *                         xmlns:jsdl="http://schemas.ggf.org/jsdl/2005/11/jsdl" />
168  *                     <xs:element name="Range" minOccurs="0" maxOccurs="0"
169  *                         type="jsdl:Range_Type" 
170  *                         xmlns:jsdl="http://schemas.ggf.org/jsdl/2005/11/jsdl" />
171  *                 </xs:sequence>
172  *             </wsag:ItemConstraint>
173  *         </wsag:Item>
174  *         <wsag:Item
175  *             wsag:Name="ResourcesSDT_JobDefinition_JobDescription_Resources_TotalResourceCount_Exact">
176  *             <wsag:Location>
177  *                  declare namespace jsdl='http://schemas.ggf.org/jsdl/2005/11/jsdl';
178  *                  declare namespace wsag='http://schemas.ggf.org/graap/2007/03/ws-agreement';
179  *                  $this/wsag:AgreementOffer/wsag:Terms/wsag:All/wsag:ServiceDescriptionTerm[@wsag:Name='RESOURCE_STD']
180  *                  /jsdl:JobDefinition/jsdl:JobDescription/jsdl:Resources/jsdl:TotalResourceCount/jsdl:Exact
181  *             </wsag:Location>
182  *             <wsag:ItemConstraint>
183  *                 <xs:minInclusive value="1"
184  *                     xmlns:xs="http://www.w3.org/2001/XMLSchema" />
185  *                 <xs:maxInclusive value="$TOTALRESOURCES"
186  *                     xmlns:xs="http://www.w3.org/2001/XMLSchema" />
187  *             </wsag:ItemConstraint>
188  *         </wsag:Item>
189  *         <!-- Agreement Offer Structure -->
190  *         <wsag:Item wsag:Name="AgreementOffer">
191  *             <wsag:Location>
192  *                  declare namespace wsag='http://schemas.ggf.org/graap/2007/03/ws-agreement';
193  *                  $this/wsag:AgreementOffer
194  *             </wsag:Location>
195  *             <wsag:ItemConstraint>
196  *                 <xs:sequence xmlns:xs="http://www.w3.org/2001/XMLSchema">
197  *                     <xs:element ref="wsag:Name" minOccurs="0" maxOccurs="1" />
198  *                     <xs:element ref="wsag:Context" minOccurs="1" maxOccurs="1" />
199  *                     <xs:element ref="wsag:Terms" minOccurs="1" maxOccurs="1" />
200  *                 </xs:sequence>
201  *             </wsag:ItemConstraint>
202  *         </wsag:Item>
203  *         <wsag:Item wsag:Name="AgreementOffer_Context">
204  *             <wsag:Location>
205  *                  declare namespace wsag='http://schemas.ggf.org/graap/2007/03/ws-agreement';
206  *                  $this/wsag:AgreementOffer/wsag:Context
207  *             </wsag:Location>
208  *             <wsag:ItemConstraint>
209  *                 <xs:sequence xmlns:xs="http://www.w3.org/2001/XMLSchema">
210  *                     <xs:element name="AgreementInitiator" type="xs:anyType"
211  *                         minOccurs="0" maxOccurs="0" />
212  *                     <xs:element name="AgreementResponder" type="xs:anyType"
213  *                         minOccurs="0" maxOccurs="0" />
214  *                     <xs:element name="ServiceProvider" type="wsag:AgreementRoleType"
215  *                         minOccurs="1" maxOccurs="1" />
216  *                     <xs:element name="ExpirationTime" type="xs:dateTime"
217  *                         minOccurs="0" maxOccurs="0" />
218  *                     <xs:element name="TemplateId" type="xs:string"
219  *                         minOccurs="1" maxOccurs="1" />
220  *                     <xs:element name="TemplateName" type="xs:string"
221  *                         minOccurs="1" maxOccurs="1" />
222  *                     <xs:any maxOccurs="0" minOccurs="0" namespace="##other"
223  *                         processContents="lax" />
224  *                 </xs:sequence>
225  *             </wsag:ItemConstraint>
226  *         </wsag:Item>
227  *         <wsag:Item wsag:Name="AgreementOffer_Context_ServiceProvider">
228  *             <wsag:Location>
229  *                  declare namespace wsag='http://schemas.ggf.org/graap/2007/03/ws-agreement';
230  *                  $this/wsag:AgreementOffer/wsag:Context/wsag:ServiceProvider
231  *             </wsag:Location>
232  *             <wsag:ItemConstraint>
233  *                 <xs:simpleType xmlns:xs="http://www.w3.org/2001/XMLSchema">
234  *                     <xs:restriction base="wsag:AgreementRoleType">
235  *                         <xs:enumeration value="AgreementResponder" />
236  *                     </xs:restriction>
237  *                 </xs:simpleType>
238  *             </wsag:ItemConstraint>
239  *         </wsag:Item>
240  *         <wsag:Item wsag:Name="AgreementOffer_Terms">
241  *             <wsag:Location>
242  *                  declare namespace wsag='http://schemas.ggf.org/graap/2007/03/ws-agreement';
243  *                  $this/wsag:AgreementOffer/wsag:Terms
244  *             </wsag:Location>
245  *             <wsag:ItemConstraint>
246  *                 <xs:sequence xmlns:xs="http://www.w3.org/2001/XMLSchema">
247  *                     <xs:element name="All" minOccurs="1" maxOccurs="1"
248  *                         type="wsag:TermCompositorType" />
249  *                 </xs:sequence>
250  *             </wsag:ItemConstraint>
251  *         </wsag:Item>
252  *         <wsag:Item wsag:Name="AgreementOffer_Terms_All">
253  *             <wsag:Location>
254  *                  declare namespace wsag='http://schemas.ggf.org/graap/2007/03/ws-agreement';
255  *                  $this/wsag:AgreementOffer/wsag:Terms/wsag:All
256  *             </wsag:Location>
257  *             <wsag:ItemConstraint>
258  *                 <xs:sequence xmlns:xs="http://www.w3.org/2001/XMLSchema">
259  *                     <xs:choice maxOccurs="2">
260  *                         <xs:element name="ExactlyOne" minOccurs="0" maxOccurs="0"
261  *                             type="wsag:TermCompositorType" />
262  *                         <xs:element name="OneOrMore" minOccurs="0" maxOccurs="0"
263  *                             type="wsag:TermCompositorType" />
264  *                         <xs:element ref="wsag:All" minOccurs="0" maxOccurs="0" />
265  *                         <xs:element name="ServiceDescriptionTerm" minOccurs="1"
266  *                             maxOccurs="1" type="wsag:ServiceDescriptionTermType" />
267  *                         <xs:element name="ServiceReference" minOccurs="0"
268  *                             maxOccurs="0" type="wsag:ServiceReferenceType" />
269  *                         <xs:element name="ServiceProperties" minOccurs="0"
270  *                             maxOccurs="0" type="wsag:ServicePropertiesType" />
271  *                         <xs:element name="GuaranteeTerm" minOccurs="0"
272  *                             maxOccurs="0" type="wsag:GuaranteeTermType" />
273  *                     </xs:choice>
274  *                 </xs:sequence>
275  *             </wsag:ItemConstraint>
276  *         </wsag:Item>
277  *     </wsag:CreationConstraints>
278  * </wsag:Template>  
279  * }
280  * </pre>
281  *
282  * @author hrasheed
283  **/
284 //@formatter:on
285 
286 public class SampleAgreementTemplate extends TemplateType
287 {
288 
289     /**
290      * Template name for which this pattern applies.
291      */
292     public static final String NAME = "SAMPLE-TEMPLATE";
293 
294     /**
295      * Template id for which this pattern applies.
296      */
297     public static final String ID = "1";
298 
299     private ComputeResourcePattern resourcePattern = null;
300 
301     private AdvanceReservationPattern arPattern = null;
302 
303     /**
304      * Creates a Sample Template instance based on a given XML representation.
305      * 
306      * @param template
307      *            the XML representation of the template
308      */
309     public SampleAgreementTemplate( AgreementTemplateType template )
310     {
311         super( template );
312 
313         //
314         // use the internal XML object for creating the pattern
315         //
316         template = getXMLObject();
317 
318         resourcePattern = new ComputeResourcePattern( template.getTerms().getAll() );
319         arPattern = new AdvanceReservationPattern( template.getTerms().getAll() );
320     }
321 
322     /**
323      * @return the resource definition
324      * @see ComputeResourcePattern#getResourceDefinition()
325      */
326     public ResourcesType getResourceDefinition()
327     {
328         return resourcePattern.getResourceDefinition();
329     }
330 
331     /**
332      * @return the specified time constraints
333      * 
334      * @see AdvanceReservationPattern#getTimeConstraint()
335      */
336     public TimeConstraintType getTimeConstraint()
337     {
338         return arPattern.getTimeConstraint();
339     }
340 
341     /**
342      * 
343      * @return negotiation offer based on this template
344      * 
345      * @throws Exception
346      *             failed to create the negotiation offer object
347      */
348     public SampleNegotiationOffer getNegotiationOffer() throws Exception
349     {
350         return new SampleNegotiationOffer( getXMLObject() );
351     }
352 
353     /**
354      * 
355      * @return an agreement offer based on this template
356      * 
357      * @throws Exception
358      *             failed to create the offer object
359      */
360     public SampleAgreementOffer getAgreementOffer() throws Exception
361     {
362         return new SampleAgreementOffer( getXMLObject() );
363     }
364 
365 }