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: package org.netbeans.modules.sql.framework.model.impl;
042:
043: import java.util.ArrayList;
044: import java.util.Map;
045: import java.util.TreeMap;
046:
047: import org.w3c.dom.Element;
048: import org.w3c.dom.Node;
049: import org.w3c.dom.NodeList;
050:
051: import com.sun.sql.framework.exception.BaseException;
052:
053: /**
054: *
055: */
056: public class OperatorCategoryNodeX extends CommonNodeX
057: implements
058: org.netbeans.modules.sql.framework.ui.graph.IOperatorXmlInfoCategory {
059: private static final String TAG_OPERATOR = "operator";
060:
061: private Map operatorNameToNodeMap = new TreeMap(
062: String.CASE_INSENSITIVE_ORDER);
063:
064: public OperatorCategoryNodeX(Element catElem) {
065: super (catElem);
066: createOperators(catElem);
067: }
068:
069: private void createOperators(Element catElem) {
070: NodeList children = catElem.getChildNodes();
071: Node node = null;
072: Element element = null;
073: Object value = null;
074: for (int i = 0; i < children.getLength(); i++) {
075: node = children.item(i);
076: if (node.getNodeName().equals(TAG_OPERATOR)) {
077: element = (Element) node;
078: try {
079: OperatorNodeX opNode = new OperatorNodeX(element);
080: // For quick search of oOperatorNode based on operator name.
081: operatorNameToNodeMap.put(opNode.getName(), opNode);
082: } catch (BaseException ex) {
083:
084: }
085: } else if (node.getNodeName().equals(TAG_ATTRIBUTE)) {
086: element = (Element) node;
087: name = element.getAttribute(ATTR_NAME);
088: value = this .getAttributeValue(element);
089: this .attributes.put(name, value);
090: }
091: }
092: }
093:
094: /**
095: * Gets the operator list for this category
096: *
097: * @return operator list
098: */
099: public ArrayList getOperatorList() {
100: ArrayList list = new ArrayList();
101: list.addAll(this .operatorNameToNodeMap.values());
102: return list;
103: }
104:
105: /**
106: * Gets the IOperatorXmlInfo instance in this category, if any, corresponding to the
107: * given operator name.
108: *
109: * @param operatorName name of operator to locate
110: * @return IOperatorXmlInfo instance for <code>operatorName</code>, or null if it
111: * does not exist in this category
112: */
113: public org.netbeans.modules.sql.framework.ui.graph.IOperatorXmlInfo findOperatorXmlInfo(
114: String operatorName) {
115: return (org.netbeans.modules.sql.framework.ui.graph.IOperatorXmlInfo) operatorNameToNodeMap
116: .get(operatorName);
117: }
118: }
|