View Javadoc

1   /*
2    * Copyright 2001-2004 The Apache Software Foundation.
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  package org.apache.neethi;
17  
18  import java.util.Iterator;
19  import java.util.List;
20  
21  import javax.xml.stream.XMLStreamException;
22  import javax.xml.stream.XMLStreamWriter;
23  
24  /** 
25   * All is a PolicyOperator that require all its PolicyComponents to be met.
26   */
27  public class All extends AbstractPolicyOperator {
28      
29      /**
30       * Adds an assertion to its PolicyComponent list.
31       * 
32       * @param assertion the assertion to be added.
33       */
34      public void addAssertion(Assertion assertion) {
35          addPolicyComponent(assertion);
36      }
37  
38      /**
39       * Returns a <tt>List</tt> of it's PolicyComponents.
40       * 
41       * @return a List of it's PolicyComponents
42       */
43      public List getAssertions() {
44          return policyComponents;
45      }
46  
47      
48      public void serialize(XMLStreamWriter writer) throws XMLStreamException {
49          String prefix = writer.getPrefix(Constants.URI_POLICY_NS);
50  
51          if (prefix == null) {
52              writer.writeStartElement(Constants.ATTR_WSP, Constants.ELEM_ALL, Constants.URI_POLICY_NS);
53              writer.writeNamespace(Constants.ATTR_WSP, Constants.URI_POLICY_NS);
54              writer.setPrefix(Constants.ATTR_WSP, Constants.URI_POLICY_NS);
55          } else {
56              writer.writeStartElement(Constants.URI_POLICY_NS, Constants.ELEM_ALL);
57          }
58  
59          PolicyComponent policyComponent;
60  
61          for (Iterator iterator = getPolicyComponents().iterator(); iterator
62                  .hasNext();) {
63              policyComponent = (PolicyComponent) iterator.next();
64              policyComponent.serialize(writer);
65          }
66  
67          writer.writeEndElement();
68      }
69  
70      /**
71       * Returns Constants.TYPE_ALL
72       */
73      public short getType() {
74          return Constants.TYPE_ALL;
75      }
76  }