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.pattern;
36
37 import org.apache.xmlbeans.XmlObject;
38 import org.ogf.graap.wsag4j.types.scheduling.TimeConstraintType;
39 import org.ogf.schemas.graap.wsAgreement.TermCompositorType;
40
41 /**
42 * AdvanceReservationPattern
43 *
44 * An advance reservation pattern includes a service description term that defines the earliest start time of
45 * the overall service. The example below illustrates the structure of an advance reservation template.
46 *
47 * <pre>
48 * {@code
49 * <wsag:Template wsag:TemplateId="1"
50 * xmlns:wsag="http://schemas.ggf.org/graap/2007/03/ws-agreement">
51 * <wsag:Name>ADAVANCE_RESERVATION_TEMPLATE</wsag:Name>
52 * <wsag:Context>
53 * <wsag:ServiceProvider>AgreementResponder</wsag:ServiceProvider>
54 * <wsag:TemplateId>1</wsag:TemplateId>
55 * <wsag:TemplateName>ADAVANCE_RESERVATION_TEMPLATE</wsag:TemplateName>
56 * </wsag:Context>
57 * <wsag:Terms>
58 * <wsag:All>
59 * <wsag:ServiceDescriptionTerm wsag:Name="SDT_1"
60 * wsag:ServiceName="SERVICE_1">
61 * (Put your service description terms here) ....
62 * </wsag:ServiceDescriptionTerm>
63 * ...
64 * <wsag:ServiceDescriptionTerm wsag:Name="TIME_CONSTRAINT_SDT"
65 * wsag:ServiceName="SERVICE_1">
66 * <wsag-tc:TimeConstraint
67 * xmlns:wsag-tc="http://schemas.wsag4j.org/2009/07/wsag4j-scheduling-extensions">
68 * <wsag-tc:StartTime>2010-06-24T02:00:00</wsag-tc:StartTime>
69 * </wsag-tc:TimeConstraint>
70 * </wsag:ServiceDescriptionTerm>
71 * </wsag:All>
72 * </wsag:Terms>
73 * <wsag:CreationConstraints />
74 * </wsag:Template>
75 * }
76 * </pre>
77 *
78 *
79 * @author Oliver Waeldrich
80 *
81 */
82 public class AdvanceReservationPattern extends AbstractPattern
83 {
84
85 private TimeConstraintType timeConstraint;
86
87 private String timeConstraintXPath =
88 "declare namespace wsag-tc='http://schemas.wsag4j.org/2009/07/wsag4j-scheduling-extensions';"
89 + "declare namespace wsag='http://schemas.ggf.org/graap/2007/03/ws-agreement';"
90 + "$this/wsag:ServiceDescriptionTerm[@wsag:Name = 'TIME_CONSTRAINT_SDT']/wsag-tc:TimeConstraint";
91
92 /**
93 * Instantiates the advance reservation pattern on a given term compositor.
94 *
95 * @param termCompositor
96 * the term compositor
97 */
98 public AdvanceReservationPattern( TermCompositorType termCompositor )
99 {
100 super( termCompositor );
101
102 initialize();
103 }
104
105 /**
106 * initializes the pattern object after creation
107 */
108 protected void initialize()
109 {
110 XmlObject[] arConstraints = getTermCompositor().selectPath( getTimeConstraintXPath() );
111
112 if ( arConstraints.length != 1 )
113 {
114 throw new IllegalStateException(
115 "Invalid number of advance reservation time constraints in template." );
116 }
117
118 timeConstraint = (TimeConstraintType) arConstraints[0];
119 }
120
121 /**
122 * @return the timeConstraint
123 */
124 public TimeConstraintType getTimeConstraint()
125 {
126 return timeConstraint;
127 }
128
129 /**
130 * @param timeConstraintXPath
131 * the timeConstraintXPath to set
132 */
133 public void setTimeConstraintXPath( String timeConstraintXPath )
134 {
135 this.timeConstraintXPath = timeConstraintXPath;
136 }
137
138 /**
139 * @return the timeConstraintXPath
140 */
141 public String getTimeConstraintXPath()
142 {
143 return timeConstraintXPath;
144 }
145
146 }