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 org.opensaml.saml1.core.AssertionArtifact;
24  import org.opensaml.saml1.core.AssertionIDReference;
25  import org.opensaml.saml1.core.AttributeQuery;
26  import org.opensaml.saml1.core.AuthenticationQuery;
27  import org.opensaml.saml1.core.AuthorizationDecisionQuery;
28  import org.opensaml.saml1.core.Query;
29  import org.opensaml.saml1.core.Request;
30  import org.opensaml.saml1.core.SubjectQuery;
31  import org.opensaml.xml.XMLObject;
32  import org.opensaml.xml.util.XMLObjectChildrenList;
33  
34  /**
35   * Concrete implementation of {@link org.opensaml.saml1.core.Request}
36   */
37  public class RequestImpl extends RequestAbstractTypeImpl implements Request {
38  
39      /** Saves the query (one of Query, SubjectQuery, AuthenticationQuery, AttributeQuery, AuthorizationDecisionQuery */
40      private Query query;
41  
42      /** The List of AssertionIDReferences */
43      private final XMLObjectChildrenList<AssertionIDReference> assertionIDReferences;
44  
45      /** The List of AssertionArtifacts */
46      private final XMLObjectChildrenList<AssertionArtifact> assertionArtifacts;
47  
48      /**
49       * Constructor
50       * 
51       * @param namespaceURI the namespace the element is in
52       * @param elementLocalName the local name of the XML element this Object represents
53       * @param namespacePrefix the prefix for the given namespace
54       */
55      protected RequestImpl(String namespaceURI, String elementLocalName, String namespacePrefix) {
56          super(namespaceURI, elementLocalName, namespacePrefix);
57          assertionIDReferences = new XMLObjectChildrenList<AssertionIDReference>(this);
58          assertionArtifacts = new XMLObjectChildrenList<AssertionArtifact>(this);
59      }
60  
61      /** {@inheritDoc} */
62      public Query getQuery() {
63          return query;
64      }
65  
66      /** {@inheritDoc} */
67      public SubjectQuery getSubjectQuery() {
68          return (query instanceof SubjectQuery ? (SubjectQuery) query : null);
69      }
70  
71      /** {@inheritDoc} */
72      public AttributeQuery getAttributeQuery() {
73          return (query instanceof AttributeQuery ? (AttributeQuery) query : null);
74      }
75  
76      /** {@inheritDoc} */
77      public AuthenticationQuery getAuthenticationQuery() {
78          return (query instanceof AuthenticationQuery ? (AuthenticationQuery) query : null);
79      }
80  
81      /** {@inheritDoc} */
82      public AuthorizationDecisionQuery getAuthorizationDecisionQuery() {
83          return (query instanceof AuthorizationDecisionQuery ? (AuthorizationDecisionQuery) query : null);
84      }
85  
86      /** {@inheritDoc} */
87      public void setQuery(Query query) throws IllegalArgumentException {
88          this.query = prepareForAssignment(this.query, query);
89      }
90  
91      /** {@inheritDoc} */
92      public List<AssertionIDReference> getAssertionIDReferences() {
93          return assertionIDReferences;
94      }
95  
96      /** {@inheritDoc} */
97      public List<AssertionArtifact> getAssertionArtifacts() {
98          return assertionArtifacts;
99      }
100 
101     /** {@inheritDoc} */
102     public List<XMLObject> getOrderedChildren() {
103 
104         List<XMLObject> list = new ArrayList<XMLObject>();
105 
106         if (super.getOrderedChildren() != null) {
107             list.addAll(super.getOrderedChildren());
108         }
109         if (query != null) {
110             list.add(query);
111         }
112         if (assertionIDReferences.size() != 0) {
113             list.addAll(assertionIDReferences);
114         }
115         if (assertionArtifacts.size() != 0) {
116             list.addAll(assertionArtifacts);
117         }
118 
119         if (list.size() == 0) {
120             return null;
121         }
122 
123         return Collections.unmodifiableList(list);
124     }
125 }