View Javadoc

1   /*
2    * Copyright [2005] [University Corporation for Advanced Internet Development, Inc.]
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.opensaml.saml1.core.impl;
18  
19  import java.util.ArrayList;
20  import java.util.Collections;
21  import java.util.List;
22  
23  import javax.xml.namespace.QName;
24  
25  import org.joda.time.DateTime;
26  import org.opensaml.common.impl.AbstractSAMLObject;
27  import org.opensaml.common.xml.SAMLConstants;
28  import org.opensaml.saml1.core.AudienceRestrictionCondition;
29  import org.opensaml.saml1.core.Condition;
30  import org.opensaml.saml1.core.Conditions;
31  import org.opensaml.saml1.core.DoNotCacheCondition;
32  import org.opensaml.xml.XMLObject;
33  import org.opensaml.xml.util.IndexedXMLObjectChildrenList;
34  
35  /**
36   * This is a concrete implementation of the {@link org.opensaml.saml1.core.Conditions} interface.
37   */
38  public class ConditionsImpl extends AbstractSAMLObject implements Conditions {
39  
40      /** Value saved in the NotBefore attribute */
41      private DateTime notBefore;
42  
43      /** Value saved in the NotOnOrAfter attribute */
44      private DateTime notOnOrAfter;
45  
46      /** Set containing all the Conditions */
47      private final IndexedXMLObjectChildrenList<Condition> conditions;
48  
49      /**
50       * Constructor
51       * 
52       * @param namespaceURI the namespace the element is in
53       * @param elementLocalName the local name of the XML element this Object represents
54       * @param namespacePrefix the prefix for the given namespace
55       */
56      protected ConditionsImpl(String namespaceURI, String elementLocalName, String namespacePrefix) {
57          super(namespaceURI, elementLocalName, namespacePrefix);
58          conditions = new IndexedXMLObjectChildrenList<Condition>(this);
59      }
60  
61      /** {@inheritDoc} */
62      public DateTime getNotBefore() {
63          return notBefore;
64      }
65  
66      /** {@inheritDoc} */
67      public void setNotBefore(DateTime notBefore) {
68          this.notBefore = prepareForAssignment(this.notBefore, notBefore);
69      }
70  
71      /** {@inheritDoc} */
72      public DateTime getNotOnOrAfter() {
73          return notOnOrAfter;
74      }
75  
76      /** {@inheritDoc} */
77      public void setNotOnOrAfter(DateTime notOnOrAfter) {
78          this.notOnOrAfter = prepareForAssignment(this.notOnOrAfter, notOnOrAfter);
79      }
80  
81      /** {@inheritDoc} */
82      public List<Condition> getConditions() {
83          return conditions;
84      }
85  
86      /** {@inheritDoc} */
87      public List<Condition> getConditions(QName typeOrName) {
88          return conditions;
89      }
90  
91      /** {@inheritDoc} */
92      public List<AudienceRestrictionCondition> getAudienceRestrictionConditions() {
93          QName qname = new QName(SAMLConstants.SAML1_NS, AudienceRestrictionCondition.DEFAULT_ELEMENT_LOCAL_NAME);
94          return (List<AudienceRestrictionCondition>) conditions.subList(qname);
95      }
96  
97      /** {@inheritDoc} */
98      public List<DoNotCacheCondition> getDoNotCacheConditions() {
99          QName qname = new QName(SAMLConstants.SAML1_NS, DoNotCacheCondition.DEFAULT_ELEMENT_LOCAL_NAME);
100         return (List<DoNotCacheCondition>) conditions.subList(qname);
101     }
102 
103     /** {@inheritDoc} */
104     public List<XMLObject> getOrderedChildren() {
105         if (conditions.size() == 0) {
106             return null;
107         }
108         ArrayList<XMLObject> children = new ArrayList<XMLObject>();
109         children.addAll(conditions);
110         return Collections.unmodifiableList(children);
111     }
112 }