View Javadoc

1   /*
2    * Copyright 2008 Members of the EGEE Collaboration.
3    * Copyright 2008 University Corporation for Advanced Internet Development, Inc.
4    *
5    * Licensed under the Apache License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    *
9    * http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.opensaml.xacml.policy.impl;
19  
20  import java.util.ArrayList;
21  import java.util.List;
22  
23  import org.opensaml.xacml.XACMLObject;
24  import org.opensaml.xacml.policy.CombinerParametersType;
25  import org.opensaml.xacml.policy.DefaultsType;
26  import org.opensaml.xacml.policy.DescriptionType;
27  import org.opensaml.xacml.policy.IdReferenceType;
28  import org.opensaml.xacml.policy.ObligationsType;
29  import org.opensaml.xacml.policy.PolicyCombinerParametersType;
30  import org.opensaml.xacml.policy.PolicySetCombinerParametersType;
31  import org.opensaml.xacml.policy.PolicySetType;
32  import org.opensaml.xacml.policy.PolicyType;
33  import org.opensaml.xacml.policy.TargetType;
34  import org.opensaml.xml.XMLObject;
35  import org.opensaml.xml.util.IndexedXMLObjectChildrenList;
36  import org.opensaml.xml.validation.AbstractValidatingXMLObject;
37  
38  /** Concrete implementation of {@link PolicySetType}. */
39  public class PolicySetTypeImpl extends AbstractValidatingXMLObject implements PolicySetType {
40  
41      /** Policy set description. */
42      private DescriptionType description;
43  
44      /** Policy set defaults. */
45      private DefaultsType policySetDefaults;
46  
47      /** Policy set target. */
48      private TargetType target;
49  
50      /** Elements within the choice group. */
51      private IndexedXMLObjectChildrenList<? extends XACMLObject> choiceGroup;
52  
53      /** Policy obligations. */
54      private ObligationsType obligations;
55  
56      /** ID of this policy set. */
57      private String policySetId;
58  
59      /** Version of this policy set. */
60      private String version;
61  
62      /** Policy combinging algorithm ID. */
63      private String combiningAlgo;
64  
65      /**
66       * Constructor.
67       * 
68       * @param namespaceURI the namespace the element is in
69       * @param elementLocalName the local name of the XML element this Object represents
70       * @param namespacePrefix the prefix for the given namespace
71       */
72      protected PolicySetTypeImpl(String namespaceURI, String elementLocalName, String namespacePrefix) {
73          super(namespaceURI, elementLocalName, namespacePrefix);
74          choiceGroup = new IndexedXMLObjectChildrenList<XACMLObject>(this);
75      }
76  
77      /** {@inheritDoc} */
78      public List<CombinerParametersType> getCombinerParameters() {
79          return (List<CombinerParametersType>) choiceGroup.subList(CombinerParametersType.DEFAULT_ELEMENT_NAME);
80      }
81  
82      /** {@inheritDoc} */
83      public DescriptionType getDescription() {
84          return description;
85      }
86  
87      /** {@inheritDoc} */
88      public ObligationsType getObligations() {
89          return obligations;
90      }
91  
92      /** {@inheritDoc} */
93      public List<XMLObject> getOrderedChildren() {
94          ArrayList<XMLObject> children = new ArrayList<XMLObject>();
95          if (description != null) {
96              children.add(description);
97          }
98  
99          if (policySetDefaults != null) {
100             children.add(policySetDefaults);
101         }
102 
103         children.add(target);
104 
105         if (!choiceGroup.isEmpty()) {
106             children.addAll(choiceGroup);
107         }
108 
109         if (obligations != null) {
110             children.add(obligations);
111         }
112 
113         return children;
114     }
115 
116     /** {@inheritDoc} */
117     public List<PolicyType> getPolicies() {
118         return (List<PolicyType>) choiceGroup.subList(PolicyType.DEFAULT_ELEMENT_NAME);
119     }
120 
121     /** {@inheritDoc} */
122     public List<PolicyCombinerParametersType> getPolicyCombinerParameters() {
123         return (List<PolicyCombinerParametersType>) choiceGroup
124                 .subList(PolicyCombinerParametersType.DEFAULT_ELEMENT_NAME);
125     }
126 
127     /** {@inheritDoc} */
128     public String getPolicyCombiningAlgoId() {
129         return combiningAlgo;
130     }
131 
132     /** {@inheritDoc} */
133     public List<IdReferenceType> getPolicyIdReferences() {
134         return (List<IdReferenceType>) choiceGroup.subList(IdReferenceType.POLICY_ID_REFERENCE_ELEMENT_NAME);
135     }
136 
137     /** {@inheritDoc} */
138     public List<PolicySetCombinerParametersType> getPolicySetCombinerParameters() {
139         return (List<PolicySetCombinerParametersType>) choiceGroup
140                 .subList(PolicySetCombinerParametersType.DEFAULT_ELEMENT_NAME);
141     }
142 
143     /** {@inheritDoc} */
144     public DefaultsType getPolicySetDefaults() {
145         return policySetDefaults;
146     }
147 
148     /** {@inheritDoc} */
149     public String getPolicySetId() {
150         return policySetId;
151     }
152 
153     /** {@inheritDoc} */
154     public List<IdReferenceType> getPolicySetIdReferences() {
155         return (List<IdReferenceType>) choiceGroup.subList(IdReferenceType.POLICY_SET_ID_REFERENCE_ELEMENT_NAME);
156     }
157 
158     /** {@inheritDoc} */
159     public List<PolicySetType> getPolicySets() {
160         return (List<PolicySetType>) choiceGroup.subList(PolicySetType.DEFAULT_ELEMENT_NAME);
161     }
162 
163     /** {@inheritDoc} */
164     public TargetType getTarget() {
165         return target;
166     }
167 
168     /** {@inheritDoc} */
169     public String getVersion() {
170         return version;
171     }
172 
173     /** {@inheritDoc} */
174     public void setDescription(DescriptionType newDescription) {
175         this.description = prepareForAssignment(this.description, newDescription);
176     }
177 
178     /** {@inheritDoc} */
179     public void setObligations(ObligationsType newObligations) {
180         this.obligations = prepareForAssignment(this.obligations, newObligations);
181     }
182 
183     /** {@inheritDoc} */
184     public void setPolicyCombiningAlgoId(String id) {
185         combiningAlgo = prepareForAssignment(combiningAlgo, id);
186     }
187 
188     /** {@inheritDoc} */
189     public void setPolicySetDefaults(DefaultsType defaults) {
190         policySetDefaults = prepareForAssignment(policySetDefaults, defaults);
191     }
192 
193     /** {@inheritDoc} */
194     public void setPolicySetId(String id) {
195         policySetId = prepareForAssignment(policySetId, id);
196     }
197 
198     /** {@inheritDoc} */
199     public void setTarget(TargetType newTarget) {
200         this.target = prepareForAssignment(this.target, newTarget);
201     }
202 
203     /** {@inheritDoc} */
204     public void setVersion(String newVersion) {
205         this.version = prepareForAssignment(this.version, newVersion);
206     }
207 
208     /** {@inheritDoc} */
209     public IndexedXMLObjectChildrenList<XACMLObject> getPolicyChoiceGroup() {
210         return (IndexedXMLObjectChildrenList<XACMLObject>) choiceGroup;
211     }
212 }