Examples of ODOMObservable


Examples of com.volantis.mcs.eclipse.common.odom.ODOMObservable

        }

        // We now know that we are dealing with 'simple' XPaths. However,
        // we don't cater for functions besides the text() function, so if we
        // find a '(' we need to determine whether the function is text or not.
        ODOMObservable odomObservable = null;
        StringTokenizer tokenizer = new StringTokenizer(xpathStr, XPATH_DELIM);

        // Create an XPath relative to the parent (tracked during path
        // traversal). For example, with a context of 'a' and an XPath of
        // 'b/c/d' the parent and relative XPath will change as follows for
        // each token found:
        //
        // Parent XPath  Token
        // ------ -----  -----
        // a      b      b
        // a/b    c      c
        // a/b/c  d      d
        Element parent = context;
        XPath xpath;
        String xPathToken;

        while (tokenizer.hasMoreTokens()) {
            xPathToken = tokenizer.nextToken();
            // @todo pass the namespaces on in a nicer way (e.g. have a protected constructor that takes the map and copies it)
            xpath = new XPath(xPathToken, this.getNamespacesString());

            // Check to see if the node or nodes already exist in the document.
            List nodes = xpath.selectNodes(parent);
            ODOMObservable node = null;
            if ((nodes == null) || (nodes.size() == 0)) {
                // Node wasn't found, so create one.
                ODOMObservable result = null;
                int predicateStart = xPathToken.indexOf(PREDICATE_START);

                // Handle a predicate on the current path step if needed
                if (predicateStart != -1) {
                    String predicate =
View Full Code Here

Examples of com.volantis.mcs.eclipse.common.odom.ODOMObservable

     *         ODOMElement) node.
     */
    private ODOMObservable createNode(final ODOMElement context,
                                      final ODOMFactory factory,
                                      String xPathToken) {
        ODOMObservable result = null;
        if (xPathToken.startsWith(ATTRIBUTE)) {
            // The token starts with '@' so create a new attribute and add
            // this attribute to the context.
            Attribute attribute = factory.attribute(xPathToken.substring(1),
                    "");
View Full Code Here

Examples of com.volantis.mcs.eclipse.common.odom.ODOMObservable

        if (context == null) {
            throw new IllegalArgumentException("Context may not be null.");
        }
        Object result = null;
        ODOMObservable node = selectSingleNode(context);
        if (node != null) {
            Element parent = null;
            if (node instanceof Element) {
                parent = node.getParent();
                result = ((Element) node).detach();
            } else if (node instanceof Attribute) {
                parent = node.getParent();
                result = ((Attribute) node).detach();
            } else if (node instanceof Text) {
                parent = node.getParent();
                result = ((Text) node).detach();
            } else {
                throw new XPathException("Unknown ODOMObservable node: " + node);
            }
            if ((result != null) && (parent != null)) {
                ODOMObservable removedParent = removeParents(context, parent);
                if (removedParent != null) {
                    result = removedParent;
                }
            }
        }
View Full Code Here

Examples of com.volantis.mcs.eclipse.common.odom.ODOMObservable

     * @param context the ODOMObservable context.
     * @param element  the actual element.
     * @return the top most removed node, or null if no element was removed.
     */
    private ODOMObservable removeParents(ODOMObservable context, Element element) {
        ODOMObservable result = null;
        if (element != null) {
            List parentAttributeList = element.getAttributes();

            // Consider deleting me if I don't have any attributes, children,
            // or content and I am not the context or root node.
            boolean haveAttributes = (parentAttributeList != null) &&
                    parentAttributeList.size() > 0;

            boolean haveContent = (element.getContent().size() > 0);

            if (!haveAttributes && !haveContent && (element != context) &&
                    !element.isRootElement()) {

                // OK to remove me - first get my parent.
                Element parent = element.getParent();
                result = (ODOMObservable) element.detach();

                // Now remove my parent's parents (if they may be removed).
                ODOMObservable deadAncestor = removeParents(context, parent);
                if (deadAncestor != null) {
                    result = deadAncestor;
                }
            }
        }
View Full Code Here

Examples of com.volantis.mcs.eclipse.common.odom.ODOMObservable

        for (int i = 0; i < changedNodesXPaths.size(); i++) {
            XPath xPath = (XPath) changedNodesXPaths.get(i);

            while (xPath != null) {
                ODOMObservable o = (ODOMObservable) xPath.selectSingleNode(
                        document);

                if (o != null) {
                    if (o instanceof ODOMElement) {
                        result.add(o);
                    } else {
                        result.add(o.getParent());
                    }
                    break; //exit while loop
                } else {
                    xPath = xPath.getParent();
                }
View Full Code Here

Examples of com.volantis.mcs.eclipse.common.odom.ODOMObservable

    // Helper method to create an entity in the current selection
    private void processCreate(
            ODOMElement context, ODOMXPath xpath) throws Exception {

        // Attempt the creation from the specified context
        final ODOMObservable created = xpath.create(context, odomFactory);
        Utils.print("\nCreate OK: " + xpath.getExternalForm());
        if (created == null) {
            throw new IllegalStateException("Nothing created with " + xpath);
        }
View Full Code Here

Examples of com.volantis.mcs.eclipse.common.odom.ODOMObservable

    // Helper method to delete an entity in the current selection
    private void processDelete(
            ODOMElement context, ODOMXPath xpath) throws Exception {

        // Delete from the specified context
        final ODOMObservable deleted = xpath.remove(context);
        Utils.print("\nDeleted OK: " + xpath.getExternalForm());
        if (deleted instanceof ODOMAttribute) {
            Utils.print("Attribute deleted: " + xpath.getExternalForm());
        } else if (deleted instanceof ODOMElement) {
            Utils.print("Element deleted: " + xpath.getExternalForm());
View Full Code Here

Examples of com.volantis.mcs.eclipse.common.odom.ODOMObservable

        }
        if (finds.size() != 1) {
            throw new IllegalStateException(
                    "Found " + finds.size() + " in " + xpath.getExternalForm());
        }
        final ODOMObservable found = (ODOMObservable)finds.get(0);
        Utils.print("\nFind OK: " + xpath.getExternalForm());
        return found;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.