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  /**
18   * 
19   */
20  
21  package org.opensaml.saml2.core.impl;
22  
23  import java.util.ArrayList;
24  import java.util.Collections;
25  import java.util.List;
26  
27  import javax.xml.namespace.QName;
28  
29  import org.joda.time.DateTime;
30  import org.opensaml.common.impl.AbstractSAMLObject;
31  import org.opensaml.common.xml.SAMLConstants;
32  import org.opensaml.saml2.core.AudienceRestriction;
33  import org.opensaml.saml2.core.Condition;
34  import org.opensaml.saml2.core.Conditions;
35  import org.opensaml.saml2.core.OneTimeUse;
36  import org.opensaml.saml2.core.ProxyRestriction;
37  import org.opensaml.xml.XMLObject;
38  import org.opensaml.xml.util.IndexedXMLObjectChildrenList;
39  
40  /**
41   * Concrete implementation of {@link org.opensaml.saml2.core.Conditions}.
42   */
43  public class ConditionsImpl extends AbstractSAMLObject implements Conditions {
44  
45      /** A Condition. */
46      private final IndexedXMLObjectChildrenList<Condition> conditions;
47  
48      /** Not Before conditions. */
49      private DateTime notBefore;
50  
51      /** Not On Or After conditions. */
52      private DateTime notOnOrAfter;
53  
54      /**
55       * Constructor.
56       * 
57       * @param namespaceURI the namespace the element is in
58       * @param elementLocalName the local name of the XML element this Object represents
59       * @param namespacePrefix the prefix for the given namespace
60       */
61      protected ConditionsImpl(String namespaceURI, String elementLocalName, String namespacePrefix) {
62          super(namespaceURI, elementLocalName, namespacePrefix);
63          conditions = new IndexedXMLObjectChildrenList<Condition>(this);
64      }
65  
66      /** {@inheritDoc} */
67      public List<Condition> getConditions() {
68          return conditions;
69      }
70  
71      /** {@inheritDoc} */
72      public List<AudienceRestriction> getAudienceRestrictions() {
73          QName conditionQName = new QName(SAMLConstants.SAML20_NS, AudienceRestriction.DEFAULT_ELEMENT_LOCAL_NAME,
74                  SAMLConstants.SAML20_PREFIX);
75          return (List<AudienceRestriction>) conditions.subList(conditionQName);
76      }
77  
78      /** {@inheritDoc} */
79      public OneTimeUse getOneTimeUse() {
80          QName conditionQName = new QName(SAMLConstants.SAML20_NS, OneTimeUse.DEFAULT_ELEMENT_LOCAL_NAME,
81                  SAMLConstants.SAML20_PREFIX);
82          List<OneTimeUse> list = (List<OneTimeUse>) conditions.subList(conditionQName);
83          if (list == null || list.size() == 0) {
84              return null;
85          } else {
86              return list.get(0);
87          }
88      }
89  
90      /** {@inheritDoc} */
91      public ProxyRestriction getProxyRestriction() {
92          QName conditionQName = new QName(SAMLConstants.SAML20_NS, ProxyRestriction.DEFAULT_ELEMENT_LOCAL_NAME,
93                  SAMLConstants.SAML20_PREFIX);
94          List<ProxyRestriction> list = (List<ProxyRestriction>) conditions.subList(conditionQName);
95          if (list == null || list.size() == 0) {
96              return null;
97          } else {
98              return list.get(0);
99          }
100     }
101 
102     /** {@inheritDoc} */
103     public DateTime getNotBefore() {
104         return notBefore;
105     }
106 
107     /** {@inheritDoc} */
108     public void setNotBefore(DateTime newNotBefore) {
109         this.notBefore = prepareForAssignment(this.notBefore, newNotBefore);
110     }
111 
112     /** {@inheritDoc} */
113     public DateTime getNotOnOrAfter() {
114         return notOnOrAfter;
115     }
116 
117     /** {@inheritDoc} */
118     public void setNotOnOrAfter(DateTime newNotOnOrAfter) {
119         this.notOnOrAfter = prepareForAssignment(this.notOnOrAfter, newNotOnOrAfter);
120     }
121 
122     /** {@inheritDoc} */
123     public List<XMLObject> getOrderedChildren() {
124         ArrayList<XMLObject> children = new ArrayList<XMLObject>();
125 
126         children.addAll(conditions);
127 
128         return Collections.unmodifiableList(children);
129     }
130 }