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 org.opensaml.xacml.XACMLConstants;
21  import org.opensaml.xacml.policy.CombinerParametersType;
22  import org.opensaml.xacml.policy.DefaultsType;
23  import org.opensaml.xacml.policy.DescriptionType;
24  import org.opensaml.xacml.policy.IdReferenceType;
25  import org.opensaml.xacml.policy.ObligationsType;
26  import org.opensaml.xacml.policy.PolicyCombinerParametersType;
27  import org.opensaml.xacml.policy.PolicySetCombinerParametersType;
28  import org.opensaml.xacml.policy.PolicySetType;
29  import org.opensaml.xacml.policy.PolicyType;
30  import org.opensaml.xacml.policy.TargetType;
31  import org.opensaml.xml.XMLObject;
32  import org.opensaml.xml.io.AbstractXMLObjectUnmarshaller;
33  import org.opensaml.xml.io.UnmarshallingException;
34  import org.w3c.dom.Attr;
35  
36  /** Unmarshaller for {@link PolicySetType} objects. */
37  public class PolicySetTypeUnmarshaller extends AbstractXMLObjectUnmarshaller {
38  
39      /** Constructor. */
40      public PolicySetTypeUnmarshaller() {
41          super(XACMLConstants.XACML20_NS, PolicySetType.DEFAULT_ELEMENT_LOCAL_NAME);
42      }
43  
44      /** {@inheritDoc} */
45      protected void processAttribute(XMLObject xmlObject, Attr attribute) throws UnmarshallingException {
46          PolicySetType policySet = (PolicySetType) xmlObject;
47  
48          if (attribute.getLocalName().equals(PolicySetType.POLICY_SET_ID_ATTRIB_NAME)) {
49              policySet.setPolicySetId(attribute.getValue());
50          } else if (attribute.getLocalName().equals(PolicySetType.VERSION_ATTRIB_NAME)) {
51              policySet.setVersion(attribute.getValue());
52          } else if (attribute.getLocalName().equals(PolicySetType.POLICY_COMBINING_ALG_ID_ATTRIB_NAME)) {
53              policySet.setPolicyCombiningAlgoId(attribute.getValue());
54          }
55      }
56  
57      /** {@inheritDoc} */
58      protected void processChildElement(XMLObject parentXMLObject, XMLObject childXMLObject)
59              throws UnmarshallingException {
60          PolicySetType policySet = (PolicySetType) parentXMLObject;
61  
62          if (childXMLObject instanceof DescriptionType) {
63              policySet.setDescription((DescriptionType) childXMLObject);
64          } else if (childXMLObject instanceof DefaultsType) {
65              policySet.setPolicySetDefaults((DefaultsType) childXMLObject);
66          } else if (childXMLObject instanceof TargetType){
67                  policySet.setTarget((TargetType) childXMLObject);
68          } else if (childXMLObject instanceof PolicySetType) {
69              policySet.getPolicySets().add((PolicySetType) childXMLObject);
70          } else if (childXMLObject instanceof PolicyType) {
71              policySet.getPolicies().add((PolicyType) childXMLObject);
72          } else if (childXMLObject.getElementQName().equals(IdReferenceType.POLICY_SET_ID_REFERENCE_ELEMENT_NAME)) {
73              policySet.getPolicySetIdReferences().add((IdReferenceType) childXMLObject);
74          } else if (childXMLObject.getElementQName().equals(IdReferenceType.POLICY_ID_REFERENCE_ELEMENT_NAME)) {
75              policySet.getPolicyIdReferences().add((IdReferenceType) childXMLObject);
76          } else if (childXMLObject.getElementQName().equals(CombinerParametersType.DEFAULT_ELEMENT_NAME)) {
77              policySet.getCombinerParameters().add((CombinerParametersType) childXMLObject);
78          } else if (childXMLObject.getElementQName().equals(PolicyCombinerParametersType.DEFAULT_ELEMENT_NAME)) {
79              policySet.getPolicyCombinerParameters().add((PolicyCombinerParametersType) childXMLObject);
80          } else if (childXMLObject.getElementQName().equals(PolicySetCombinerParametersType.DEFAULT_ELEMENT_NAME)) {
81              policySet.getPolicySetCombinerParameters().add((PolicySetCombinerParametersType) childXMLObject);
82          } else if (childXMLObject instanceof ObligationsType) {
83              policySet.setObligations((ObligationsType) childXMLObject);
84          }
85      }
86  
87      /** {@inheritDoc} */
88      protected void processElementContent(XMLObject xmlObject, String elementContent) {
89  
90      }
91  }