001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.xml.xpath.impl;
043:
044: import org.netbeans.modules.xml.xpath.XPathCoreFunction;
045: import org.netbeans.modules.xml.xpath.function.core.visitor.XPathCoreFunctionVisitor;
046: import org.netbeans.modules.xml.xpath.visitor.XPathVisitor;
047:
048: /**
049: * Represents a core XPath function.
050: *
051: * @author Enrico Lelina
052: * @version
053: */
054: public class XPathCoreFunctionImpl extends XPathOperatorOrFunctionImpl
055: implements XPathCoreFunction {
056:
057: /** The function code. */
058: int mFunction;
059:
060: /**
061: * Constructor. Instantiates a new XPathCoreFunction with the given code.
062: * @param function the function code
063: */
064: public XPathCoreFunctionImpl(int function) {
065: super ();
066: setFunction(function);
067: }
068:
069: /**
070: * Gets the function code.
071: * @return the function code
072: */
073: public int getFunction() {
074: return mFunction;
075: }
076:
077: /**
078: * Sets the function code.
079: * @param function the function code
080: */
081: public void setFunction(int function) {
082: mFunction = function;
083: }
084:
085: /**
086: * Gets the name of the function.
087: * @return the function name or null if invalid
088: */
089: public String getName() {
090: int code = getFunction();
091:
092: switch (code) {
093: case XPathCoreFunction.FUNC_LAST:
094: return "last";
095: case XPathCoreFunction.FUNC_POSITION:
096: return "position";
097: case XPathCoreFunction.FUNC_COUNT:
098: return "count";
099: case XPathCoreFunction.FUNC_ID:
100: return "id";
101: case XPathCoreFunction.FUNC_LOCAL_NAME:
102: return "local-name";
103: case XPathCoreFunction.FUNC_NAMESPACE_URI:
104: return "namespace-uri";
105: case XPathCoreFunction.FUNC_NAME:
106: return "name";
107: case XPathCoreFunction.FUNC_STRING:
108: return "string";
109: case XPathCoreFunction.FUNC_CONCAT:
110: return "concat";
111: case XPathCoreFunction.FUNC_STARTS_WITH:
112: return "starts-with";
113: case XPathCoreFunction.FUNC_CONTAINS:
114: return "contains";
115: case XPathCoreFunction.FUNC_SUBSTRING_BEFORE:
116: return "substring-before";
117: case XPathCoreFunction.FUNC_SUBSTRING_AFTER:
118: return "substring-after";
119: case XPathCoreFunction.FUNC_SUBSTRING:
120: return "substring";
121: case XPathCoreFunction.FUNC_STRING_LENGTH:
122: return "string-length";
123: case XPathCoreFunction.FUNC_NORMALIZE_SPACE:
124: return "normalize-space";
125: case XPathCoreFunction.FUNC_TRANSLATE:
126: return "translate";
127: case XPathCoreFunction.FUNC_BOOLEAN:
128: return "boolean";
129: case XPathCoreFunction.FUNC_NOT:
130: return "not";
131: case XPathCoreFunction.FUNC_TRUE:
132: return "true";
133: case XPathCoreFunction.FUNC_FALSE:
134: return "false";
135: case XPathCoreFunction.FUNC_LANG:
136: return "lang";
137: case XPathCoreFunction.FUNC_NUMBER:
138: return "number";
139: case XPathCoreFunction.FUNC_SUM:
140: return "sum";
141: case XPathCoreFunction.FUNC_FLOOR:
142: return "floor";
143: case XPathCoreFunction.FUNC_CEILING:
144: return "ceiling";
145: case XPathCoreFunction.FUNC_ROUND:
146: return "round";
147: case XPathCoreFunction.FUNC_NULL:
148: return "null";
149: case XPathCoreFunction.FUNC_KEY:
150: return "key";
151: case XPathCoreFunction.FUNC_FORMAT_NUMBER:
152: return "format-number";
153: case XPathCoreFunction.FUNC_EXISTS:
154: return "exists";
155: }
156:
157: return null;
158: }
159:
160: /**
161: * Calls the visitor.
162: * @param visitor the visitor
163: */
164: public void accept(XPathVisitor visitor) {
165: visitor.visit(this );
166: }
167:
168: public void accept(XPathCoreFunctionVisitor visitor) {
169: //do nothing
170:
171: }
172:
173: }
|