diff options
Diffstat (limited to 'branches/sca-java-1.x')
4 files changed, 163 insertions, 35 deletions
diff --git a/branches/sca-java-1.x/tools/databinding/sdo/pom.xml b/branches/sca-java-1.x/tools/databinding/sdo/pom.xml index 9c8b6bb027..bd28b81e04 100644 --- a/branches/sca-java-1.x/tools/databinding/sdo/pom.xml +++ b/branches/sca-java-1.x/tools/databinding/sdo/pom.xml @@ -39,6 +39,13 @@ <artifactId>cxf-tools-wsdlto-core</artifactId>
<version>2.2.2</version>
</dependency>
+
+ <!--we are using jax-ws fronend-->
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-tools-wsdlto-frontend-jaxws</artifactId>
+ <version>2.2.2</version>
+ </dependency>
<!--tuscany implementation related dependencies-->
<dependency>
diff --git a/branches/sca-java-1.x/tools/databinding/sdo/src/main/java/org/apache/tuscany/tools/wsdl2java/sdo/SDODatabinding.java b/branches/sca-java-1.x/tools/databinding/sdo/src/main/java/org/apache/tuscany/tools/wsdl2java/sdo/SDODatabinding.java index 465977194c..de7e23ec71 100644 --- a/branches/sca-java-1.x/tools/databinding/sdo/src/main/java/org/apache/tuscany/tools/wsdl2java/sdo/SDODatabinding.java +++ b/branches/sca-java-1.x/tools/databinding/sdo/src/main/java/org/apache/tuscany/tools/wsdl2java/sdo/SDODatabinding.java @@ -19,12 +19,18 @@ package org.apache.tuscany.tools.wsdl2java.sdo;
+import java.io.BufferedReader;
import java.io.File;
+import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
import javax.xml.namespace.QName;
@@ -34,7 +40,13 @@ import org.apache.cxf.tools.common.ToolException; import org.apache.cxf.tools.common.model.DefaultValueWriter;
import org.apache.cxf.tools.wsdlto.core.DataBindingProfile;
import org.apache.tuscany.sdo.api.SDOUtil;
-import org.apache.tuscany.sdo.generate.JavaGenerator;
+import org.apache.tuscany.sdo.generate.XSD2JavaGenerator;
+import org.apache.tuscany.sdo.helper.HelperContextImpl;
+import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.impl.EPackageRegistryImpl;
+import org.eclipse.emf.ecore.util.BasicExtendedMetaData;
+import org.eclipse.emf.ecore.util.ExtendedMetaData;
import commonj.sdo.DataObject;
import commonj.sdo.Property;
@@ -43,22 +55,34 @@ import commonj.sdo.helper.HelperContext; import commonj.sdo.helper.TypeHelper;
import commonj.sdo.helper.XSDHelper;
-public class SDODatabinding extends JavaGenerator implements DataBindingProfile {
+public class SDODatabinding extends XSD2JavaGenerator implements DataBindingProfile {
+ private static final String DATABINDING_SDO = "sdo";
+ private static final String DATABINDING_STATIC_SDO = "static-sdo";
private TypeHelper typeHelper;
private XSDHelper xsdHelper;
+ private boolean dynamic;
+ private ExtendedMetaData extendedMetaData;
+
public void generate(ToolContext context) throws ToolException {
+ if (dynamic) {
+ // Node XSD2Java is needed for dynamic SDO
+ return;
+ }
+
+ Map<String, String> ns2pkgMap = context.getNamespacePackageMap();
+
String srcd = (String)context.get(ToolConstants.CFG_OUTPUTDIR);
- String classesd = (String)context.get(ToolConstants.CFG_CLASSDIR);
+ String pkg = context.getPackageName();
+
+ String wsdl = (String)context.get(ToolConstants.CFG_WSDLLOCATION);
// preparing the directories where files to be written.
File srcDir;
- File classesDir;
if (srcd == null) {
- String wsdl = (String)context.get(ToolConstants.CFG_WSDLLOCATION);
try {
- srcd = new File(new URI(wsdl)).getAbsolutePath();
+ srcd = new File(new URI(wsdl)).getParentFile().getAbsolutePath();
} catch (URISyntaxException e) {
srcd = new File(".").getAbsolutePath();
}
@@ -66,29 +90,112 @@ public class SDODatabinding extends JavaGenerator implements DataBindingProfile srcDir = new File(srcd);
srcDir.mkdirs();
- if (classesd == null) {
- classesDir = srcDir;
+ List<String> argList = new ArrayList<String>();
+ argList.add("-targetDirectory");
+ argList.add(srcDir.getAbsolutePath());
+
+ if (pkg != null) {
+ argList.add("-javaPackage");
+ argList.add(pkg);
+ }
+
+ // We need to copy the wsdl to a local file if it is not
+ argList.add(new File(URI.create(wsdl)).getAbsolutePath());
+
+ String[] args = argList.toArray(new String[argList.size()]);
+
+ try {
+ processArguments(args);
+ run(args);
+ } catch (Exception e) {
+ e.printStackTrace();
+ printUsage();
+ }
+
+ HelperContext hc = new HelperContextImpl(extendedMetaData, false);
+ xsdHelper = hc.getXSDHelper();
+ typeHelper = hc.getTypeHelper();
+
+ }
+
+ protected void run(String args[]) {
+ String xsdFileName = args[inputIndex];
+ EPackage.Registry packageRegistry = new EPackageRegistryImpl(EPackage.Registry.INSTANCE);
+ extendedMetaData = new BasicExtendedMetaData(packageRegistry);
+ String packageURI = getSchemaNamespace(xsdFileName);
+ Hashtable packageInfoTable =
+ createPackageInfoTable(packageURI, schemaNamespace, javaPackage, prefix, namespaceInfo);
+ generateFromXMLSchema(xsdFileName,
+ packageRegistry,
+ extendedMetaData,
+ targetDirectory,
+ packageInfoTable,
+ genOptions,
+ generateBuiltIn,
+ allNamespaces);
+ }
+
+ private static Hashtable createPackageInfoTable(String packageURI,
+ String schemaNamespace,
+ String javaPackage,
+ String prefix,
+ String namespaceInfo) {
+ Hashtable packageInfoTable = new Hashtable();
+
+ if (namespaceInfo != null) {
+ try {
+ FileReader inputFile = new FileReader(namespaceInfo);
+ BufferedReader bufRead = new BufferedReader(inputFile);
+
+ String line = bufRead.readLine();
+ while (line != null) {
+ if (line.length() > 0) {
+ String[] options = line.split(";");
+ if (options.length > 1) {
+ if (options.length > 2)
+ packageInfoTable.put(options[0], new PackageInfo(options[1], options[2], options[0],
+ null));
+ else
+ packageInfoTable.put(options[0], new PackageInfo(options[1], null, options[0], null));
+ } else
+ packageInfoTable.put(options[0], new PackageInfo(null, null, options[0], null));
+ }
+ line = bufRead.readLine();
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
} else {
- classesDir = new File(classesd);
- classesDir.mkdirs();
+ if (schemaNamespace != null)
+ packageInfoTable.put(schemaNamespace, new PackageInfo(javaPackage, prefix, schemaNamespace, null));
+ else if (packageURI != null)
+ packageInfoTable.put(packageURI, new PackageInfo(javaPackage, prefix, null, null));
}
+ return packageInfoTable;
}
public void initialize(ToolContext context) throws ToolException {
+ String databinding = (String)context.get(ToolConstants.CFG_DATABINDING);
+ if (!DATABINDING_STATIC_SDO.equalsIgnoreCase(databinding) || DATABINDING_SDO.equalsIgnoreCase(databinding)) {
+ dynamic = true;
+ }
+
+ generatedPackages = null;
String wsdl = (String)context.get(ToolConstants.CFG_WSDLLOCATION);
- xsdFileName = wsdl;
- HelperContext helperContext = SDOUtil.createHelperContext();
- xsdHelper = helperContext.getXSDHelper();
- URL location;
- try {
- location = new URL(xsdFileName);
- InputStream is = location.openStream();
- xsdHelper.define(is, xsdFileName);
- } catch (IOException e) {
- throw new ToolException(e);
+ if (dynamic) {
+ HelperContext helperContext = SDOUtil.createHelperContext();
+ xsdHelper = helperContext.getXSDHelper();
+ URL location;
+ try {
+ location = new URL(wsdl);
+ InputStream is = location.openStream();
+ xsdHelper.define(is, wsdl);
+ } catch (IOException e) {
+ throw new ToolException(e);
+ }
+ this.typeHelper = helperContext.getTypeHelper();
}
- this.typeHelper = helperContext.getTypeHelper();
}
public String getType(QName qName, boolean element) {
@@ -99,13 +206,25 @@ public class SDODatabinding extends JavaGenerator implements DataBindingProfile type = property.getType();
}
}
- typeHelper.getType(qName.getNamespaceURI(), qName.getLocalPart());
- if (type != null && type.isDataType()) {
- return type.getInstanceClass().getName();
+ if (type == null) {
+ type = typeHelper.getType(qName.getNamespaceURI(), qName.getLocalPart());
+ }
+ if (type != null) {
+ return getClassName(type);
}
return DataObject.class.getName();
}
+ private String getClassName(Type type) {
+ EClassifier eClass = (EClassifier)type;
+ String name = eClass.getInstanceClassName();
+ if (name == null) {
+ return type.getName();
+ } else {
+ return name;
+ }
+ }
+
public String getWrappedElementType(QName wrapperElement, QName item) {
Type type = null;
Property property =
@@ -117,8 +236,8 @@ public class SDODatabinding extends JavaGenerator implements DataBindingProfile type = itemProp.getType();
}
}
- if (type != null && type.isDataType()) {
- return type.getInstanceClass().getName();
+ if (type != null) {
+ return getClassName(type);
}
return DataObject.class.getName();
}
@@ -133,10 +252,4 @@ public class SDODatabinding extends JavaGenerator implements DataBindingProfile return null;
}
- protected void run(String[] strings) {
- // We extended the JavaGenerator class in order to make use of its utility methods
- //but we are not going to implement standalone java generator.
- // So no functionality in this method.
- }
-
}
diff --git a/branches/sca-java-1.x/tools/databinding/sdo/src/main/resources/META-INF/tools-plugin.xml b/branches/sca-java-1.x/tools/databinding/sdo/src/main/resources/META-INF/tools-plugin.xml index 6f989cf3ae..abcdeb0f7c 100644 --- a/branches/sca-java-1.x/tools/databinding/sdo/src/main/resources/META-INF/tools-plugin.xml +++ b/branches/sca-java-1.x/tools/databinding/sdo/src/main/resources/META-INF/tools-plugin.xml @@ -19,4 +19,5 @@ -->
<plugin name="sdo" version="" provider="tuscany.apache.org" xmlns="http://cxf.apache.org/tools/plugin">
<databinding name="sdo" package="org.apache.tuscany.tools.wsdl2java.sdo" profile="SDODatabinding" />
+ <databinding name="static-sdo" package="org.apache.tuscany.tools.wsdl2java.sdo" profile="SDODatabinding" />
</plugin>
\ No newline at end of file diff --git a/branches/sca-java-1.x/tools/databinding/sdo/src/test/java/org/apache/tuscany/tools/wsdl2java/sdo/SDODataBindingTestCase.java b/branches/sca-java-1.x/tools/databinding/sdo/src/test/java/org/apache/tuscany/tools/wsdl2java/sdo/SDODataBindingTestCase.java index 72d66a7ac9..5ae8421870 100644 --- a/branches/sca-java-1.x/tools/databinding/sdo/src/test/java/org/apache/tuscany/tools/wsdl2java/sdo/SDODataBindingTestCase.java +++ b/branches/sca-java-1.x/tools/databinding/sdo/src/test/java/org/apache/tuscany/tools/wsdl2java/sdo/SDODataBindingTestCase.java @@ -30,10 +30,17 @@ import org.junit.Test; public class SDODataBindingTestCase {
@Test
- public void testGenerate() {
+ public void testGenerateStatic() {
URL url = getClass().getResource("/HelloService.wsdl");
- String args[] =
- new String[] {"-db", "sdo", "-d", "target/jaxws-source", url.toString()};
+ String args[] = new String[] {"-db", "static-sdo", "-d", "target/jaxws-static-sdo-source", url.toString()};
+ WSDLToJava.main(args);
+
+ }
+
+ @Test
+ public void testGenerateDynamic() {
+ URL url = getClass().getResource("/HelloService.wsdl");
+ String args[] = new String[] {"-db", "sdo", "-d", "target/jaxws-sdo-source", url.toString()};
WSDLToJava.main(args);
}
|