01: /*
02: * The contents of this file are subject to the terms of the Common Development
03: * and Distribution License (the License). You may not use this file except in
04: * compliance with the License.
05: *
06: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
07: * or http://www.netbeans.org/cddl.txt.
08: *
09: * 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.ext;
21:
22: import java.util.HashMap;
23: import org.netbeans.modules.xml.xpath.ext.metadata.OperationMetadata;
24: import org.netbeans.modules.xml.xpath.ext.metadata.impl.OperationMetadataImpl.AdditionOperationMetadata;
25: import org.netbeans.modules.xml.xpath.ext.metadata.impl.OperationMetadataImpl.AndOperationMetadata;
26: import org.netbeans.modules.xml.xpath.ext.metadata.impl.OperationMetadataImpl.DivOperationMetadata;
27: import org.netbeans.modules.xml.xpath.ext.metadata.impl.OperationMetadataImpl.EqualOperationMetadata;
28: import org.netbeans.modules.xml.xpath.ext.metadata.impl.OperationMetadataImpl.GEOperationMetadata;
29: import org.netbeans.modules.xml.xpath.ext.metadata.impl.OperationMetadataImpl.GTOperationMetadata;
30: import org.netbeans.modules.xml.xpath.ext.metadata.impl.OperationMetadataImpl.LEOperationMetadata;
31: import org.netbeans.modules.xml.xpath.ext.metadata.impl.OperationMetadataImpl.LTOperationMetadata;
32: import org.netbeans.modules.xml.xpath.ext.metadata.impl.OperationMetadataImpl.ModOperationMetadata;
33: import org.netbeans.modules.xml.xpath.ext.metadata.impl.OperationMetadataImpl.MultOperationMetadata;
34: import org.netbeans.modules.xml.xpath.ext.metadata.impl.OperationMetadataImpl.NegativeOperationMetadata;
35: import org.netbeans.modules.xml.xpath.ext.metadata.impl.OperationMetadataImpl.NotEqualOperationMetadata;
36: import org.netbeans.modules.xml.xpath.ext.metadata.impl.OperationMetadataImpl.OrOperationMetadata;
37: import org.netbeans.modules.xml.xpath.ext.metadata.impl.OperationMetadataImpl.SubtractionOperationMetadata;
38: import org.netbeans.modules.xml.xpath.ext.metadata.impl.OperationMetadataImpl.UnionOperationMetadata;
39:
40: /**
41: * Types of the core XPath operations.
42: *
43: * @author Enrico Lelina
44: * @version
45: */
46: public enum CoreOperationType {
47:
48: OP_SUM(new AdditionOperationMetadata()), // Operator code: sum
49: OP_MINUS(new SubtractionOperationMetadata()), // Operator code: minus
50: OP_MULT(new MultOperationMetadata()), // Operator code: multiplication
51: OP_DIV(new DivOperationMetadata()), // Operator code: division
52: OP_MOD(new ModOperationMetadata()), // Operator code: mod
53: OP_NEGATIVE(new NegativeOperationMetadata()), // Operator code: negative/unary minus
54: OP_AND(new AndOperationMetadata()), // Operator code: and
55: OP_OR(new OrOperationMetadata()), // Operator code: or
56: OP_EQ(new EqualOperationMetadata()), // Operator code: equal
57: OP_NE(new NotEqualOperationMetadata()), // Operator code: not equal
58: OP_LT(new LTOperationMetadata()), // Operator code: less than
59: OP_LE(new LEOperationMetadata()), // Operator code: less than or equal
60: OP_GT(new GTOperationMetadata()), // Operator code: greater than
61: OP_GE(new GEOperationMetadata()), // Operator code: greater than or equal
62: OP_UNION(new UnionOperationMetadata()); // Operator code: union "|"
63:
64: private OperationMetadata myMetadata;
65:
66: private CoreOperationType(OperationMetadata metadata) {
67: myMetadata = metadata;
68: }
69:
70: public OperationMetadata getMetadata() {
71: return myMetadata;
72: }
73:
74: //==========================================================================
75:
76: private static HashMap<String, CoreOperationType> sNameTypeMap;
77:
78: public static synchronized CoreOperationType getTypeByName(
79: String operName) {
80: if (sNameTypeMap == null) {
81: sNameTypeMap = new HashMap<String, CoreOperationType>();
82: //
83: for (CoreOperationType type : CoreOperationType.values()) {
84: String typeName = type.getMetadata().getName();
85: sNameTypeMap.put(typeName, type);
86: }
87: }
88: //
89: return sNameTypeMap.get(operName);
90: }
91: }
|