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.opensaml.common.impl.AbstractSAMLObject;
26  import org.opensaml.common.xml.SAMLConstants;
27  import org.opensaml.saml1.core.Advice;
28  import org.opensaml.saml1.core.Assertion;
29  import org.opensaml.saml1.core.AssertionIDReference;
30  import org.opensaml.xml.XMLObject;
31  import org.opensaml.xml.util.IndexedXMLObjectChildrenList;
32  
33  /**
34   * Concrete Implementation of the {@link org.opensaml.saml1.core.Advice} Object
35   */
36  public class AdviceImpl extends AbstractSAMLObject implements Advice {
37  
38      /** Contains all the SAML objects we have added */
39      private final IndexedXMLObjectChildrenList<XMLObject> assertionChildren;
40      
41      /** "any" children */
42      private final IndexedXMLObjectChildrenList<XMLObject> unknownChildren;
43  
44      /**
45       * Constructor
46       * 
47       * @param namespaceURI the namespace the element is in
48       * @param elementLocalName the local name of the XML element this Object represents
49       * @param namespacePrefix the prefix for the given namespace
50       */
51      protected AdviceImpl(String namespaceURI, String elementLocalName, String namespacePrefix) {
52          super(namespaceURI, elementLocalName, namespacePrefix);
53          assertionChildren = new IndexedXMLObjectChildrenList<XMLObject>(this);
54          unknownChildren = new IndexedXMLObjectChildrenList<XMLObject>(this);
55      }
56      
57      /** {@inheritDoc} */
58      public List<AssertionIDReference> getAssertionIDReferences() {
59          //
60          // The cast in the line below is unsafe. (it's checking against the erasure of l - which is List.
61          // We are, howeverever guaranteed by sublist that although l is 'just' a List it
62          // will only contain <AssertionIDReferences> explicit code in IndexedXMLObjectChildrenList$ListView.indexCheck
63          // helps us be sure.
64  
65          QName assertionIDRefQName = new QName(SAMLConstants.SAML1_NS, AssertionIDReference.DEFAULT_ELEMENT_LOCAL_NAME);
66          return (List<AssertionIDReference>) assertionChildren.subList(assertionIDRefQName);
67      }
68  
69      /** {@inheritDoc} */
70      public List<Assertion> getAssertions() {
71          // See Comment for getAssertionIDReference as to why this unsafe casting is OK
72          QName assertionQname = new QName(SAMLConstants.SAML1_NS, Assertion.DEFAULT_ELEMENT_LOCAL_NAME);
73          return (List<Assertion>) assertionChildren.subList(assertionQname);
74      }
75      
76      /**
77       * {@inheritDoc}
78       */
79      public List<XMLObject> getUnknownXMLObjects() {
80          return unknownChildren;
81      }
82      
83      /** {@inheritDoc} */
84      public List<XMLObject> getUnknownXMLObjects(QName typeOrName) {
85          return (List<XMLObject>) unknownChildren.subList(typeOrName);
86      }
87  
88      /** {@inheritDoc} */
89      public List<XMLObject> getOrderedChildren() {
90          ArrayList<XMLObject> children = new ArrayList<XMLObject>();
91          
92          children.addAll(assertionChildren);
93          children.addAll(unknownChildren);
94          
95          return Collections.unmodifiableList(children);
96      }
97  }