KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > xpath > impl > LocationStepImpl


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.xpath.impl;
21
22 import org.netbeans.modules.xml.xpath.LocationStep;
23 import org.netbeans.modules.xml.xpath.StepNodeTest;
24 import org.netbeans.modules.xml.xpath.StepNodeNameTest;
25 import org.netbeans.modules.xml.xpath.StepNodeTypeTest;
26 import org.netbeans.modules.xml.xpath.XPathExpression;
27 import org.netbeans.modules.xml.xpath.XPathPredicateExpression;
28 import org.netbeans.modules.xml.xpath.visitor.XPathVisitor;
29
30 /**
31  * Represents a location path step.
32  *
33  * @author Enrico Lelina
34  * @version $Revision: 1.4 $
35  */

36 public class LocationStepImpl extends XPathExpressionImpl implements LocationStep {
37     
38     /** The axis. */
39     private int mAxis;
40     
41     /** The node test. */
42     private StepNodeTest mNodeTest;
43
44     /** predicates */
45     private XPathPredicateExpression[] mPredicates = null;
46     
47     /** Constructor. */
48     public LocationStepImpl() {
49         this(0, null, null);
50     }
51
52
53     /**
54      * Constructor.
55      * @param axis the axis
56      * @param nodeTest the node test
57      */

58     public LocationStepImpl(int axis, StepNodeTest nodeTest, XPathPredicateExpression[] predicates) {
59         setAxis(axis);
60         setNodeTest(nodeTest);
61         setPredicates(predicates);
62     }
63     
64     
65     /**
66      * Gets the axis.
67      * @return the axis
68      */

69     public int getAxis() {
70         return mAxis;
71     }
72     
73     
74     /**
75      * Sets the axis.
76      * @param axis the axis
77      */

78     public void setAxis(int axis) {
79         mAxis = axis;
80     }
81                                           
82     /**
83      * Gets the node test.
84      * @return the node test
85      */

86     public StepNodeTest getNodeTest() {
87         return mNodeTest;
88     }
89     
90     
91     /**
92      * Sets the node test.
93      * @param nodeTest the node test
94      */

95     public void setNodeTest(StepNodeTest nodeTest) {
96         mNodeTest = nodeTest;
97     }
98     
99     /**
100      * Gets the Predicates
101      * @return the predicates
102      */

103     public XPathPredicateExpression[] getPredicates() {
104         return mPredicates;
105     }
106     
107     
108     /**
109      * Sets the Predicates
110      * @param predicates list of predicates
111      */

112     public void setPredicates(XPathPredicateExpression[] predicates) {
113         mPredicates = predicates;
114     }
115     
116     /**
117      * Gets the string representation.
118      * @return the string representation
119      */

120     public String JavaDoc getString() {
121         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
122         
123         if (LocationStep.AXIS_ATTRIBUTE == getAxis()) {
124             sb.append('@');
125         }
126         
127         StepNodeTest nodeTest = getNodeTest();
128         if (nodeTest instanceof StepNodeNameTest) {
129             sb.append(((StepNodeNameTest) nodeTest).getNodeName());
130         } else if (nodeTest instanceof StepNodeTypeTest) {
131             sb.append(((StepNodeTypeTest) nodeTest).getNodeTypeString());
132         }
133         
134         return sb.toString();
135     }
136
137
138     public void accept(XPathVisitor visitor) {
139         visitor.visit(this);
140     }
141     
142     
143 }
144
Popular Tags