Package org.apache.xmlbeans

Examples of org.apache.xmlbeans.XmlCursor


    static ConnectorDocument convertToConnectorSchema(XmlObject xmlObject) throws XmlException {
        if (ConnectorDocument.type.equals(xmlObject.schemaType())) {
            XmlBeansUtil.validateDD(xmlObject);
            return (ConnectorDocument) xmlObject;
        }
        XmlCursor cursor = xmlObject.newCursor();
        XmlDocumentProperties xmlDocumentProperties = cursor.documentProperties();
        String publicId = xmlDocumentProperties.getDoctypePublicId();
        try {
            if ("-//Sun Microsystems, Inc.//DTD Connector 1.0//EN".equals(publicId)) {
                XmlCursor moveable = xmlObject.newCursor();
                try {
                    String schemaLocationURL = "http://java.sun.com/xml/ns/j2ee/connector_1_5.xsd";
                    String version = "1.5";
                    SchemaConversionUtils.convertToSchema(cursor, SchemaConversionUtils.J2EE_NAMESPACE, schemaLocationURL, version);
                    cursor.toStartDoc();
                    cursor.toChild(SchemaConversionUtils.J2EE_NAMESPACE, "connector");
                    cursor.toFirstChild();
                    SchemaConversionUtils.convertToDescriptionGroup(SchemaConversionUtils.J2EE_NAMESPACE, cursor, moveable);
                    cursor.toNextSibling(SchemaConversionUtils.J2EE_NAMESPACE, "spec-version");
                    cursor.removeXml();
                    cursor.toNextSibling(SchemaConversionUtils.J2EE_NAMESPACE, "version");
                    cursor.setName(RESOURCE_ADAPTER_VERSION);
                    cursor.toNextSibling(SchemaConversionUtils.J2EE_NAMESPACE, "resourceadapter");
                    moveable.toCursor(cursor);
                    cursor.toFirstChild();
                    cursor.beginElement("outbound-resourceadapter", SchemaConversionUtils.J2EE_NAMESPACE);
                    cursor.beginElement("connection-definition", SchemaConversionUtils.J2EE_NAMESPACE);
                    moveable.toChild(SchemaConversionUtils.J2EE_NAMESPACE, "managedconnectionfactory-class");
                    moveable.push();
                    //from moveable to cursor
                    moveable.moveXml(cursor);
                    while (moveable.toNextSibling(SchemaConversionUtils.J2EE_NAMESPACE, "config-property")) {
                        moveable.moveXml(cursor);
                    }
                    moveable.pop();
                    moveable.toNextSibling(SchemaConversionUtils.J2EE_NAMESPACE, "connectionfactory-interface");
                    moveable.moveXml(cursor);
                    moveable.toNextSibling(SchemaConversionUtils.J2EE_NAMESPACE, "connectionfactory-impl-class");
                    moveable.moveXml(cursor);
                    moveable.toNextSibling(SchemaConversionUtils.J2EE_NAMESPACE, "connection-interface");
                    moveable.moveXml(cursor);
                    moveable.toNextSibling(SchemaConversionUtils.J2EE_NAMESPACE, "connection-impl-class");
                    moveable.moveXml(cursor);
                    //get out of connection-definition element
                    cursor.toNextToken();
                    moveable.toNextSibling(SchemaConversionUtils.J2EE_NAMESPACE, "transaction-support");
                    moveable.moveXml(cursor);
                    while (moveable.toNextSibling(SchemaConversionUtils.J2EE_NAMESPACE, "authentication-mechanism")) {
                        moveable.moveXml(cursor);
                    }
                    moveable.toNextSibling(SchemaConversionUtils.J2EE_NAMESPACE, "reauthentication-support");
                    moveable.moveXml(cursor);
                } finally {
                    moveable.dispose();
                }

            }
        } finally {
            cursor.dispose();
View Full Code Here


                    }
                }
            }
        }
        // Copy the content into the XmlAttributeType
        XmlCursor loginCursor = lcDoc.newCursor();
        loginCursor.toFirstContentToken();
        XmlCursor destination = config.newCursor();
        destination.toNextToken();
        loginCursor.moveXml(destination);
        loginCursor.dispose();
        destination.dispose();
        config.setName("LoginModuleConfiguration");

        return doc;
    }
View Full Code Here

        } else if (plan instanceof XmlObject) {
            xmlObject = (XmlObject) plan;
        } else {
            return defaultNamespace;
        }
        XmlCursor cursor = xmlObject.newCursor();
        try {
            while (cursor.hasNextToken()){
                if (cursor.isStart()) {
                    return cursor.getName().getNamespaceURI();
                }
                cursor.toNextToken();
            }
        } finally {
            cursor.dispose();
        }
        throw new DeploymentException("Cannot find namespace in xmlObject: " + xmlObject.xmlText());
    }
View Full Code Here

            }
        }
    }

    private boolean compareXmlObjects(XmlObject xmlObject, XmlObject expectedObject, List problems) {
        XmlCursor test = xmlObject.newCursor();
        XmlCursor expected = expectedObject.newCursor();
        boolean similar = true;
        int elementCount = 0;
        while (toNextStartToken(test)) {
            elementCount++;
            if (!toNextStartToken(expected)) {
                problems.add("test longer than expected at element: " + elementCount);
                return false;
            }
            QName actualQName = test.getName();
            QName expectedQName = expected.getName();
            if (!actualQName.equals(expectedQName)) {
                problems.add("Different elements at elementCount: " + elementCount + ", test: " + actualQName + ", expected: " + expectedQName);
                similar = false;
            }
            test.toNextToken();
            expected.toNextToken();
        }
        if (toNextStartToken(expected)) {
            problems.add("test shorter that expected at element: " + elementCount);
            similar = false;
        }
View Full Code Here

        this.namespace = namespace;
        this.element = element;
    }

    public XmlObject convertToSpecificPlan(XmlObject plan) throws DeploymentException {
        XmlCursor rawCursor = plan.newCursor();
        try {
            if (SchemaConversionUtils.findNestedElement(rawCursor, "web-app")) {
                XmlCursor temp = rawCursor.newCursor();
                String namespace = temp.getName().getNamespaceURI();
                temp.dispose();
                if(!namespace.equals(GENERIC_NAMESPACE) && !namespace.equals(this.namespace) && !namespace.equals(OLD_GENERIC_NAMESPACE)) {
                    throw new DeploymentException("Cannot handle web plan with namespace "+namespace+" -- expecting "+GENERIC_NAMESPACE+" or "+this.namespace);
                }

                XmlObject webPlan = rawCursor.getObject().copy();

                XmlCursor cursor = webPlan.newCursor();
                XmlCursor end = cursor.newCursor();
                try {
                    cursor.push();
                    if (cursor.toChild(GENERIC_CONFIG_QNAME) || cursor.toChild(OLD_GENERIC_CONFIG_QNAME)) {
                        XmlCursor source = cursor.newCursor();
                        cursor.push();
                        cursor.toEndToken();
                        cursor.toNextToken();
                        try {
                            if (source.toChild(configNamespace, element)) {
                                source.copyXmlContents(cursor);
                            }

                        } finally {
                            source.dispose();
                        }
                        cursor.pop();
                        cursor.removeXml();
                    }
                    cursor.pop();
                    cursor.push();
                    while (cursor.hasNextToken()) {
                        if (cursor.isStart()) {
                            if (!SchemaConversionUtils.convertSingleElementToGeronimoSubSchemas(cursor, end)
                            && !this.namespace.equals(cursor.getName().getNamespaceURI())) {
                                cursor.setName(new QName(this.namespace, cursor.getName().getLocalPart()));
                            }
                        }
                        cursor.toNextToken();
                    }
                    //move security elements after refs

                    cursor.pop();
                    cursor.push();
                    if (cursor.toChild(this.namespace, "security-realm-name")) {
                        XmlCursor other = cursor.newCursor();
                        try {
                            other.toParent();
                            if (other.toChild(SYSTEM_NAMESPACE, "gbean")) {
                                other.toPrevToken();
                            } else {
                                other.toEndToken();
                                other.toPrevToken();
                            }
                            cursor.moveXml(other);
                            cursor.pop();
                            cursor.push();
                            if (cursor.toChild(SECURITY_QNAME)) {
                                cursor.moveXml(other);
                            }
                        } finally {
                            other.dispose();
                        }
                    }
                    cursor.pop();
                    return webPlan;
                } finally {
View Full Code Here

                    }
                }
                TTypes[] types = definitions.getTypesArray();
                for (int i = 0; i < types.length; i++) {
                    TTypes type = types[i];
                    XmlCursor typeCursor = type.newCursor();
                    try {
                        if (typeCursor.toChild(SCHEMA_QNAME)) {
                            do {
                                SchemaDocument.Schema schema = (SchemaDocument.Schema) typeCursor.getObject();
                                rewriteSchema(schema, contextURI, key);
                            } while (typeCursor.toNextSibling(SCHEMA_QNAME));
                        }
                    } finally {
                        typeCursor.dispose();
                    }
                }
                String docString = xmlObjectToString(doc);
                wsdlMap.put(key.toString(), docString);
            } else {
View Full Code Here

            }
            cursor.toNextToken();
        }
        cursor.pop();
        XmlCursor source = null;
        try {
        while (cursor.hasNextToken() && cursor.isLeftOf(end)) {
            if (cursor.isStart()) {
                String localPart = cursor.getName().getLocalPart();
                if (localPart.equals("realm")) {
                    if (source == null) {
                        source = cursor.newCursor();
                    } else {
                        source.toCursor(cursor);
                    }
                    cursor.push();
                    cursor.toEndToken();
                    cursor.toNextToken();
                        if (source.toChild(PRINCIPAL_QNAME)) {
                            do {
                                source.copyXml(cursor);
                            } while (source.toNextSibling(PRINCIPAL_QNAME));
                        }

                    cursor.pop();
                    cursor.removeXml();
                } else if (localPart.equals("default-principal")) {
                    cursor.removeAttribute(REALM_NAME_QNAME);
                }
            }
            cursor.toNextToken();
        }
        } finally {
            if (source != null) {
                source.dispose();
            }
        }
    }
View Full Code Here

    }



    private boolean compareXmlObjects(XmlObject xmlObject, XmlObject expectedObject, List problems) {
        XmlCursor test = xmlObject.newCursor();
        XmlCursor expected = expectedObject.newCursor();
        boolean similar = true;
        int elementCount = 0;
        while (toNextStartToken(test)) {
            elementCount++;
            if (!toNextStartToken(expected)) {
                problems.add("test longer than expected at element: " + elementCount);
                return false;
            }
            QName actualChars = test.getName();
            QName expectedChars = expected.getName();
            if (!actualChars.equals(expectedChars)) {
                problems.add("Different elements at elementCount: " + elementCount + ", test: " + actualChars + ", expected: " + expectedChars);
                similar = false;
            }
            test.toNextToken();
            expected.toNextToken();
        }
        if (toNextStartToken(expected)) {
            problems.add("test shorter that expected at element: " + elementCount);
            similar = false;
        }
View Full Code Here

        XmlOptions xmlOptions = XmlBeansUtil.createXmlOptions(errors);
        SchemaDocument parsed = SchemaDocument.Factory.parse(element, xmlOptions);
        if (errors.size() != 0) {
            throw new XmlException(errors.toArray().toString());
        }
        XmlCursor cursor = parsed.newCursor();
        try {
            cursor.toFirstContentToken();
            for (Iterator namespaces = namespaceMap.entrySet().iterator(); namespaces.hasNext();) {
                Map.Entry entry = (Map.Entry) namespaces.next();
                cursor.insertNamespace((String) entry.getKey(), (String) entry.getValue());
            }
        } finally {
            cursor.dispose();
        }
        return parsed;
    }
View Full Code Here

            TService service = services[i];
            TPort[] ports = service.getPortArray();
            for (int j = 0; j < ports.length; j++) {
                TPort port = ports[j];
                if (port.getName().trim().equals(portComponentName)) {
                    XmlCursor portCursor = port.newCursor();
                    try {
                        if (portCursor.toChild(ADDRESS_QNAME)) {
                            if (servletLocation == null) {
                                String original = portCursor.getAttributeText(LOCATION_QNAME);
                                URI originalURI = new URI(original);
                                servletLocation = originalURI.getPath();
                            }
                            portCursor.setAttributeText(LOCATION_QNAME, AxisWebServiceContainer.LOCATION_REPLACEMENT_TOKEN + servletLocation);
                            return servletLocation;
                        }
                    } catch (URISyntaxException e) {
                        throw new DeploymentException("Could not construct URI for ejb location in wsdl", e);
                    } finally {
                        portCursor.dispose();
                    }
                }
            }
        }
        throw new DeploymentException("No port found with name " + portComponentName + " expected at " + servletLocation);
View Full Code Here

TOP

Related Classes of org.apache.xmlbeans.XmlCursor

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.