View Javadoc
1   /*
2    $Id$
3   
4    Copyright 2003 The Werken Company. All Rights Reserved.
5    
6   Redistribution and use in source and binary forms, with or without
7   modification, are permitted provided that the following conditions are
8   met:
9   
10    * Redistributions of source code must retain the above copyright
11      notice, this list of conditions and the following disclaimer.
12  
13    * Redistributions in binary form must reproduce the above copyright
14      notice, this list of conditions and the following disclaimer in the
15      documentation and/or other materials provided with the distribution.
16  
17    * Neither the name of the Jaxen Project nor the names of its
18      contributors may be used to endorse or promote products derived 
19      from this software without specific prior written permission.
20  
21  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22  IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23  TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
24  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
25  OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  
33   */
34  package org.jaxen.expr.iter;
35  
36  import java.util.Iterator;
37  
38  import org.jaxen.ContextSupport;
39  import org.jaxen.NamedAccessNavigator;
40  import org.jaxen.UnsupportedAxisException;
41  
42  /**
43   * Provide access to the XPath attribute axis.
44   * This axis does not include namespace declarations such as 
45   * <code>xmlns</code> and <code>xmlns:<i>prefix</i></code>.
46   * It does include attributes defaulted from the DTD.
47   * 
48   * @author Bob McWhirter
49   * @author James Strachan
50   * @author Stephen Colebourne
51   */
52  public class IterableAttributeAxis extends IterableAxis {
53      
54      private static final long serialVersionUID = 1L;
55      
56      /**
57       * Constructor.
58       * 
59       * @param value the axis value
60       */
61      public IterableAttributeAxis(int value) {
62          super(value);
63      }
64  
65      /**
66       * Gets an iterator for the attribute axis.
67       * 
68       * @param contextNode  the current context node to work from
69       * @param support  the additional context information
70       */
71      public Iterator iterator(Object contextNode, ContextSupport support) throws UnsupportedAxisException {
72          return support.getNavigator().getAttributeAxisIterator(contextNode);
73      }
74  
75      /**
76       * Gets the iterator for the attribute axis that supports named access.
77       * 
78       * @param contextNode  the current context node to work from
79       * @param support  the additional context information
80       * @param localName  the local name of the attributes to return
81       * @param namespacePrefix  the prefix of the namespace of the attributes to return
82       * @param namespaceURI  the uri of the namespace of the attributes to return
83       */
84      public Iterator namedAccessIterator(
85          Object contextNode,
86          ContextSupport support,
87          String localName,
88          String namespacePrefix,
89          String namespaceURI)
90              throws UnsupportedAxisException {
91                  
92          NamedAccessNavigator nav = (NamedAccessNavigator) support.getNavigator();
93          return nav.getAttributeAxisIterator(contextNode, localName, namespacePrefix, namespaceURI);
94      }
95  
96      /**
97       * Does this axis support named access?
98       * 
99       * @param support  the additional context information
100      * @return true if named access is supported. If not iterator() will be used.
101      */
102     public boolean supportsNamedAccess(ContextSupport support) {
103         return (support.getNavigator() instanceof NamedAccessNavigator);
104     }
105 
106 }