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.ObligationsType;
28  import org.opensaml.xacml.policy.PolicyType;
29  import org.opensaml.xacml.policy.RuleCombinerParametersType;
30  import org.opensaml.xacml.policy.RuleType;
31  import org.opensaml.xacml.policy.TargetType;
32  import org.opensaml.xacml.policy.VariableDefinitionType;
33  import org.opensaml.xml.XMLObject;
34  import org.opensaml.xml.util.IndexedXMLObjectChildrenList;
35  import org.opensaml.xml.validation.AbstractValidatingXMLObject;
36  
37  /** Concrete implemenation of {@link PolicyType}. */
38  public class PolicyTypeImpl extends AbstractValidatingXMLObject implements PolicyType {
39  
40      /** Policy description. */
41      private DescriptionType description;
42  
43      /** Policy defaults. */
44      private DefaultsType policyDefaults;
45  
46      /** Policy target. */
47      private TargetType target;
48  
49      /** Elements within the choice group. */
50      private IndexedXMLObjectChildrenList<? extends XACMLObject> choiceGroup;
51  
52      /** Policy obligations. */
53      private ObligationsType obligations;
54  
55      /** ID of this policy. */
56      private String policyId;
57  
58      /** Version of this policy. */
59      private String version;
60  
61      /** Rule combinging algorithm ID. */
62      private String ruleCombiningAlgo;
63  
64      /**
65       * Constructor.
66       * 
67       * @param namespaceURI the namespace the element is in
68       * @param elementLocalName the local name of the XML element this Object represents
69       * @param namespacePrefix the prefix for the given namespace
70       */
71      protected PolicyTypeImpl(String namespaceURI, String elementLocalName, String namespacePrefix) {
72          super(namespaceURI, elementLocalName, namespacePrefix);
73          choiceGroup = new IndexedXMLObjectChildrenList<XACMLObject>(this);
74      }
75  
76      /** {@inheritDoc} */
77      public List<CombinerParametersType> getCombinerParameters() {
78          return (List<CombinerParametersType>) choiceGroup.subList(CombinerParametersType.DEFAULT_ELEMENT_NAME);
79      }
80  
81      /** {@inheritDoc} */
82      public DescriptionType getDescription() {
83          return description;
84      }
85  
86      /** {@inheritDoc} */
87      public ObligationsType getObligations() {
88          return obligations;
89      }
90  
91      /** {@inheritDoc} */
92      public DefaultsType getPolicyDefaults() {
93          return policyDefaults;
94      }
95  
96      /** {@inheritDoc} */
97      public String getPolicyId() {
98          return policyId;
99      }
100 
101     /** {@inheritDoc} */
102     public List<RuleCombinerParametersType> getRuleCombinerParameters() {
103         return (List<RuleCombinerParametersType>) choiceGroup.subList(RuleCombinerParametersType.DEFAULT_ELEMENT_NAME);
104     }
105 
106     /** {@inheritDoc} */
107     public String getRuleCombiningAlgoId() {
108         return ruleCombiningAlgo;
109     }
110 
111     /** {@inheritDoc} */
112     public List<RuleType> getRules() {
113        	return (List<RuleType>) choiceGroup.subList(RuleType.DEFAULT_ELEMENT_NAME);
114     }
115 
116     /** {@inheritDoc} */
117     public TargetType getTarget() {
118         return target;
119     }
120 
121     /** {@inheritDoc} */
122     public List<VariableDefinitionType> getVariableDefinitions() {
123         return (List<VariableDefinitionType>) choiceGroup.subList(VariableDefinitionType.DEFAULT_ELEMENT_NAME);
124     }
125 
126     /** {@inheritDoc} */
127     public String getVersion() {
128         return version;
129     }
130 
131     /** {@inheritDoc} */
132     public void setDescription(DescriptionType newDescription) {
133         this.description = prepareForAssignment(this.description, newDescription);
134     }
135 
136     /** {@inheritDoc} */
137     public void setObligations(ObligationsType newObligations) {
138         this.obligations = prepareForAssignment(this.obligations, newObligations);
139     }
140 
141     /** {@inheritDoc} */
142     public void setPolicyDefaults(DefaultsType defaults) {
143         policyDefaults = prepareForAssignment(policyDefaults, defaults);
144     }
145 
146     /** {@inheritDoc} */
147     public void setPolicyId(String id) {
148         policyId = prepareForAssignment(policyId, id);
149     }
150 
151     /** {@inheritDoc} */
152     public void setRuleCombiningAlgoId(String id) {
153         ruleCombiningAlgo = prepareForAssignment(ruleCombiningAlgo, id);
154     }
155 
156     /** {@inheritDoc} */
157     public void setTarget(TargetType newTarget) {
158         this.target = prepareForAssignment(this.target, newTarget);
159     }
160 
161     /** {@inheritDoc} */
162     public void setVersion(String newVersion) {
163         this.version = prepareForAssignment(this.version, newVersion);
164     }
165 
166     /** {@inheritDoc} */
167     public List<XMLObject> getOrderedChildren() {
168         ArrayList<XMLObject> children = new ArrayList<XMLObject>();
169         if (description != null) {
170             children.add(description);
171         }
172 
173         if (policyDefaults != null) {
174             children.add(policyDefaults);
175         }
176 
177         children.add(target);
178 
179         if (!choiceGroup.isEmpty()) {
180             children.addAll(choiceGroup);
181         }
182 
183         if (obligations != null) {
184             children.add(obligations);
185         }
186 
187         return children;
188     }
189 }