You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by as...@apache.org on 2005/08/26 16:39:28 UTC
svn commit: r240250 - in
/webservices/axis/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl:
codegen/ codegen/writer/ template/java/
Author: ashutosh
Date: Fri Aug 26 07:39:16 2005
New Revision: 240250
URL: http://svn.apache.org/viewcvs?rev=240250&view=rev
Log:
Some code additions to incorporate JAXB extension. I have kept JAXBExtension.java in scratch area for time being as it is dependent on JAXB 2.0 RI
Added:
webservices/axis/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/template/java/JAXBSupporterTemplate.xsl
Modified:
webservices/axis/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/codegen/CodeGenConfiguration.java
webservices/axis/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/codegen/CommandLineOptionConstants.java
webservices/axis/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/codegen/XSLTConstants.java
webservices/axis/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/codegen/writer/DatabindingSupportClassWriter.java
webservices/axis/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/template/java/TestClassTemplate.xsl
Modified: webservices/axis/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/codegen/CodeGenConfiguration.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/codegen/CodeGenConfiguration.java?rev=240250&r1=240249&r2=240250&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/codegen/CodeGenConfiguration.java (original)
+++ webservices/axis/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/codegen/CodeGenConfiguration.java Fri Aug 26 07:39:16 2005
@@ -61,6 +61,16 @@
public void setDatabindingType(int databindingType) {
this.databindingType = databindingType;
}
+
+ public void setDatabindingType(String databindingType) {
+ if (Databinding.XML_BEANS.equalsIgnoreCase(databindingType)) {
+ this.databindingType = XSLTConstants.DataBindingTypes.XML_BEANS;
+ }else if(Databinding.JAXB.equalsIgnoreCase(databindingType)){
+ this.databindingType = XSLTConstants.DataBindingTypes.JAXB;
+ }else{
+ throw new UnsupportedOperationException();
+ }
+ }
/**
* @param wom
@@ -117,10 +127,9 @@
// Unused code commented out by gdaniels...
CommandLineOption dataBindingOption = (CommandLineOption) optionMap.get(
DATA_BINDING_TYPE_OPTION);
- if (dataBindingOption!=null){
- this.databindingType = Integer.parseInt(dataBindingOption.getOptionValue());
+ if(dataBindingOption != null){
+ setDatabindingType(dataBindingOption.getOptionValue());
}
-
}
Modified: webservices/axis/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/codegen/CommandLineOptionConstants.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/codegen/CommandLineOptionConstants.java?rev=240250&r1=240249&r2=240250&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/codegen/CommandLineOptionConstants.java (original)
+++ webservices/axis/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/codegen/CommandLineOptionConstants.java Fri Aug 26 07:39:16 2005
@@ -44,4 +44,9 @@
public static final String C_PLUS_PLUS = "cpp";
}
+
+ public interface Databinding {
+ public static final String XML_BEANS = "xmlbeans";
+ public static final String JAXB = "jaxb";
+ }
}
Modified: webservices/axis/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/codegen/XSLTConstants.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/codegen/XSLTConstants.java?rev=240250&r1=240249&r2=240250&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/codegen/XSLTConstants.java (original)
+++ webservices/axis/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/codegen/XSLTConstants.java Fri Aug 26 07:39:16 2005
@@ -87,6 +87,7 @@
public interface XSLTDatabindingSupporterTemplates {
public static final String JAVA_TEMPLATE = "/org/apache/axis2/wsdl/template/java/XMLBeansSupporterTemplate.xsl";
+ public static final String JAXB_TEMPLATE = "/org/apache/axis2/wsdl/template/java/JAXBSupporterTemplate.xsl";
public static final String DEFAULT_TEMPLATE = "/org/apache/axis2/wsdl/template/java/DefaultDataBindingSupporterTemplate.xsl";
//public static final String CSHARP_TEMPLATE = "/org/apache/axis2/wsdl/template/csharp/TestClassTemplate.xsl";
}
Modified: webservices/axis/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/codegen/writer/DatabindingSupportClassWriter.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/codegen/writer/DatabindingSupportClassWriter.java?rev=240250&r1=240249&r2=240250&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/codegen/writer/DatabindingSupportClassWriter.java (original)
+++ webservices/axis/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/codegen/writer/DatabindingSupportClassWriter.java Fri Aug 26 07:39:16 2005
@@ -58,6 +58,9 @@
default:
throw new UnsupportedOperationException();
}
+ } else if (XSLTConstants.DataBindingTypes.JAXB ==
+ this.databindingFramework) {
+ this.xsltStream = clazz.getResourceAsStream(XSLTConstants.XSLTDatabindingSupporterTemplates.JAXB_TEMPLATE);
} else if (XSLTConstants.DataBindingTypes.NONE ==
this.databindingFramework) {
this.xsltStream = clazz.getResourceAsStream(XSLTConstants.XSLTDatabindingSupporterTemplates.DEFAULT_TEMPLATE);
Added: webservices/axis/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/template/java/JAXBSupporterTemplate.xsl
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/template/java/JAXBSupporterTemplate.xsl?rev=240250&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/template/java/JAXBSupporterTemplate.xsl (added)
+++ webservices/axis/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/template/java/JAXBSupporterTemplate.xsl Fri Aug 26 07:39:16 2005
@@ -0,0 +1,107 @@
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+ <xsl:output method="text"/>
+ <xsl:template match="/class">
+ package <xsl:value-of select="@package"/>;
+ import java.io.FileOutputStream;
+ import java.io.FileInputStream;
+
+ import javax.xml.bind.JAXBContext;
+ import javax.xml.bind.Marshaller;
+ import javax.xml.bind.Unmarshaller;
+ import javax.xml.stream.*;
+
+ /**
+ * Auto generated supporter class for XML beans by the Axis code generator
+ */
+
+ public class <xsl:value-of select="@name"/> {
+ <xsl:apply-templates />
+
+ public static java.lang.Object fromOM(org.apache.axis2.om.OMElement param,
+ java.lang.Class type){
+ try{
+ FileOutputStream fos = new FileOutputStream("_temp_");
+ XMLStreamWriter writer = XMLOutputFactory.newInstance()
+ .createXMLStreamWriter(new FileOutputStream("_temp_"));
+ param.serialize(writer);
+ writer.flush();
+ fos.flush();
+ fos.close();
+ JAXBContext jaxbContext = JAXBContext.newInstance("org.simpletest.xsd");
+ //Above org.simpletest.xsd is being hardcoded, but it should actually be the
+ //package corresponding to targetnamespace of schema.
+ Unmarshaller unmarsh = jaxbContext.createUnmarshaller();
+ FileInputStream xmlContent = new FileInputStream("_temp_");
+
+ <xsl:for-each select="param">
+ <xsl:if test="@type!=''">
+ if (<xsl:value-of select="@type"/>.class.equals(type)){
+ <xsl:value-of select="@type"/> unmarshalledClazz = (<xsl:value-of select="@type"/>)unmarsh.unmarshal(xmlContent);
+ return unmarshalledClazz;
+ }
+ </xsl:if>
+ </xsl:for-each>
+ }catch(java.lang.Exception e){
+ throw new RuntimeException("Data binding error",e);
+ }
+ return null;
+ }
+
+ //Generates an empty object for testing
+ // Caution - need some manual editing to work properly
+
+ public static java.lang.Object getTestObject(java.lang.Class type){
+ //Returning empty object for compilation to succeed. Don't rely on
+ //using the test object out of this method, as it is.
+ try {
+ <xsl:for-each select="param">
+ <xsl:if test="@type!=''">
+ if (<xsl:value-of select="@type"/>.class.equals(type)){
+ <xsl:value-of select="@type"/> emptyObject= <xsl:value-of select="@type"/>.class.newInstance();
+ return emptyObject;
+ }
+ </xsl:if>
+ </xsl:for-each>
+ return null;
+ } catch(java.lang.Exception e){
+ throw new RuntimeException("Test object creation failure",e);
+ }
+ }
+
+ }
+ </xsl:template>
+
+ <xsl:template match="param">
+ <xsl:if test="@type!=''">
+ public static org.apache.axis2.om.OMElement toOM(<xsl:value-of select="@type"/> param){
+ try {
+ JAXBContext jaxbContext = JAXBContext.newInstance("org.simpletest.xsd");
+ //Above org.simpletest.xsd is being hardcoded, but it should actually be the
+ //package corresponding to targetnamespace of schema.
+ Marshaller marsh = jaxbContext.createMarshaller();
+ //we want the output to be neatly indented, right?
+ marsh.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,
+ new Boolean(true));
+ FileOutputStream tempFOP = new FileOutputStream("_temp_");
+ System.out.println("JAXB marshalled output of the java instance:");
+ marsh.marshal(param,System.out);
+ marsh.marshal(param, tempFOP);
+
+ tempFOP.flush();
+ tempFOP.close();
+ XMLStreamReader reader = XMLInputFactory.newInstance().
+ createXMLStreamReader(new FileInputStream("_temp_"));
+ org.apache.axis2.om.impl.llom.builder.StAXOMBuilder builder = new org.apache.axis2.om.impl.llom.builder.StAXOMBuilder
+ (org.apache.axis2.om.OMAbstractFactory.getOMFactory(),new org.apache.axis2.clientapi.StreamWrapper(reader)) ;
+ org.apache.axis2.om.OMElement documentElement = builder.getDocumentElement();
+ //Building the element is needed to avoid certain stream errors!
+ documentElement.build();
+ return documentElement;
+ } catch(Exception e) {
+ System.err.println("Exception encountered in echoStringDatabindingSupporter.toOM(). Returning null");
+ }
+ return null;
+ }
+ </xsl:if>
+ </xsl:template>
+ </xsl:stylesheet>
\ No newline at end of file
Modified: webservices/axis/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/template/java/TestClassTemplate.xsl
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/template/java/TestClassTemplate.xsl?rev=240250&r1=240249&r2=240250&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/template/java/TestClassTemplate.xsl (original)
+++ webservices/axis/trunk/java/modules/wsdl/src/org/apache/axis2/wsdl/template/java/TestClassTemplate.xsl Fri Aug 26 07:39:16 2005
@@ -135,6 +135,6 @@
<!-- end of in-out mep -->
</xsl:if>
</xsl:for-each>
-
+ }
</xsl:template>
</xsl:stylesheet>