View Javadoc

1   /*
2   Copyright 2008 Members of the EGEE Collaboration.
3   Copyright 2008 University Corporation for Advanced Internet Development,
4   Inc.
5   
6   Licensed under the Apache License, Version 2.0 (the "License");
7   you may not use this file except in compliance with the License.
8   You may obtain a copy of the License at
9   
10      http://www.apache.org/licenses/LICENSE-2.0
11  
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the License is distributed on an "AS IS" BASIS,
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  See the License for the specific language governing permissions and
16  limitations under the License.
17   */
18  
19  package org.opensaml.xacml.profile.saml.impl;
20  
21  import java.util.ArrayList;
22  import java.util.Collections;
23  import java.util.List;
24  
25  import org.opensaml.saml2.core.impl.RequestAbstractTypeImpl;
26  import org.opensaml.xacml.ctx.RequestType;
27  import org.opensaml.xacml.policy.PolicySetType;
28  import org.opensaml.xacml.policy.PolicyType;
29  import org.opensaml.xacml.profile.saml.ReferencedPoliciesType;
30  import org.opensaml.xacml.profile.saml.XACMLAuthzDecisionQueryType;
31  import org.opensaml.xml.XMLObject;
32  import org.opensaml.xml.schema.XSBooleanValue;
33  import org.opensaml.xml.util.XMLObjectChildrenList;
34  
35  /** A concrete implementation of {@link XACMLAuthzDecisionQueryType}. */
36  public class XACMLAuthzDecisionQueryTypeImpl extends RequestAbstractTypeImpl implements XACMLAuthzDecisionQueryType {
37  
38      /** Policy children. */
39      private List<PolicyType> policies;
40  
41      /** PolicySet children. */
42      private List<PolicySetType> policySets;
43  
44      /** ReeferencedPolicies child. */
45      private ReferencedPoliciesType referencedPolicies;
46  
47      /** The xacml-context:Request. */
48      private RequestType request;
49  
50      /** InputContextOnly attribute value. Default = false. */
51      private XSBooleanValue inputContextOnly;
52  
53      /** ReturnContext attribute value.Default = false. */
54      private XSBooleanValue returnContext;
55  
56      /** CombinePolicies attribute value. Default = true. */
57      private XSBooleanValue combinePolicies;
58  
59      /**
60       * Constructor.
61       * 
62       * @param namespaceURI the namespace the element is in
63       * @param elementLocalName the local name of the XML element this Object represents
64       * @param namespacePrefix the prefix for the given namespace
65       */
66      protected XACMLAuthzDecisionQueryTypeImpl(String namespaceURI, String elementLocalName, String namespacePrefix) {
67          super(namespaceURI, elementLocalName, namespacePrefix);
68          setElementNamespacePrefix(namespacePrefix);
69          policies = new XMLObjectChildrenList<PolicyType>(this);
70          policySets = new XMLObjectChildrenList<PolicySetType>(this);
71      }
72  
73      /** {@inheritDoc} */
74      public XSBooleanValue getCombinePoliciesXSBooleanValue() {
75          return combinePolicies;
76      }
77  
78      /** {@inheritDoc} */
79      public XSBooleanValue getInputContextOnlyXSBooleanValue() {
80          return inputContextOnly;
81      }
82  
83      /** {@inheritDoc} */
84      public List<XMLObject> getOrderedChildren() {
85          ArrayList<XMLObject> children = new ArrayList<XMLObject>();
86  
87          if (super.getOrderedChildren() != null) {
88              children.addAll(super.getOrderedChildren());
89          }
90          if (request != null) {
91              children.add(request);
92          }
93  
94          if (!policies.isEmpty()) {
95              children.addAll(policies);
96          }
97  
98          if (!policySets.isEmpty()) {
99              children.addAll(policySets);
100         }
101 
102         if (referencedPolicies != null) {
103             children.add(referencedPolicies);
104         }
105 
106         return Collections.unmodifiableList(children);
107     }
108 
109     /** {@inheritDoc} */
110     public RequestType getRequest() {
111         return request;
112     }
113 
114     /** {@inheritDoc} */
115     public XSBooleanValue getReturnContextXSBooleanValue() {
116         return returnContext;
117     }
118 
119     /** {@inheritDoc} */
120     public Boolean isCombinePolicies() {
121         if (combinePolicies != null) {
122             return combinePolicies.getValue();
123         }
124 
125         return Boolean.TRUE;
126     }
127 
128     /** {@inheritDoc} */
129     public Boolean isInputContextOnly() {
130         if (inputContextOnly != null) {
131             return inputContextOnly.getValue();
132         }
133 
134         return Boolean.FALSE;
135     }
136 
137     /** {@inheritDoc} */
138     public Boolean isReturnContext() {
139         if (returnContext != null) {
140             return returnContext.getValue();
141         }
142 
143         return Boolean.FALSE;
144     }
145 
146     /** {@inheritDoc} */
147     public void setCombinePolicies(XSBooleanValue combinePolicies) {
148         this.combinePolicies = prepareForAssignment(this.combinePolicies, combinePolicies);
149     }
150 
151     /** {@inheritDoc} */
152     public void setCombinePolicies(Boolean combinePolicies) {
153         if (combinePolicies != null) {
154             this.combinePolicies = prepareForAssignment(this.combinePolicies,
155                     new XSBooleanValue(combinePolicies, false));
156         } else {
157             this.combinePolicies = prepareForAssignment(this.combinePolicies, null);
158         }
159 
160     }
161 
162     /** {@inheritDoc} */
163     public void setInputContextOnly(XSBooleanValue inputContextOnly) {
164         this.inputContextOnly = prepareForAssignment(this.inputContextOnly, inputContextOnly);
165     }
166 
167     /** {@inheritDoc} */
168     public void setInputContextOnly(Boolean inputContextOnly) {
169         if (inputContextOnly != null) {
170             this.inputContextOnly = prepareForAssignment(this.inputContextOnly, new XSBooleanValue(inputContextOnly,
171                     false));
172         } else {
173             this.inputContextOnly = prepareForAssignment(this.inputContextOnly, null);
174         }
175     }
176 
177     /** {@inheritDoc} */
178     public void setRequest(RequestType request) {
179         this.request = prepareForAssignment(this.request, request);
180     }
181 
182     /** {@inheritDoc} */
183     public void setReturnContext(XSBooleanValue returnContext) {
184         this.returnContext = prepareForAssignment(this.returnContext, returnContext);
185     }
186 
187     /** {@inheritDoc} */
188     public void setReturnContext(Boolean returnContext) {
189         if (returnContext != null) {
190             this.returnContext = prepareForAssignment(this.returnContext, new XSBooleanValue(returnContext, false));
191         } else {
192             this.returnContext = prepareForAssignment(this.returnContext, null);
193         }
194     }
195 
196     /** {@inheritDoc} */
197     public List<PolicyType> getPolicies() {
198         return policies;
199     }
200 
201     /** {@inheritDoc} */
202     public List<PolicySetType> getPolicySets() {
203         return policySets;
204     }
205 
206     /** {@inheritDoc} */
207     public ReferencedPoliciesType getReferencedPolicies() {
208         return referencedPolicies;
209     }
210 
211     /** {@inheritDoc} */
212     public void setReferencedPolicies(ReferencedPoliciesType policies) {
213         referencedPolicies = prepareForAssignment(referencedPolicies, policies);
214     }
215 }