KickJava   Java API By Example, From Geeks To Geeks.

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


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
23 import java.util.Iterator JavaDoc;
24
25 import org.netbeans.modules.xml.xpath.XPathCoreOperation;
26 import org.netbeans.modules.xml.xpath.visitor.XPathVisitable;
27 import org.netbeans.modules.xml.xpath.visitor.XPathVisitor;
28
29
30 /**
31  * Represents a core XPath operation.
32  *
33  * @author Enrico Lelina
34  * @version $Revision: 1.4 $
35  */

36 public class XPathCoreOperationImpl
37     extends XPathOperatorOrFunctionImpl
38     implements XPathCoreOperation {
39         
40     /** The operator code. */
41     int mOperator;
42     
43     
44     /**
45      * Constructor. Instantiates a new XPathCoreOperation with the given code.
46      * @param operator the operator code
47      */

48     public XPathCoreOperationImpl(int operator) {
49         super();
50         setOperator(operator);
51     }
52     
53     
54     /**
55      * Gets the operator code.
56      * @return the operator code
57      */

58     public int getOperator() {
59         return mOperator;
60     }
61     
62     
63     /**
64      * Sets the operator code.
65      * @param operator the operator code
66      */

67     public void setOperator(int operator) {
68         mOperator = operator;
69     }
70     
71     
72     /**
73      * Gets the name of the operator.
74      * @return the operator name
75      */

76     public String JavaDoc getName() {
77         int code = getOperator();
78
79         switch (code) {
80         case XPathCoreOperation.OP_SUM:
81             return "addition";
82         case XPathCoreOperation.OP_MINUS:
83             return "subtraction";
84         case XPathCoreOperation.OP_MULT:
85             return "multiplication";
86         case XPathCoreOperation.OP_DIV:
87             return "division";
88         case XPathCoreOperation.OP_MOD:
89             return "remainder";
90         case XPathCoreOperation.OP_NEGATIVE:
91             return "negative";
92         case XPathCoreOperation.OP_AND:
93             return "and";
94         case XPathCoreOperation.OP_OR:
95             return "or";
96         case XPathCoreOperation.OP_EQ:
97             return "equal";
98         case XPathCoreOperation.OP_NE:
99             return "not_equal";
100         case XPathCoreOperation.OP_LT:
101             return "lesser_than";
102         case XPathCoreOperation.OP_LE:
103             return "lesser_or_equal";
104         case XPathCoreOperation.OP_GT:
105             return "greater_than";
106         case XPathCoreOperation.OP_GE:
107             return "greater_or_equal";
108         }
109
110         return null;
111     }
112     
113     
114     /**
115      * Gets the operator sign.
116      * @return the operator sign
117      */

118     public String JavaDoc getSign() {
119         int code = getOperator();
120
121         switch (code) {
122         case XPathCoreOperation.OP_SUM:
123             return "+";
124         case XPathCoreOperation.OP_MINUS:
125             return "-";
126         case XPathCoreOperation.OP_MULT:
127             return "*";
128         case XPathCoreOperation.OP_DIV:
129             return "div";
130         case XPathCoreOperation.OP_MOD:
131             return "mod";
132         case XPathCoreOperation.OP_NEGATIVE:
133             return "-";
134         case XPathCoreOperation.OP_AND:
135             return "and";
136         case XPathCoreOperation.OP_OR:
137             return "or";
138         case XPathCoreOperation.OP_EQ:
139             return "=";
140         case XPathCoreOperation.OP_NE:
141             return "!=";
142         case XPathCoreOperation.OP_LT:
143             return "<";
144         case XPathCoreOperation.OP_LE:
145             return "<=";
146         case XPathCoreOperation.OP_GT:
147             return ">";
148         case XPathCoreOperation.OP_GE:
149             return ">=";
150         }
151
152         return null;
153     }
154
155     /**
156      * Calls the visitor.
157      * @param visitor the visitor
158      */

159     public void accept(XPathVisitor visitor) {
160         visitor.visit(this);
161     }
162 }
163
Popular Tags