View Javadoc

1   /*
2    * Copyright 2009 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.ws.wspolicy.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.ws.wspolicy.AppliesTo;
26  import org.opensaml.ws.wspolicy.Policy;
27  import org.opensaml.ws.wspolicy.PolicyAttachment;
28  import org.opensaml.ws.wspolicy.PolicyReference;
29  import org.opensaml.xml.XMLObject;
30  import org.opensaml.xml.util.AttributeMap;
31  import org.opensaml.xml.util.IndexedXMLObjectChildrenList;
32  
33  /**
34   * PolicyAttachmentImpl.
35   */
36  public class PolicyAttachmentImpl extends AbstractWSPolicyObject implements PolicyAttachment {
37      
38      /** AppliesTo Child element. */
39      private AppliesTo appliesTo;
40      
41      /** Policy and PolicyReference children. */
42      private IndexedXMLObjectChildrenList<XMLObject> policiesAndReferences;
43      
44      /** Wildcard child elements. */
45      private IndexedXMLObjectChildrenList<XMLObject> unknownChildren;
46      
47      /** Wildcard attributes. */
48      private AttributeMap unknownAttributes;
49  
50      /**
51       * Constructor.
52       * 
53       * @param namespaceURI The namespace of the element
54       * @param elementLocalName The local name of the element
55       * @param namespacePrefix The namespace prefix of the element
56       */
57      public PolicyAttachmentImpl(String namespaceURI, String elementLocalName, String namespacePrefix) {
58          super(namespaceURI, elementLocalName, namespacePrefix);
59          policiesAndReferences = new IndexedXMLObjectChildrenList<XMLObject>(this);
60          unknownChildren = new IndexedXMLObjectChildrenList<XMLObject>(this);
61          unknownAttributes = new AttributeMap(this);
62      }
63  
64      /** {@inheritDoc} */
65      public AppliesTo getAppliesTo() {
66          return appliesTo;
67      }
68  
69      /** {@inheritDoc} */
70      public void setAppliesTo(AppliesTo newAppliesTo) {
71          appliesTo = prepareForAssignment(appliesTo, newAppliesTo);
72      }
73  
74      /** {@inheritDoc} */
75      public List<Policy> getPolicies() {
76          return (List<Policy>) policiesAndReferences.subList(Policy.ELEMENT_NAME);
77      }
78  
79      /** {@inheritDoc} */
80      public List<PolicyReference> getPolicyReferences() {
81          return (List<PolicyReference>) policiesAndReferences.subList(PolicyReference.ELEMENT_NAME);
82      }
83  
84      /** {@inheritDoc} */
85      public List<XMLObject> getUnknownXMLObjects() {
86          return unknownChildren;
87      }
88  
89      /** {@inheritDoc} */
90      public List<XMLObject> getUnknownXMLObjects(QName typeOrName) {
91          return (List<XMLObject>) unknownChildren.subList(typeOrName);
92      }
93  
94      /** {@inheritDoc} */
95      public AttributeMap getUnknownAttributes() {
96          return unknownAttributes;
97      }
98  
99      /** {@inheritDoc} */
100     public List<XMLObject> getOrderedChildren() {
101         ArrayList<XMLObject> children = new ArrayList<XMLObject>();
102         if (appliesTo != null) {
103             children.add(appliesTo);
104         }
105         children.addAll(policiesAndReferences);
106         children.addAll(unknownChildren);
107         return Collections.unmodifiableList(children);
108     }
109 
110 }