Example usage for javax.swing.tree TreeNode getClass

List of usage examples for javax.swing.tree TreeNode getClass

Introduction

In this page you can find the example usage for javax.swing.tree TreeNode getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:org.apache.accumulo.examples.wikisearch.parser.FieldIndexQueryReWriter.java

private RewriterTreeNode transformTreeNode(TreeNode node) throws ParseException {
    if (node.getType().equals(ASTEQNode.class) || node.getType().equals(ASTNENode.class)) {
        if (log.isDebugEnabled()) {
            log.debug("transformTreeNode, Equals Node");
        }// w ww.  j  ava2  s.co m

        Multimap<String, QueryTerm> terms = node.getTerms();
        for (String fName : terms.keySet()) {
            Collection<QueryTerm> values = terms.get(fName);

            for (QueryTerm t : values) {
                if (null == t || null == t.getValue()) {
                    continue;
                }
                String fValue = t.getValue().toString();
                fValue = fValue.replaceAll("'", "");
                boolean negated = t.getOperator().equals("!=");
                RewriterTreeNode child = new RewriterTreeNode(ParserTreeConstants.JJTEQNODE, fName, fValue,
                        negated);
                return child;
            }
        }
    }

    if (node.getType().equals(ASTERNode.class) || node.getType().equals(ASTNRNode.class)) {
        if (log.isDebugEnabled()) {
            log.debug("transformTreeNode, Regex Node");
        }

        Multimap<String, QueryTerm> terms = node.getTerms();
        for (String fName : terms.keySet()) {
            Collection<QueryTerm> values = terms.get(fName);
            for (QueryTerm t : values) {
                if (null == t || null == t.getValue()) {
                    continue;
                }
                String fValue = t.getValue().toString();
                fValue = fValue.replaceAll("'", "");
                boolean negated = node.getType().equals(ASTNRNode.class);
                RewriterTreeNode child = new RewriterTreeNode(ParserTreeConstants.JJTERNODE, fName, fValue,
                        negated);
                return child;
            }
        }
    }

    if (node.getType().equals(ASTLTNode.class) || node.getType().equals(ASTLENode.class)
            || node.getType().equals(ASTGTNode.class) || node.getType().equals(ASTGENode.class)) {
        if (log.isDebugEnabled()) {
            log.debug("transformTreeNode, LT/LE/GT/GE node");
        }
        Multimap<String, QueryTerm> terms = node.getTerms();
        for (String fName : terms.keySet()) {
            Collection<QueryTerm> values = terms.get(fName);
            for (QueryTerm t : values) {
                if (null == t || null == t.getValue()) {
                    continue;
                }
                String fValue = t.getValue().toString();
                fValue = fValue.replaceAll("'", "").toLowerCase();
                boolean negated = false; // to be negated, must be child of Not, which is handled elsewhere.
                int mytype = JexlOperatorConstants.getJJTNodeType(t.getOperator());
                RewriterTreeNode child = new RewriterTreeNode(mytype, fName, fValue, negated);
                return child;
            }
        }
    }

    RewriterTreeNode returnNode = null;

    if (node.getType().equals(ASTAndNode.class) || node.getType().equals(ASTOrNode.class)) {
        int parentType = node.getType().equals(ASTAndNode.class) ? ParserTreeConstants.JJTANDNODE
                : ParserTreeConstants.JJTORNODE;
        if (log.isDebugEnabled()) {
            log.debug("transformTreeNode, AND/OR node: " + parentType);
        }
        if (node.isLeaf() || !node.getTerms().isEmpty()) {
            returnNode = new RewriterTreeNode(parentType);
            Multimap<String, QueryTerm> terms = node.getTerms();
            for (String fName : terms.keySet()) {
                Collection<QueryTerm> values = terms.get(fName);
                for (QueryTerm t : values) {
                    if (null == t || null == t.getValue()) {
                        continue;
                    }
                    String fValue = t.getValue().toString();
                    fValue = fValue.replaceAll("'", "");
                    boolean negated = t.getOperator().equals("!=");
                    int childType = JexlOperatorConstants.getJJTNodeType(t.getOperator());
                    RewriterTreeNode child = new RewriterTreeNode(childType, fName, fValue, negated);
                    if (log.isDebugEnabled()) {
                        log.debug("adding child node: " + child.getContents());
                    }
                    returnNode.add(child);
                }
            }
        } else {
            returnNode = new RewriterTreeNode(parentType);
        }
    } else if (node.getType().equals(ASTNotNode.class)) {
        if (log.isDebugEnabled()) {
            log.debug("transformTreeNode, NOT node");
        }
        if (node.isLeaf()) {
            // NOTE: this should be cleaned up a bit.
            Multimap<String, QueryTerm> terms = node.getTerms();
            for (String fName : terms.keySet()) {
                Collection<QueryTerm> values = terms.get(fName);
                for (QueryTerm t : values) {
                    if (null == t || null == t.getValue()) {
                        continue;
                    }
                    String fValue = t.getValue().toString();
                    fValue = fValue.replaceAll("'", "").toLowerCase();
                    boolean negated = !t.getOperator().equals("!=");
                    int mytype = JexlOperatorConstants.getJJTNodeType(t.getOperator());
                    return new RewriterTreeNode(mytype, fName, fValue, negated);
                }
            }
        } else {
            returnNode = new RewriterTreeNode(ParserTreeConstants.JJTNOTNODE);
        }
    } else if (node.getType().equals(ASTJexlScript.class)
            || node.getType().getSimpleName().equals("RootNode")) {

        if (log.isDebugEnabled()) {
            log.debug("transformTreeNode, ROOT/JexlScript node");
        }
        if (node.isLeaf()) {
            returnNode = new RewriterTreeNode(ParserTreeConstants.JJTJEXLSCRIPT);
            // NOTE: this should be cleaned up a bit.
            Multimap<String, QueryTerm> terms = node.getTerms();
            for (String fName : terms.keySet()) {
                Collection<QueryTerm> values = terms.get(fName);
                for (QueryTerm t : values) {
                    if (null == t || null == t.getValue()) {
                        continue;
                    }
                    String fValue = t.getValue().toString();
                    fValue = fValue.replaceAll("'", "");
                    boolean negated = t.getOperator().equals("!=");
                    int mytype = JexlOperatorConstants.getJJTNodeType(t.getOperator());
                    RewriterTreeNode child = new RewriterTreeNode(mytype, fName, fValue, negated);
                    returnNode.add(child);
                    return returnNode;
                }
            }
        } else {
            returnNode = new RewriterTreeNode(ParserTreeConstants.JJTJEXLSCRIPT);
        }
    } else {
        log.error("transformTreeNode,  Currently Unsupported Node type: " + node.getClass().getName() + " \t"
                + node.getType());
    }
    for (TreeNode child : node.getChildren()) {
        returnNode.add(transformTreeNode(child));
    }

    return returnNode;
}

From source file:org.geopublishing.geopublisher.AMLExporter.java

/**
 * Create a tree of <aml:group> and <aml:datapoolRef>
 * //  w ww  .  j av a  2  s . c  o  m
 * @param group
 *            The {@link Group} to start with
 * @throws AtlasFatalException
 */
private final Element exportGroup(final Document document, final Group group) throws AtlasFatalException {
    // LOGGER.debug("exportGroup " + group + " to AML");
    final Element element = document.createElementNS(AMLUtil.AMLURI, "group");

    // Store whether this is marked as the Help menu in an optional
    // attribute
    if (group.isHelpMenu()) {
        final String isHelpString = Boolean.valueOf(group.isHelpMenu()).toString();
        element.setAttribute("isHelpMenu", isHelpString);
    }

    // Store whether this is marked as the File menu in an optional
    // attribute
    if (group.isFileMenu()) {
        final String isFileString = Boolean.valueOf(group.isFileMenu()).toString();
        element.setAttribute("isFileMenu", isFileString);
    }

    // Creating a aml:name tag...
    element.appendChild(exportTranslation(document, "name", group.getTitle()));

    // Creating aml:desc tag
    element.appendChild(exportTranslation(document, "desc", group.getDesc()));

    // Creating optional aml:keywords tag
    if (!group.getKeywords().isEmpty())
        element.appendChild(exportTranslation(document, "keywords", group.getKeywords()));

    final Enumeration<TreeNode> children = group.children();
    while (children.hasMoreElements()) {
        final TreeNode nextElement = children.nextElement();
        if (nextElement instanceof Group) {
            final Group subGroup = (Group) nextElement;
            element.appendChild(exportGroup(document, subGroup));

        } else if (nextElement instanceof DpRef) {
            final DpRef mref = (DpRef) nextElement;
            element.appendChild(exportDatapoolRef(document, mref));

        } else if (nextElement instanceof MapRef) {
            final MapRef mref = (MapRef) nextElement;
            final Element datapoolRef = document.createElementNS(AMLUtil.AMLURI, "mapRef");
            datapoolRef.setAttribute("id", mref.getTargetId());
            element.appendChild(datapoolRef);

        } else {
            throw new AtlasFatalException("Can't export Group " + group + " because of an unknown TreeNode "
                    + nextElement + " of class " + nextElement.getClass().getSimpleName());
        }
    }
    return element;
}