Package org.apache.xmlbeans

Examples of org.apache.xmlbeans.XmlCursor$TokenType


    public static WebAppDocument convertToServletSchema(XmlObject xmlObject) throws XmlException {
        if (WebAppDocument.type.equals(xmlObject.schemaType())) {
            validateDD(xmlObject);
            return (WebAppDocument) xmlObject;
        }
        XmlCursor cursor = xmlObject.newCursor();
        try {
            cursor.toStartDoc();
            cursor.toFirstChild();
            if ("http://java.sun.com/xml/ns/j2ee".equals(cursor.getName().getNamespaceURI())) {
                XmlObject result = xmlObject.changeType(WebAppDocument.type);
                validateDD(result);
                return (WebAppDocument) result;
            }

            XmlDocumentProperties xmlDocumentProperties = cursor.documentProperties();
            String publicId = xmlDocumentProperties.getDoctypePublicId();
            if ("-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN".equals(publicId) ||
                    "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN".equals(publicId)) {
                XmlCursor moveable = xmlObject.newCursor();
                try {
                    moveable.toStartDoc();
                    moveable.toFirstChild();
                    String schemaLocationURL = "http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd";
                    String version = "2.4";
                    convertToSchema(cursor, J2EE_NAMESPACE, schemaLocationURL, version);
                    cursor.toStartDoc();
                    cursor.toChild(J2EE_NAMESPACE, "web-app");
                    cursor.toFirstChild();
                    convertToDescriptionGroup(cursor, moveable);
                    convertToJNDIEnvironmentRefsGroup(cursor, moveable);
                    cursor.push();
                    if (cursor.toNextSibling(TAGLIB)) {
                        cursor.toPrevSibling();
                        moveable.toCursor(cursor);
                        cursor.beginElement("jsp-config", J2EE_NAMESPACE);
                        while (moveable.toNextSibling(TAGLIB)) {
                            moveable.moveXml(cursor);
                        }
                    }
                    cursor.pop();
                    do {
                        String name = cursor.getName().getLocalPart();
                        if ("filter".equals(name) || "servlet".equals(name)) {
                            cursor.push();
                            cursor.toFirstChild();
                            convertToDescriptionGroup(cursor, moveable);
                            if (cursor.toNextSibling(J2EE_NAMESPACE, "init-param")) {
                                cursor.toFirstChild();
                                convertToDescriptionGroup(cursor, moveable);
                            }
                            cursor.pop();
                        }
                    } while (cursor.toNextSibling());
                } finally {
                    moveable.dispose();
                }
            }
        } finally {
            cursor.dispose();
        }
View Full Code Here


        return (WebAppDocument) xmlObject;
    }

    public static void convertToGeronimoSubSchemas(XmlCursor cursor) {
        cursor.toStartDoc();
        XmlCursor end = cursor.newCursor();
        try {
            while (cursor.hasNextToken()) {
                if (cursor.isStart()) {
                    String localName = cursor.getName().getLocalPart();
                    String namespace = (String) GERONIMO_SCHEMA_CONVERSIONS.get(localName);
                    if (namespace != null) {
                        convertElementToSchema(cursor, end, namespace);
                    }
                }
                cursor.toNextToken();
            }
        } finally {
            end.dispose();
        }
    }
View Full Code Here

            end.dispose();
        }
    }

    public static XmlObject fixGeronimoSchema(XmlObject rawPlan, String desiredElement, SchemaType desiredType) throws XmlException {
        XmlCursor cursor = rawPlan.newCursor();
        try {
            if (findNestedElement(cursor, desiredElement)) {
                cursor.push();
                convertToGeronimoSubSchemas(cursor);
                cursor.pop();
                XmlObject temp = cursor.getObject();

                XmlObject result = temp.changeType(desiredType);
                if (result == null || result.schemaType() != desiredType) {
                    result = temp.copy().changeType(desiredType);
                }
                validateDD(result);
                return result;
            } else {
                return null;
            }
        } finally {
            cursor.dispose();
        }
    }
View Full Code Here

            cursor.dispose();
        }
    }

    public static XmlObject getNestedObject(XmlObject xmlObject, String desiredElement) {
        XmlCursor cursor = xmlObject.newCursor();
        try {
            if (findNestedElement(cursor, desiredElement)) {
                XmlObject child = cursor.getObject();
                //The copy seems to be needed to make the type change work for some documents!
                return child.copy();
            }
        } finally {
            cursor.dispose();
        }
        throw new IllegalArgumentException("xmlobject did not have desired element: " + desiredElement + "/n" + xmlObject);
    }
View Full Code Here

        }
        return false;
    }

    public static XmlObject getNestedObjectAsType(XmlObject xmlObject, String desiredElement, SchemaType type) {
        XmlCursor cursor = xmlObject.newCursor();
        try {
            if (findNestedElement(cursor, desiredElement)) {
                XmlObject child = cursor.getObject();
                //The copy seems to be needed to make the type change work for some documents!
                XmlObject result = child.copy().changeType(type);
                assert result.schemaType() == type;
                return result;
            }
        } finally {
            cursor.dispose();
        }
        throw new IllegalArgumentException("xmlobject did not have desired element: " + desiredElement + "/n" + xmlObject);
    }
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

        XmlObject webPlan = new GenericToSpecificPlanConverter(GerJettyDocument.type.getDocumentElementName().getNamespaceURI(),
                JettyWebAppDocument.type.getDocumentElementName().getNamespaceURI(), "jetty").convertToSpecificPlan(rawPlan);
        File ConvertedPlan = new File(basedir, "src/test-resources/plans/plan4-converted.xml");
        assertTrue(ConvertedPlan.exists());
        XmlObject converted = XmlBeansUtil.parse(ConvertedPlan.toURL());
        XmlCursor c = converted.newCursor();
        SchemaConversionUtils.findNestedElement(c, "web-app");
        c.toFirstChild();
        ArrayList problems = new ArrayList();
        compareXmlObjects(webPlan, c, problems);
        assertEquals("problems: " + problems, 0, problems.size());
    }
View Full Code Here

        compareXmlObjects(webPlan, c, problems);
        assertEquals("problems: " + problems, 0, problems.size());
    }

    private boolean compareXmlObjects(XmlObject xmlObject, XmlCursor expected, List problems) {
        XmlCursor test = xmlObject.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;
            }
            String actualChars = test.getName().getLocalPart();
            String expectedChars = expected.getName().getLocalPart();
            if (!actualChars.equals(expectedChars)) {
                problems.add("Different elements at elementCount: " + elementCount + ", test: " + actualChars + ", expected: " + expectedChars);
                similar = false;
            }
            test.toNextToken();
            expected.toNextToken();
        }
        return similar;
    }
View Full Code Here

        }

        // load the openejb-jar.xml
        XmlObject object = null;
        if (geronimoOpenejb.isSetOpenejbJar()) {
            XmlCursor xmlCursor = geronimoOpenejb.getOpenejbJar().newCursor();
            xmlCursor.toFirstChild();
            object = xmlCursor.getObject();
        }
        String openejbJarXml = XmlUtil.loadOpenejbJarXml(object, moduleFile);
        OpenejbJar openejbJar = XmlUtil.unmarshal(OpenejbJar.class, openejbJarXml);
        if (openejbJar == null){
            openejbJar = new OpenejbJar();
View Full Code Here

TOP

Related Classes of org.apache.xmlbeans.XmlCursor$TokenType

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.