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.saml2.metadata.impl;
18  
19  import java.util.ArrayList;
20  import java.util.Collections;
21  import java.util.List;
22  
23  import org.joda.time.DateTime;
24  import org.opensaml.common.SAMLObject;
25  import org.opensaml.common.impl.AbstractSignableSAMLObject;
26  import org.opensaml.saml2.common.Extensions;
27  import org.opensaml.saml2.metadata.EntitiesDescriptor;
28  import org.opensaml.saml2.metadata.EntityDescriptor;
29  import org.opensaml.xml.XMLObject;
30  import org.opensaml.xml.util.IndexedXMLObjectChildrenList;
31  
32  /**
33   * Concrete implementation of {@link org.opensaml.saml2.metadata.EntitiesDescriptor}.
34   */
35  public class EntitiesDescriptorImpl extends AbstractSignableSAMLObject implements EntitiesDescriptor {
36  
37      /** Name of this descriptor group. */
38      private String name;
39  
40      /** ID attribute. */
41      private String id;
42  
43      /** validUntil attribute. */
44      private DateTime validUntil;
45  
46      /** cacheDurection attribute. */
47      private Long cacheDuration;
48  
49      /** Extensions child. */
50      private Extensions extensions;
51  
52      /** Ordered set of child Entity/Entities Descriptors. */
53      private final IndexedXMLObjectChildrenList<SAMLObject> orderedDescriptors;
54  
55      /**
56       * Constructor.
57       * 
58       * @param namespaceURI the namespace the element is in
59       * @param elementLocalName the local name of the XML element this Object represents
60       * @param namespacePrefix the prefix for the given namespace
61       */
62      protected EntitiesDescriptorImpl(String namespaceURI, String elementLocalName, String namespacePrefix) {
63          super(namespaceURI, elementLocalName, namespacePrefix);
64          orderedDescriptors = new IndexedXMLObjectChildrenList<SAMLObject>(this);
65      }
66  
67      /** {@inheritDoc} */
68      public String getName() {
69          return name;
70      }
71  
72      /** {@inheritDoc} */
73      public void setName(String newName) {
74          this.name = prepareForAssignment(this.name, newName);
75      }
76  
77      /** {@inheritDoc} */
78      public String getID() {
79          return id;
80      }
81  
82      /** {@inheritDoc} */
83      public void setID(String newID) {
84          String oldID = this.id;
85          this.id = prepareForAssignment(this.id, newID);
86          registerOwnID(oldID, this.id);
87      }
88  
89      /** {@inheritDoc} */
90      public boolean isValid() {
91          if (null == validUntil) {
92              return true;
93          }
94          
95          DateTime now = new DateTime();
96          return now.isBefore(validUntil);
97      }
98  
99      /** {@inheritDoc} */
100     public DateTime getValidUntil() {
101         return validUntil;
102     }
103 
104     /** {@inheritDoc} */
105     public void setValidUntil(DateTime newValidUntil) {
106         validUntil = prepareForAssignment(validUntil, newValidUntil);
107     }
108 
109     /** {@inheritDoc} */
110     public Long getCacheDuration() {
111         return cacheDuration;
112     }
113 
114     /** {@inheritDoc} */
115     public void setCacheDuration(Long duration) {
116         cacheDuration = prepareForAssignment(cacheDuration, duration);
117     }
118 
119     /** {@inheritDoc} */
120     public Extensions getExtensions() {
121         return extensions;
122     }
123 
124     /** {@inheritDoc} */
125     public void setExtensions(Extensions newExtensions) {
126         extensions = prepareForAssignment(extensions, newExtensions);
127     }
128 
129     /** {@inheritDoc} */
130     public List<EntitiesDescriptor> getEntitiesDescriptors() {
131         return (List<EntitiesDescriptor>) orderedDescriptors.subList(EntitiesDescriptor.ELEMENT_QNAME);
132     }
133 
134     /** {@inheritDoc} */
135     public List<EntityDescriptor> getEntityDescriptors() {
136         return (List<EntityDescriptor>) orderedDescriptors.subList(EntityDescriptor.ELEMENT_QNAME);
137     }
138     
139     /** {@inheritDoc} */
140     public String getSignatureReferenceID(){
141         return id;
142     }
143 
144     /** {@inheritDoc} */
145     public List<XMLObject> getOrderedChildren() {
146         ArrayList<XMLObject> children = new ArrayList<XMLObject>();
147 
148         if(getSignature() != null){
149             children.add(getSignature());
150         }
151         
152         children.add(getExtensions());
153         children.addAll(orderedDescriptors);
154 
155         return Collections.unmodifiableList(children);
156     }
157 }