View Javadoc

1   /*
2    * Copyright 2008 University Corporation for Advanced Internet Development, Inc.
3    * Copyright 2008 Members of the EGEE Collaboration.
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.Collections;
22  import java.util.List;
23  
24  import org.opensaml.xacml.policy.ConditionType;
25  import org.opensaml.xacml.policy.DescriptionType;
26  import org.opensaml.xacml.policy.EffectType;
27  import org.opensaml.xacml.policy.RuleType;
28  import org.opensaml.xacml.policy.TargetType;
29  import org.opensaml.xml.XMLObject;
30  import org.opensaml.xml.validation.AbstractValidatingXMLObject;
31  
32  /**
33   *Implementation for {@link RuleType}.
34   */
35  public class RuleTypeImpl extends AbstractValidatingXMLObject implements RuleType {
36  
37      /** Condition of the policy.*/
38      private ConditionType condition;
39      
40      /** The rule target.*/
41      private TargetType target;
42      
43      /**Dscription of the rule.*/
44      private DescriptionType description;
45      
46      /**Effect type of the rule.*/
47      private EffectType effectType;
48      
49      /**The id of the rule.*/
50      private String ruleId;
51          
52      /**
53       * Constructor.
54       * @param namespaceURI the namespace the element is in
55       * @param elementLocalName the local name of the XML element this Object represents
56       * @param namespacePrefix the prefix for the given namespace
57       */
58      protected RuleTypeImpl(String namespaceURI, String elementLocalName, String namespacePrefix){
59          super(namespaceURI,elementLocalName,namespacePrefix);
60      }
61      
62      /** {@inheritDoc} */
63      public ConditionType getCondition() {
64          return condition;
65      }
66  
67      /** {@inheritDoc} */
68      public DescriptionType getDescription() {
69          return description;
70      }
71  
72      /** {@inheritDoc} */
73      public EffectType getEffect() {
74          return effectType;
75      }
76  
77      /** {@inheritDoc} */
78      public String getRuleId() {
79          return ruleId;
80      }
81  
82      /** {@inheritDoc} */
83      public TargetType getTarget() {
84          return target;
85      }
86  
87      /** {@inheritDoc} */
88      public void setCondition(ConditionType newCondition) {
89         this.condition = prepareForAssignment(this.condition,newCondition);
90      }
91  
92      /** {@inheritDoc} */
93      public void setDescription(DescriptionType newDescription) {
94          this.description = prepareForAssignment(this.description,newDescription);
95      }
96  
97      /** {@inheritDoc} */
98      public void setEffect(EffectType type) {
99          this.effectType = prepareForAssignment(this.effectType,type);
100     }
101 
102     /** {@inheritDoc} */
103     public void setRuleId(String id) {
104         this.ruleId = prepareForAssignment(this.ruleId,id);
105     }
106 
107     /** {@inheritDoc} */
108     public void setTarget(TargetType newTarget) {
109        this.target = prepareForAssignment(this.target,newTarget);
110     }
111 
112     /** {@inheritDoc} */
113     public List<XMLObject> getOrderedChildren() {
114         
115         ArrayList<XMLObject> children = new ArrayList<XMLObject>();        
116         
117         if(description != null){
118             children.add(description);
119         }
120         if(target != null){
121             children.add(target);
122         }
123         if(condition != null){
124             children.add(condition);
125         }
126                 
127         return Collections.unmodifiableList(children);
128     }
129 }