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.metadata.impl;
22  
23  import java.util.ArrayList;
24  import java.util.Collections;
25  import java.util.List;
26  
27  import org.joda.time.DateTime;
28  import org.opensaml.common.impl.AbstractSignableSAMLObject;
29  import org.opensaml.saml2.common.Extensions;
30  import org.opensaml.saml2.metadata.AffiliateMember;
31  import org.opensaml.saml2.metadata.AffiliationDescriptor;
32  import org.opensaml.saml2.metadata.KeyDescriptor;
33  import org.opensaml.xml.XMLObject;
34  import org.opensaml.xml.util.AttributeMap;
35  import org.opensaml.xml.util.XMLObjectChildrenList;
36  
37  /**
38   * Concrete implementation of {@link org.opensaml.saml2.metadata.AffiliationDescriptor}.
39   */
40  public class AffiliationDescriptorImpl extends AbstractSignableSAMLObject implements AffiliationDescriptor {
41  
42      /** ID of the owner of this affiliation */
43      private String ownerID;
44      
45      /** ID attribute*/
46      private String id;
47  
48      /** validUntil attribute */
49      private DateTime validUntil;
50  
51      /** cacheDurection attribute */
52      private Long cacheDuration;
53  
54      /** Extensions child */
55      private Extensions extensions;
56      
57      /** "anyAttribute" attributes */
58      private final AttributeMap unknownAttributes;
59  
60      /** Members of this affiliation */
61      private final XMLObjectChildrenList<AffiliateMember> members;
62  
63      /** Key descriptors for this role */
64      private final XMLObjectChildrenList<KeyDescriptor> keyDescriptors;
65  
66      /**
67       * Constructor
68       * 
69       * @param namespaceURI
70       * @param elementLocalName
71       * @param namespacePrefix
72       */
73      protected AffiliationDescriptorImpl(String namespaceURI, String elementLocalName, String namespacePrefix) {
74          super(namespaceURI, elementLocalName, namespacePrefix);
75          unknownAttributes = new AttributeMap(this);
76          members = new XMLObjectChildrenList<AffiliateMember>(this);
77          keyDescriptors = new XMLObjectChildrenList<KeyDescriptor>(this);
78      }
79  
80      /** {@inheritDoc} */
81      public String getOwnerID() {
82          return ownerID;
83      }
84  
85      /** {@inheritDoc} */
86      public void setOwnerID(String newOwnerID) {
87          if (newOwnerID != null && newOwnerID.length() > 1024) {
88              throw new IllegalArgumentException("Owner ID can not exceed 1024 characters in length");
89          }
90          ownerID = prepareForAssignment(ownerID, newOwnerID);
91      }
92      
93      public String getID() {
94          return id;
95      }
96      
97      public void setID(String newID) {
98          String oldID = this.id;
99          this.id = prepareForAssignment(this.id, newID);
100         registerOwnID(oldID, this.id);
101     }
102 
103     /** {@inheritDoc} */
104     public boolean isValid() {
105         return validUntil.isBeforeNow();
106     }
107 
108     /** {@inheritDoc} */
109     public DateTime getValidUntil() {
110         return validUntil;
111     }
112 
113     /** {@inheritDoc} */
114     public void setValidUntil(DateTime validUntil) {
115         this.validUntil = prepareForAssignment(this.validUntil, validUntil);
116     }
117 
118     /** {@inheritDoc} */
119     public Long getCacheDuration() {
120         return cacheDuration;
121     }
122 
123     /** {@inheritDoc} */
124     public void setCacheDuration(Long duration) {
125         cacheDuration = prepareForAssignment(cacheDuration, duration);
126     }
127 
128     /** {@inheritDoc} */
129     public Extensions getExtensions() {
130         return extensions;
131     }
132 
133     /** {@inheritDoc} */
134     public void setExtensions(Extensions extensions) throws IllegalArgumentException {
135         this.extensions = prepareForAssignment(this.extensions, extensions);
136     }
137 
138     /** {@inheritDoc} */
139     public List<AffiliateMember> getMembers() {
140         return members;
141     }
142 
143     /** {@inheritDoc} */
144     public List<KeyDescriptor> getKeyDescriptors() {
145         return keyDescriptors;
146     }
147     
148     /**
149      * {@inheritDoc}
150      */
151     public AttributeMap getUnknownAttributes() {
152         return unknownAttributes;
153     }
154     
155     /** {@inheritDoc} */
156     public String getSignatureReferenceID(){
157         return id;
158     }
159 
160     /** {@inheritDoc} */
161     public List<XMLObject> getOrderedChildren() {
162         ArrayList<XMLObject> children = new ArrayList<XMLObject>();
163 
164         if(getSignature() != null){
165             children.add(getSignature());
166         }
167         
168         children.add(getExtensions());
169 
170         children.addAll(getMembers());
171 
172         children.addAll(getKeyDescriptors());
173 
174         return Collections.unmodifiableList(children);
175     }
176 }