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.AgreementTemplate;
38  import org.ogf.schemas.graap.wsAgreement.AgreementContextType;
39  import org.ogf.schemas.graap.wsAgreement.AgreementRoleType;
40  import org.ogf.schemas.graap.wsAgreement.AgreementTemplateType;
41  import org.ogf.schemas.graap.wsAgreement.ConstraintSectionType;
42  import org.ogf.schemas.graap.wsAgreement.TemplateDocument;
43  import org.ogf.schemas.graap.wsAgreement.TermTreeType;
44  
45  /**
46   * AgreementTemplateType
47   * 
48   * @author Oliver Waeldrich
49   */
50  public class TemplateType extends WSAGXmlType implements AgreementTemplate
51  {
52      AgreementTemplateType template = AgreementTemplateType.Factory.newInstance();
53  
54      /**
55       * Default constructor.
56       */
57      public TemplateType()
58      {
59          initialize();
60      }
61  
62      /**
63       * Creates a new template type based on a template XML document.
64       * 
65       * @param template
66       *            the agreement template
67       */
68      public TemplateType( AgreementTemplateType template )
69      {
70          //
71          // make sure that template is not a document fragment
72          //
73          TemplateDocument templateDoc = TemplateDocument.Factory.newInstance();
74          templateDoc.addNewTemplate().set( template.copy() );
75          this.template = templateDoc.getTemplate();
76      }
77  
78      /**
79       * {@inheritDoc}
80       */
81      public boolean validate()
82      {
83          return validate( template );
84      }
85  
86      private void initialize()
87      {
88          AgreementContextType context = template.addNewContext();
89          context.setServiceProvider( AgreementRoleType.AGREEMENT_RESPONDER );
90  
91          template.addNewTerms();
92          template.addNewCreationConstraints();
93      }
94  
95      /**
96       * {@inheritDoc}
97       */
98      public String getAgreementId()
99      {
100         return template.getAgreementId();
101     }
102 
103     /**
104      * {@inheritDoc}
105      */
106     public AgreementContextType getContext()
107     {
108         return template.getContext();
109     }
110 
111     /**
112      * {@inheritDoc}
113      */
114     public ConstraintSectionType getCreationConstraints()
115     {
116         return template.getCreationConstraints();
117     }
118 
119     /**
120      * {@inheritDoc}
121      */
122     public String getName()
123     {
124         return template.getName();
125     }
126 
127     /**
128      * {@inheritDoc}
129      */
130     public String getTemplateId()
131     {
132         return template.getTemplateId();
133     }
134 
135     /**
136      * {@inheritDoc}
137      */
138     public TermTreeType getTerms()
139     {
140         return template.getTerms();
141     }
142 
143     /**
144      * {@inheritDoc}
145      */
146     public void setAgreementId( String arg0 )
147     {
148         template.setAgreementId( arg0 );
149     }
150 
151     /**
152      * {@inheritDoc}
153      */
154     public void setContext( AgreementContextType arg0 )
155     {
156         template.setContext( arg0 );
157     }
158 
159     /**
160      * {@inheritDoc}
161      */
162     public void setCreationConstraints( ConstraintSectionType arg0 )
163     {
164         template.setCreationConstraints( arg0 );
165     }
166 
167     /**
168      * {@inheritDoc}
169      */
170     public void setName( String arg0 )
171     {
172         template.setName( arg0 );
173     }
174 
175     /**
176      * {@inheritDoc}
177      */
178     public void setTemplateId( String arg0 )
179     {
180         template.setTemplateId( arg0 );
181     }
182 
183     /**
184      * {@inheritDoc}
185      */
186     public void setTerms( TermTreeType arg0 )
187     {
188         template.setTerms( arg0 );
189     }
190 
191     /**
192      * {@inheritDoc}
193      */
194     public AgreementTemplateType getXMLObject()
195     {
196         return template;
197     }
198 
199 }