KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > xpath > pattern > Axis


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.xpath.pattern;
30
31 import com.caucho.xpath.Env;
32 import com.caucho.xpath.ExprEnvironment;
33 import com.caucho.xpath.XPathException;
34
35 import org.w3c.dom.Document JavaDoc;
36 import org.w3c.dom.Node JavaDoc;
37
38 /**
39  * Represents any of the axis patterns, i.e. those patterns that
40  * select many nodes from a single node.
41  */

42 abstract class Axis extends AbstractPattern {
43   Axis(AbstractPattern parent)
44   {
45     super(parent);
46   }
47
48   /**
49    * Calculates the position of the node in its context.
50    *
51    * @param node the current node
52    * @param env the variable environment
53    * @param pattern the position pattern
54    *
55    * @return the node's position.
56    */

57   public int position(Node JavaDoc node, Env env, AbstractPattern pattern)
58     throws XPathException
59   {
60     return 1;
61   }
62
63   /**
64    * Counts the nodes within the axis matching the pattern.
65    *
66    * @param node the current node
67    * @param env the variable environment
68    * @param pattern the position pattern
69    *
70    * @return the count of the node list.
71    */

72   public int count(Node JavaDoc node, Env env, AbstractPattern pattern)
73     throws XPathException
74   {
75     return 1;
76   }
77
78   /**
79    * Creates a new node iterator.
80    *
81    * @param node the starting node
82    * @param env the variable environment
83    * @param match the axis match pattern
84    *
85    * @return the node iterator
86    */

87   public NodeIterator createNodeIterator(Node JavaDoc node, ExprEnvironment env,
88                                          AbstractPattern match)
89     throws XPathException
90   {
91     if (_parent == null)
92       return new AxisIterator(null, this, node, env, match);
93     else if (_parent instanceof FromRoot) {
94       if (node instanceof Document JavaDoc)
95         return new AxisIterator(null, this, node, env, match);
96       else if (node != null)
97         return new AxisIterator(null, this, node.getOwnerDocument(),
98                                 env, match);
99     }
100
101     NodeIterator parentIter;
102     parentIter = _parent.createNodeIterator(node, env, _parent.copyPosition());
103
104     return new AxisIterator(parentIter, this, null, env, match);
105   }
106
107   /**
108    * Returns the node itself for the axis.
109    */

110   public AbstractPattern copyAxis()
111   {
112     return this;
113   }
114
115   /**
116    * Returns null since the axis isn't part of the position pattern.
117    */

118   public AbstractPattern copyPosition()
119   {
120     return null;
121   }
122   
123   /**
124    * Returns true if the pattern selects a single node
125    */

126   boolean isSingleSelect()
127   {
128     return false;
129   }
130   
131   /**
132    * Returns true if the pattern is strictly ascending.
133    */

134   public boolean isStrictlyAscending()
135   {
136     return isSingleLevel();
137   }
138   
139   /**
140    * Returns true if the pattern's selector returns unique nodes.
141    */

142   public boolean isUnique()
143   {
144     return isStrictlyAscending();
145   }
146 }
147
Popular Tags