Package com.volantis.mcs.eclipse.common.odom

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


        // see if the element has a standard element. If no standard
        // element exists then we don't have anything to restore.
        Element standardElement = findStandardElement(element);
        if (standardElement != null) {
            synchronized (parent) {
                ODOMElement restoreElement = null;
                // remove the listeners
                parent.removeChangeListener(parentListener,
                        ChangeQualifier.HIERARCHY);
                element.removeChangeListener(elementListener);
                // find the index of the managed element in the parents content
                // list
                int elementIndex = parent.getContent().indexOf(element);

                // get the content of the standard element. If it has not content
                // then the element originally did not exist.
                List standardChildren = standardElement.getChildren();
                if (!standardChildren.isEmpty()) {
                    // need to check that there is only one child
                    if (standardChildren.size() > 1) {
                        throw new IllegalStateException(
                                "The standard element has more than one child");
                    }
                    // get the element that will be restored
                    restoreElement =
                            (ODOMElement) standardChildren.get(0);

                    // Move all listeners from the current element to the
                    // restored element.
                    element.moveListeners(restoreElement);

                    // we need to detach this from the standard element
                    restoreElement.detach();
                    // updated the parent so that the restored element is
                    // restored to the correct index
                    parent.getContent().add(elementIndex, restoreElement);
                }
View Full Code Here


     * element will not have any content
     * @return a "standard" ODOMElement
     */
    private ODOMElement createStandardElement(DeviceODOMElement content) {
        // create the standard element
        ODOMElement standard = (ODOMElement) JDOM_FACTORY.element(
                DeviceRepositorySchemaConstants.STANDARD_ELEMENT_NAME,
                parent.getNamespace());
        if (content != null) {
            // Ensure that the element within the standard element does
            // not itself have a StandardElementHandler in order to avoid
            // recursive change handling. The standard handler will be set
            // on the contained element if it is restored (see restore()).
            content.setStandardElementHandler(null);
            standard.addContent(content);
        }
        return standard;
    }
View Full Code Here

     * is no standard element
     * @param root the root element. Can be null.
     * @return the standard element or null if one does not exist.
     */
    private ODOMElement findStandardElement(ODOMElement root) {
        ODOMElement standardElement = null;
        if (root != null) {
            List standardElements = root.getChildren(
                    DeviceRepositorySchemaConstants.STANDARD_ELEMENT_NAME,
                    root.getNamespace());
            int count = standardElements.size();
View Full Code Here

            String gridName = grandParent.getName();
            String rowName = LayoutSchemaType.getGridRowName(gridName);

            // Create and add the new rows to the grid.
            for (int newRow = 0; newRow < numNewRows; newRow++) {
                ODOMElement newRowElement = (ODOMElement)
                        FormatPrototype.factory.element(rowName);
                // Fill each row with an empty format.
                for (int col = 0; col < colCount; col++) {
                    Element empty = FormatPrototype.get(FormatType.EMPTY);
                    newRowElement.addContent(empty);
                    selectedElements.add(empty);
                }
                // Add the new row at the correct position.
                content.add(rowPos + newRow, newRowElement);
            }
View Full Code Here

     */
    public void override(DeviceODOMElement policy) {
        if(standardElementHandler!=null) {
            standardElementHandler.dispose();
            // Get the standard element - there should always be one here
            ODOMElement standardElement =
                    (ODOMElement) this.getChild(
                            DeviceRepositorySchemaConstants.STANDARD_ELEMENT_NAME,
                            getNamespace());


            DeviceODOMElement parent = (DeviceODOMElement) getParent();

            // Detach the current policy element
            detach();

            // Detach the standard element and add it to the end of
            // the new policy.
            standardElement.detach();
            policy.getChildren().add(standardElement);

            // Move the listeners from the current policy to the new.
            moveListeners(policy);

View Full Code Here

    /**
     * Test creation of a multi-step path where none of the path element steps
     * exist and where all but the last element step exists.
     */
    public void testCreateElementMultiStep() throws Exception {
        ODOMElement context = (ODOMElement) factory.element("root");
        ODOMXPath path = new ODOMXPath("a/b");

        // Test creation of whole path from empty context
        ODOMObservable newNode = path.create(context, factory);

View Full Code Here

    /**
     * Test creation of a multi-step path where none of the path element steps
     * exist and where all the element steps exist.
     */
    public void testCreateAttributeMultiStep() throws Exception {
        ODOMElement context = (ODOMElement) factory.element("root");
        ODOMXPath path = new ODOMXPath("a/@b");

        // Test creation of whole path from empty context
        ODOMObservable newNode = path.create(context, factory);

View Full Code Here

    /**
     * Test creation of a multi-step path where none of the path element steps
     * exist and where all the element steps exist.
     */
    public void testCreateTextMultiStep() throws Exception {
        ODOMElement context = (ODOMElement) factory.element("root");
        ODOMXPath path = new ODOMXPath("a/b/text()");

        // Test creation of whole path from empty context
        ODOMObservable newNode = path.create(context, factory);

View Full Code Here

        // This will demonstrate invalid application of an absolute path
        // (the context is not appropriate to the absolute path because its
        // name doesn't match the first step in the absolute path)
        try {
            ODOMElement cd = (ODOMElement) root.getChild("cd");
            path.create(cd, factory);

            fail("Should have received an XPathException");
        } catch (XPathException e) {
            // Expected condition
View Full Code Here

        // should have returned a ODOMElement
        assertEquals("should have returned a ODOMElement",
                     ODOMElement.class,
                     node.getClass());

        ODOMElement element = (ODOMElement) node;

        // check the name of the element
        assertEquals("element should be named 'newElement'",
                     "newElement",
                     element.getName());

        // check the namespaceURI of the element
        assertEquals("element bound to an unexpected namespace",
                     "http://www.w3.org/2001/XMLSchema",
                     element.getNamespaceURI());
    }
View Full Code Here

TOP

Related Classes of com.volantis.mcs.eclipse.common.odom.ODOMElement

Copyright © 2018 www.massapicom. 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.