You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by ds...@apache.org on 2006/03/29 11:47:18 UTC

svn commit: r389731 - in /webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl: codegen/extension/JiBXExtension.java template/general/jibxAntBuildTemplate.xsl

Author: dsosnoski
Date: Wed Mar 29 01:47:16 2006
New Revision: 389731

URL: http://svn.apache.org/viewcvs?rev=389731&view=rev
Log:
Added missed files for JiBX code generation extension

Added:
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/extension/JiBXExtension.java
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/template/general/jibxAntBuildTemplate.xsl

Added: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/extension/JiBXExtension.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/extension/JiBXExtension.java?rev=389731&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/extension/JiBXExtension.java (added)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/extension/JiBXExtension.java Wed Mar 29 01:47:16 2006
@@ -0,0 +1,183 @@
+/*
+ * Copyright 2006 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.
+ */
+
+package org.apache.axis2.wsdl.codegen.extension;
+
+import java.lang.reflect.Method;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axis2.wsdl.databinding.JavaTypeMapper;
+import org.apache.axis2.wsdl.i18n.CodegenMessages;
+import org.apache.wsdl.WSDLBinding;
+import org.apache.wsdl.WSDLBindingMessageReference;
+import org.apache.wsdl.WSDLBindingOperation;
+import org.apache.wsdl.WSDLConstants;
+import org.apache.wsdl.WSDLExtensibilityElement;
+import org.apache.wsdl.WSDLInterface;
+import org.apache.wsdl.WSDLOperation;
+import org.apache.wsdl.extensions.ExtensionConstants;
+import org.apache.wsdl.extensions.SOAPBody;
+
+public class JiBXExtension extends AbstractDBProcessingExtension {
+    
+    public static final String BINDING_PATH_OPTION = "bindingfile";
+    public static final String JIBX_MODEL_CLASS =
+        "org.jibx.binding.model.BindingElement";
+    public static final String JIBX_UTILITY_CLASS =
+        "org.apache.axis2.jibx.CodeGenerationUtility";
+    public static final String BINDING_MAP_METHOD = "getBindingMap";
+    
+    public void engage() {
+
+        // just return if JiBX binding not active
+        if (testFallThrough(configuration.getDatabindingType())) {
+            return;
+        }
+
+        // check the comptibilty - currently only doc/lit is supported
+        checkCompatibility();
+        
+        // check the JiBX binding definition file specified
+        String path = (String)configuration.getProperties().get(BINDING_PATH_OPTION);
+        if (path == null) {
+            throw new RuntimeException("jibx binding option requires -" +
+                BINDING_PATH_OPTION + " {file path} parameter");
+//                CodegenMessages.getMessage("extension.encodedNotSupported"));
+        }
+        try {
+            
+            // load and call JiBX utilities to handle binding
+            Class clas = null;
+            try {
+                JiBXExtension.class.getClassLoader().loadClass(JIBX_MODEL_CLASS);
+            } catch (ClassNotFoundException e) {
+                throw new RuntimeException("JiBX framework jars not in classpath");
+            }
+            try {
+                clas = JiBXExtension.class.getClassLoader().loadClass(JIBX_UTILITY_CLASS);
+            } catch (ClassNotFoundException e) {
+                throw new RuntimeException("JiBX binding extension not in classpath");
+            }
+            Method method = clas.getMethod(BINDING_MAP_METHOD,
+                new Class[] { String.class });
+            HashMap jibxmap = (HashMap)method.invoke(null, new Object[] { path });
+            
+            // Want to find all elements by working down from bindings (if any
+            // supplied) or interfaces (if no bindings). Not sure why this dual
+            // path is required, but based on the code in
+            // org.apache.axis2.wsdl.builder.SchemaUnwrapper
+            HashSet elements = new HashSet();
+            Map bindings = configuration.getWom().getBindings();
+            Map interfaces = configuration.getWom().getWsdlInterfaces();
+            if (bindings != null && !bindings.isEmpty()) {
+                for (Iterator iter = bindings.values().iterator(); iter.hasNext();) {
+                    accumulateElements(((WSDLBinding)iter.next()).getBoundInterface(), elements);
+                }
+            } else if (interfaces != null && !interfaces.isEmpty()) {
+                for (Iterator iter = interfaces.values().iterator(); iter.hasNext();) {
+                    accumulateElements((WSDLInterface)iter.next(), elements);
+                }
+            }
+            
+            // build type mapping from JiBX mappings for elements
+            JavaTypeMapper mapper = new JavaTypeMapper();
+            for (Iterator iter = elements.iterator(); iter.hasNext();) {
+                QName qname = (QName)iter.next();
+                String cname = (String)jibxmap.get(qname);
+                if (cname == null) {
+                    throw new RuntimeException("No JiBX mapping defined for " + qname);
+                }
+                mapper.addTypeMappingName(qname, cname);
+            }
+            
+            // set the type mapper to the config
+            configuration.setTypeMapper(mapper);
+            
+        } catch (Exception e) {
+            if (e instanceof RuntimeException) {
+                throw (RuntimeException)e;
+            } else {
+                throw new RuntimeException(e);
+            }
+        }
+
+    }
+
+    /**
+     * Accumulate the QNames of all message elements used by an interface. Based on
+     * the code in {@link org.apache.axis2.wsdl.builder.SchemaUnwrapper}
+     * 
+     * @param interf
+     * @param elements
+     */
+    private void accumulateElements(WSDLInterface interf, HashSet elements) {
+        
+        // we should be getting all the operation since we also need to consider the inherited ones
+        for (Iterator iter = interf.getAllOperations().values().iterator(); iter.hasNext();) {
+            WSDLOperation operation = (WSDLOperation)iter.next();
+            if (operation.getInputMessage() != null) {
+                elements.add(operation.getInputMessage().getElementQName());
+            }
+            if (operation.getOutputMessage() != null) {
+                elements.add(operation.getOutputMessage().getElementQName());
+            }
+        }
+    }
+
+    /**
+     * Checking the compatibilty has to do with generating RPC/encoded stubs.
+     * If the XMLBeans bindings are used encoded binding cannot be done.
+     */
+    private void checkCompatibility() {
+        Map bindingMap = this.configuration.getWom().getBindings();
+        Collection col = bindingMap.values();
+
+        for (Iterator iterator = col.iterator(); iterator.hasNext();) {
+            WSDLBinding b = (WSDLBinding) iterator.next();
+            HashMap bindingOps = b.getBindingOperations();
+            Collection bindingOpsCollection = bindingOps.values();
+            for (Iterator iterator1 = bindingOpsCollection.iterator(); iterator1.hasNext();) {
+                checkInvalidUse((WSDLBindingOperation) iterator1.next());
+            }
+
+        }
+    }
+
+    protected void checkInvalidUse(WSDLBindingOperation bindingOp) {
+        WSDLBindingMessageReference input = bindingOp.getInput();
+        if (input != null) {
+            Iterator extIterator = input.getExtensibilityElements()
+                    .iterator();
+            while (extIterator.hasNext()) {
+                WSDLExtensibilityElement element = (WSDLExtensibilityElement) extIterator.next();
+                if (ExtensionConstants.SOAP_11_BODY.equals(element.getType()) ||
+                        ExtensionConstants.SOAP_12_BODY.equals(element.getType())) {
+                    if (WSDLConstants.WSDL_USE_ENCODED.equals(
+                            ((SOAPBody) element).getUse())) {
+                        throw new RuntimeException(
+                                CodegenMessages.getMessage("extension.encodedNotSupported"));
+                    }
+                }
+            }
+        }
+    }
+}
\ No newline at end of file

Added: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/template/general/jibxAntBuildTemplate.xsl
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/template/general/jibxAntBuildTemplate.xsl?rev=389731&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/template/general/jibxAntBuildTemplate.xsl (added)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/template/general/jibxAntBuildTemplate.xsl Wed Mar 29 01:47:16 2006
@@ -0,0 +1,241 @@
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+    <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
+    <xsl:template match="/ant">
+        <xsl:variable name="package">
+            <xsl:value-of select="@package"/>
+        </xsl:variable>
+
+        <project basedir="." default="jar.all">
+            <xsl:comment>Auto generated ant build file</xsl:comment>
+            <property environment="env"/>
+            <property name="axis2.home">
+                <xsl:attribute name="value">${env.AXIS2_HOME}</xsl:attribute>
+            </property>
+            <property name="project.base.dir">
+                <xsl:attribute name="value">.</xsl:attribute>
+            </property>
+            <property name="maven.class.path">
+                <xsl:attribute name="value"></xsl:attribute>
+            </property>
+            <property name="name">
+                <xsl:attribute name="value"><xsl:value-of select="@servicename"/></xsl:attribute>
+            </property>
+            <property name="src">
+                <xsl:attribute name="value">${project.base.dir}/src</xsl:attribute>
+            </property>
+            <property name="test">
+                <xsl:attribute name="value">${project.base.dir}/test</xsl:attribute>
+            </property>
+            <property name="build">
+                <xsl:attribute name="value">${project.base.dir}/build</xsl:attribute>
+            </property>
+            <property name="classes">
+                <xsl:attribute name="value">${build}/classes</xsl:attribute>
+            </property>
+            <property name="lib">
+                <xsl:attribute name="value">${build}/lib</xsl:attribute>
+            </property>
+            <property name="resources">
+                <xsl:attribute name="value">${project.base.dir}/resources</xsl:attribute>
+            </property>
+
+            <property name="jars.ok" value=""></property>
+
+            <path id="axis2.class.path">
+                <pathelement>
+                    <xsl:attribute name="path">${java.class.path}</xsl:attribute>
+                </pathelement>
+                <pathelement>
+                    <xsl:attribute name="path">${maven.class.path}</xsl:attribute>
+                </pathelement>
+                <fileset>
+                    <xsl:attribute name="dir">${axis2.home}</xsl:attribute>
+                    <include>
+                        <xsl:attribute name="name">lib/*.jar</xsl:attribute>
+                    </include>
+                </fileset>
+            </path>
+
+            <target name="init">
+                <mkdir>
+                    <xsl:attribute name="dir">${build}</xsl:attribute>
+                </mkdir>
+                <mkdir>
+                    <xsl:attribute name="dir">${classes}</xsl:attribute>
+                </mkdir>
+                <mkdir>
+                    <xsl:attribute name="dir">${lib}</xsl:attribute>
+                </mkdir>
+                <xsl:if test="not(@testOmit)">
+                    <mkdir>
+                        <xsl:attribute name="dir">${test}</xsl:attribute>
+                    </mkdir>
+                </xsl:if>
+            </target>
+
+            <target name="pre.compile.test" depends="init">
+                <xsl:comment>Test the classpath for the availability of necesary classes</xsl:comment>
+
+                <available classname="javax.xml.stream.XMLStreamReader" property="stax.available" classpathref="axis2.class.path"/>
+                <available classname="org.apache.axis2.engine.AxisEngine" property="axis2.available" classpathref="axis2.class.path"/>
+                <available classname="org.jibx.runtime.BindingDirectory" property="jibx.available" classpathref="axis2.class.path"/>
+                <condition property="jars.ok">
+                    <and>
+                        <isset property="stax.available"/>
+                        <isset property="axis2.available"/>
+                        <isset property="jibx.available"/>
+                    </and>
+                </condition>
+
+                <xsl:comment>Print out the availabilities</xsl:comment>
+                <echo>
+                    <xsl:attribute name="message">Stax Availability= ${stax.available}</xsl:attribute>
+                </echo>
+                <echo>
+                    <xsl:attribute name="message">Axis2 Availability= ${axis2.available}</xsl:attribute>
+                </echo>
+                <echo>
+                    <xsl:attribute name="message">JiBX Availability= ${jibx.available}</xsl:attribute>
+                </echo>
+
+            </target>
+
+            <target name="compile.src" depends="pre.compile.test">
+                <xsl:attribute name="if">jars.ok</xsl:attribute>
+                <javac debug="on">
+                    <xsl:attribute name="destdir">${classes}</xsl:attribute>
+                    <xsl:attribute name="srcdir">${src}</xsl:attribute>
+                    <classpath>
+                        <xsl:attribute name="refid">axis2.class.path</xsl:attribute>
+                    </classpath>
+                </javac>
+            </target>
+
+            <target name="compile.test" depends="compile.src">
+                <xsl:attribute name="if">jars.ok</xsl:attribute>
+                <javac debug="on">
+                    <xsl:attribute name="destdir">${classes}</xsl:attribute>
+                    <src>
+                        <xsl:attribute name="path">${test}</xsl:attribute>
+                    </src>
+                    <classpath>
+                        <xsl:attribute name="refid">axis2.class.path</xsl:attribute>
+                    </classpath>
+                </javac>
+            </target>
+
+            <target name="echo.classpath.problem" depends="pre.compile.test">
+                <xsl:attribute name="unless">jars.ok</xsl:attribute>
+                <echo message="The class path is not set right!
+                               Please make sure the following classes are in the classpath
+                               1. XmlBeans
+                               2. Stax
+                               3. Axis2
+                "></echo>
+            </target>
+            <target name="jar.all" depends="jar.server, jar.client">
+            </target>
+            <target name="jar.server" depends="compile.src,echo.classpath.problem">
+                <xsl:attribute name="if">jars.ok</xsl:attribute>
+                <copy>
+                    <xsl:attribute name="toDir">${classes}/META-INF</xsl:attribute>
+                    <fileset>
+                        <xsl:attribute name="dir">${resources}</xsl:attribute>
+                        <include><xsl:attribute name="name">*.xml</xsl:attribute></include>
+                        <include><xsl:attribute name="name">*.wsdl</xsl:attribute></include>
+                    </fileset>
+                </copy>
+                <jar>
+                    <xsl:attribute name="destfile">${lib}/${name}.aar</xsl:attribute>
+                    <fileset>
+                        <xsl:attribute name="excludes">**/Test.class</xsl:attribute>
+                        <xsl:attribute name="dir">${classes}</xsl:attribute>
+                    </fileset>
+                </jar>
+            </target>
+
+            <!-- select between the -->
+
+            <target name="jar.client" if="jars.ok">
+                 <!--set the correct depends target-->
+                <xsl:choose>
+                    <xsl:when test="@testOmit">
+                        <xsl:attribute name="depends">compile.src</xsl:attribute>
+                    </xsl:when>
+                    <xsl:otherwise>
+                        <xsl:attribute name="depends">compile.test</xsl:attribute>
+                    </xsl:otherwise>
+                </xsl:choose>
+                <jar>
+                    <xsl:attribute name="destfile">${lib}/${name}-test-client.jar</xsl:attribute>
+                    <fileset>
+                        <xsl:attribute name="dir">${classes}</xsl:attribute>
+                        <exclude><xsl:attribute name="name">**/META-INF/*.*</xsl:attribute></exclude>
+                        <exclude><xsl:attribute name="name">**/lib/*.*</xsl:attribute></exclude>
+                        <exclude><xsl:attribute name="name">**/*MessageReceiver.class</xsl:attribute></exclude>
+                        <exclude><xsl:attribute name="name">**/*Skeleton.class</xsl:attribute></exclude>
+                    </fileset>
+                </jar>
+            </target>
+
+
+
+
+            <target depends="jar.server" name="make.repo" if="jars.ok">
+                <mkdir>
+                    <xsl:attribute name="dir">${build}/repo/</xsl:attribute>
+                </mkdir>
+                <mkdir>
+                    <xsl:attribute name="dir">${build}/repo/services</xsl:attribute>
+                </mkdir>
+                <copy>
+                    <xsl:attribute name="file">${build}/lib/${name}.aar</xsl:attribute>
+                    <xsl:attribute name="toDir">${build}/repo/services/</xsl:attribute>
+                </copy>
+            </target>
+            <target depends="make.repo" name="start.server" if="jars.ok">
+                <java classname="org.apache.axis2.transport.http.SimpleHTTPServer" fork="true">
+                    <arg>
+                        <xsl:attribute name="value">${build}/repo</xsl:attribute>
+                    </arg>
+                    <classpath>
+                        <xsl:attribute name="refid">axis2.class.path</xsl:attribute>
+                    </classpath>
+                </java>
+            </target>
+            <target if="jars.ok" name="run.test" depends="compile.test">
+                <path id="test.class.path">
+                    <pathelement>
+                        <xsl:attribute name="location">${lib}/${name}-test-client.jar</xsl:attribute>
+                    </pathelement>
+                    <path>
+                        <xsl:attribute name="refid">axis2.class.path</xsl:attribute>
+                    </path>
+                </path>
+                <mkdir>
+                    <xsl:attribute name="dir">${build}/test-reports/</xsl:attribute>
+                </mkdir>
+                <junit printsummary="yes" haltonfailure="yes">
+                    <classpath>
+                        <xsl:attribute name="refid">test.class.path</xsl:attribute>
+                    </classpath>
+                    <formatter type="plain"/>
+                    <batchtest fork="yes">
+                        <xsl:attribute name="toDir">${build}/test-reports/</xsl:attribute>
+                        <fileset>
+                            <xsl:attribute name="dir">${test}</xsl:attribute>
+                            <include>
+                                <xsl:attribute name="name">**/*Test*.java</xsl:attribute>
+                            </include>
+                        </fileset>
+                    </batchtest>
+                </junit>
+            </target>
+            <target name="clean">
+                <delete>
+                    <xsl:attribute name="dir">${build}</xsl:attribute>
+                </delete>
+            </target>
+        </project>
+    </xsl:template>
+</xsl:stylesheet>