Hello,

I'm able to spend some time on this again.
I don't have permission to download the wsm-schema.jar.

Thanks.

Davanum Srinivas wrote:
Mark,

I've got the changes into CVS and got everything building with JDK1.4.
Please pull the latest code. You will need wsm-schema.jar from here
(http://ws.zones.apache.org/~dims/libs/wsm-schema.jar) in addition to
all the jars from xmlbeans 2.0.0. wsm-schema.jar is basically xmlbeans
output of various xsd's needed (build xml is in beehive wsm project).

Please try it and let me know. I will try to see if i can integrate
the sample into axis as well when i get a chance.

thanks,
dims

On 7/6/05, Mark Swanson <[EMAIL PROTECTED]> wrote:

Davanum Srinivas wrote:

sorry!!! - http://issues.apache.org/jira/browse/AXIS-1812

[EMAIL PROTECTED] xbeans]$ patch -p0 </tmp/axis.patch
(Stripping trailing CRs from patch.)
patching file XmlBeanSerializer.java
Hunk #1 FAILED at 21.
Hunk #2 FAILED at 50.
Hunk #3 FAILED at 99.
3 out of 3 hunks FAILED -- saving rejects to file XmlBeanSerializer.java.rej

I patched it by hand, and then found enum is being incorrectly used in
the Axis-1_2_1 sources:

compile:
   [depend] Deleted 0 out of date files in 0 seconds
    [javac] Compiling 708 source files to
/home/mswanson/downloads/java/axis-1_2_1/build/classes
    [javac]
/home/mswanson/downloads/java/axis-1_2_1/src/org/apache/axis/enum/Scope.java:17:
as of release 1.5, 'enum' is a keyword, and may not be used as an identifier
    [javac] (use -source 1.4 or lower to use 'enum' as an identifier)
    [javac] package org.apache.axis.enum;
    [javac]                         ^
    [javac]
/home/mswanson/downloads/java/axis-1_2_1/src/org/apache/axis/enum/Style.java:17:
as of release 1.5, 'enum' is a keyword, and may not be used as an identifier
    [javac] (use -source 1.4 or lower to use 'enum' as an identifier)
    [javac] package org.apache.axis.enum;
    [javac]                         ^
    [javac]
/home/mswanson/downloads/java/axis-1_2_1/src/org/apache/axis/enum/Use.java:17:
as of release 1.5, 'enum' is a keyword, and may not be used as an identifier
    [javac] (use -source 1.4 or lower to use 'enum' as an identifier)
    [javac] package org.apache.axis.enum;
    [javac]                         ^
    [javac]
/home/mswanson/downloads/java/axis-1_2_1/src/org/apache/axis/transport/http/QSMethodHandler.java:70:
as of release 1.5, 'enum' is a keyword, and may not be used as an identifier
    [javac] (use -source 1.4 or lower to use 'enum' as an identifier)
    [javac]         Enumeration enum = request.getParameterNames();
    [javac]                     ^
    [javac]
/home/mswanson/downloads/java/axis-1_2_1/src/org/apache/axis/transport/http/QSMethodHandler.java:72:
as of release 1.5, 'enum' is a keyword, and may not be used as an identifier
    [javac] (use -source 1.4 or lower to use 'enum' as an identifier)
    [javac]         while (enum.hasMoreElements()) {
    [javac]                ^
    [javac]
/home/mswanson/downloads/java/axis-1_2_1/src/org/apache/axis/transport/http/QSMethodHandler.java:73:
as of release 1.5, 'enum' is a keyword, and may not be used as an identifier
    [javac] (use -source 1.4 or lower to use 'enum' as an identifier)
    [javac]             String param = (String) enum.nextElement();
    [javac]                                     ^
    [javac] 6 errors

BUILD FAILED

Arg. I can't even do a test with Java 6 to see if the patch works or
not. I'm quite surprised to see this.
I don't have enough time left today and will have to pick this up next
Tuesday.

I'm pasting my hand-patched file in case someone wants to grab this ball
and roll with it before I get back.

Cheers.

/*
 * XmlBeanSerializer.java
 *
 * Copyright 2001-2004 The Apache Software Foundation.
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Original author: Jonathan Colwell
 */

package org.apache.axis.encoding.ser.xbeans;

import org.apache.axis.AxisFault;
import org.apache.axis.Constants;
import org.apache.axis.encoding.SerializationContext;
import org.apache.axis.encoding.Serializer;
import org.apache.axis.wsdl.fromJava.Types;
import org.apache.beehive.wsm.wsdl.Schema;
import org.apache.beehive.wsm.wsdl.Utilities;
import org.apache.xmlbeans.SchemaField;
import org.apache.xmlbeans.SchemaType;
import org.apache.xmlbeans.SchemaTypeLoader;
import org.apache.xmlbeans.XmlBeans;
import org.apache.xmlbeans.XmlCursor;
import org.apache.xmlbeans.XmlObject;
import org.apache.xmlbeans.XmlOptions;
import org.w3.x2001.xmlSchema.LocalElement;
import org.w3.x2001.xmlSchema.SchemaDocument;
import org.w3.x2001.xmlSchema.TopLevelComplexType;
import org.w3.x2001.xmlSchema.TopLevelElement;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.xml.sax.Attributes;
import org.xmlsoap.schemas.wsdl.DefinitionsDocument;
import org.xmlsoap.schemas.wsdl.TDefinitions;
import org.xmlsoap.schemas.wsdl.TTypes;

import javax.xml.namespace.QName;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Array;
import java.util.HashSet;
import java.util.Set;

/**
 * Class XmlBeanSerializer
 * @author Jonathan Colwell
 */
public class XmlBeanSerializer implements Serializer {

    /**
     * Serialize an element named name, with the indicated attributes
     * and value.
     *
     * @param name       is the element name
     * @param attributes are the attributes...serialize is free to add
more.
     * @param value      is the value
     * @param context    is the SerializationContext
     */
    public void serialize(QName name, Attributes attributes,
                          Object value, SerializationContext context)
            throws IOException {
        List<String> testL = new ArrayList<String>();
        if (!(value instanceof XmlObject)) {
            throw new IOException(((value != null) ?
                    value.getClass().getName()
                    : "null")
                    + " is not an "
                    + XmlObject.class.getName());
        } else {
            context.setWriteXMLType(null);
            context.startElement(name, attributes);
            XmlCursor xCur = ((XmlObject) value).newCursor();
            if (xCur.toFirstContentToken() == XmlCursor.TokenType.START) {
                do {
                    Node n = xCur.getDomNode();
                    if (n.getNodeType() == Node.ELEMENT_NODE) {
                        context.writeDOMElement((Element) n);
                    }
                } while (xCur.toNextSibling());
            }
            context.endElement();
        }
    }

    public String getMechanismType() {
        return Constants.AXIS_SAX;
    }

    /**
     * Return XML schema for the specified type, suitable for insertion
into the
     * &lt;types&gt; element of a WSDL document, or underneath an
     * &lt;element&gt; or &lt;attribute&gt; declaration.
     *
     * @param javaType
     *            the Java Class we're writing out schema for
     * @param types
     *            the Java2WSDL Types object which holds the context
for the
     *            WSDL being generated.
     * @return a type element containing a schema simpleType/complexType
     * @see org.apache.axis.wsdl.fromJava.Types
     */
    public Element writeSchema(Class javaType, Types types) throws
Exception {
        //if (XmlObject.class.isAssignableFrom(javaType)) {
        try {
            if (!XmlObject.class.isAssignableFrom(javaType)) {
                throw new RuntimeException(
                        "Invalid Object type is assigned to the
XMLBeanSerialization Type: "
                                + javaType.getCanonicalName());
            }
            SchemaType docType = XmlBeans.typeForClass(javaType);
            writeSchemaForDocType(docType, types);
            // assume that the writeSchemaForDocType wrote the schema
            // for the type and all the dependent types.
            return null;
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }

    /**
     * @param types
     * @param docType
     * @return
     * @throws Exception
     */
    private void writeSchemaForDocType(SchemaType docType, Types types)
            throws Exception {
        Schema mySchema = Utilities.findtSchemaDocument(docType);

        QName q = docType.getName();

        XmlObject typeNodeInWSDL = mySchema.getTypeNode(q);

        if (null == typeNodeInWSDL)
            throw new RuntimeException(
                    "Type for object not found in the assigned WSDL file. "
                            + docType.getName() + " schema in: "
                            + docType.getSourceName());
        //        insertDependentTypes(typeNodeInWSDL, types);
        Node n = typeNodeInWSDL.getDomNode();
        Document doc = types.createElement(

"element_to_get_document_useless_otherwise").getOwnerDocument();
        Element e = (Element) doc.importNode(n, true);
        try {
            types.writeSchemaElementDecl(q, e);
        } catch (AxisFault e1) {
            // this means the types was already in... fine!
            // TBD: make sure there are other types of exceptions are
at least
            // reported
        }
        Set<QName> dependentTypes = new HashSet<QName>();
        getAllDependentTypes(typeNodeInWSDL, dependentTypes);
        for (QName nxtType : dependentTypes) {
            Class nxtJavaType = null;
            // add the class if it is an xml bean
            if (null != (nxtJavaType = q2UserClass(nxtType))
                    && XmlObject.class.isAssignableFrom(nxtJavaType)) {
                writeSchema(nxtJavaType, types);
            }
        }
        return;
    }


    /**
     * @param nxtType
     * @return null for classes that are not found, or if they are
primitive types
     *     *
     */
    private Class q2UserClass(QName qname) {
        SchemaTypeLoader stl = XmlBeans.getContextTypeLoader();
        SchemaType st = stl.findType(qname);
        if (st == null) {
            SchemaField sf = stl.findElement(qname);
            if (sf != null)
                st = sf.getType();
        }

        if (st != null && !st.isBuiltinType())
            return st.getJavaClass();
        else
            return null; // for classes that are not found, or are build in

    }

    /**
     * @param nodeInWSDL
     * @param dependentTypes
     * @return
     *
     * Walk all the nodes under the nodeInWSDL if there is an 'element'
type the
     * add its types or references to the dependent type.
     */
    private void getAllDependentTypes(XmlObject nodeInWSDL,
            Set<QName> dependentTypes) {
        // scan for any node under the type that has "type" or "ref"
attribute
        XmlCursor cursor = nodeInWSDL.newCursor();
        if (cursor.toFirstChild()) { // has child
            while (true) {
                getAllDependentTypes(cursor.getObject(), dependentTypes);
                if (!cursor.toNextSibling())
                    break;
            }
        }
        if (nodeInWSDL.schemaType().getName().getLocalPart().equals(
                "localElement")) {
            LocalElement e = (LocalElement) nodeInWSDL;

            if (e.isSetType())
                dependentTypes.add(e.getType());
            else if (e.isSetRef())
                dependentTypes.add(e.getRef());
        }
        return;
    }

    // NOTE [EMAIL PROTECTED] 2004-Nov-15 --
    // once the WSDLProcessor is changed to an interface, remove this
function
    // and use the one in the upcoming XmlBeanWSDLProcessor.
    private static <T extends XmlObject> T[] selectChildren(XmlObject
parent,
            Class<T> childClass) throws IllegalAccessException,
            NoSuchFieldException {
        // retrieve the SchemaType from the static type field
        SchemaType st = (SchemaType) childClass.getField("type").get(null);
        XmlObject[] kids =
parent.selectChildren(st.getDocumentElementName());
        T[] castKids = (T[]) Array.newInstance(childClass, kids.length);
        for (int j = 0; j < castKids.length; j++) {
            castKids[j] = childClass.cast(kids[j]);
        }
       return castKids;
    }
}




--
Free replacement for Exchange and Outlook (Contacts and Calendar)
http://www.ScheduleWorld.com/
WAP: http://www.ScheduleWorld.com/sw/WAPToday?id=4000&tz=EST
WebDAV: http://www.ScheduleWorld.com/sw/webDAVDir/4000.ics
VFREEBUSY: http://www.ScheduleWorld.com/sw/freebusy/4000.ifb






--
Free replacement for Exchange and Outlook (Contacts and Calendar)
http://www.ScheduleWorld.com/
WAP: http://www.ScheduleWorld.com/sw/WAPToday?id=4000&tz=EST
WebDAV: http://www.ScheduleWorld.com/sw/webDAVDir/4000.ics
VFREEBUSY: http://www.ScheduleWorld.com/sw/freebusy/4000.ifb

Reply via email to