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.policy.impl;
20  
21  import org.opensaml.common.impl.AbstractSAMLObjectUnmarshaller;
22  import org.opensaml.xacml.policy.AttributeAssignmentType;
23  import org.opensaml.xacml.policy.EffectType;
24  import org.opensaml.xacml.policy.ObligationType;
25  import org.opensaml.xml.XMLObject;
26  import org.opensaml.xml.io.UnmarshallingException;
27  import org.w3c.dom.Attr;
28  
29  /** UnMarshaller for {@link org.opensaml.xacml.policy.ObligationType}. */
30  public class ObligationTypeUnmarshaller extends AbstractSAMLObjectUnmarshaller {
31  
32      /** {@inheritDoc} */
33      protected void processChildElement(XMLObject parentObject, XMLObject childObject) throws UnmarshallingException {
34          ObligationType obligation = (ObligationType) parentObject;
35  
36          if (childObject instanceof AttributeAssignmentType) {
37              obligation.getAttributeAssignments().add((AttributeAssignmentType) childObject);
38          }
39      }
40  
41      /** {@inheritDoc} */
42      protected void processAttribute(XMLObject samlObject, Attr attribute) throws UnmarshallingException {
43  
44          ObligationType obligation = (ObligationType) samlObject;
45  
46          if (attribute.getLocalName().equals(ObligationType.OBLIGATION_ID_ATTRIB_NAME)) {
47              obligation.setObligationId(attribute.getValue());
48          }
49          if (attribute.getLocalName().equals(ObligationType.FULFILL_ON_ATTRIB_NAME)) {
50              if (attribute.getValue().equals(EffectType.Permit.toString())) {
51                  obligation.setFulfillOn(EffectType.Permit);
52              } else {
53                  obligation.setFulfillOn(EffectType.Deny);
54              }
55          }
56      }
57  }