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 ds...@apache.org on 2006/11/12 12:24:29 UTC
svn commit: r473929 - in /webservices/axis2/branches/java/1_1/modules:
codegen/src/org/apache/axis2/wsdl/codegen/extension/JiBXExtension.java
jibx/src/org/apache/axis2/jibx/CodeGenerationUtility.java
jibx/src/org/apache/axis2/jibx/NullBindingFactory.java
Author: dsosnoski
Date: Sun Nov 12 03:24:28 2006
New Revision: 473929
URL: http://svn.apache.org/viewvc?view=rev&rev=473929
Log:
AXIS2-1685
Eliminate requirement for binding definition when only basic types are used by WSDL
Added:
webservices/axis2/branches/java/1_1/modules/jibx/src/org/apache/axis2/jibx/NullBindingFactory.java
Modified:
webservices/axis2/branches/java/1_1/modules/codegen/src/org/apache/axis2/wsdl/codegen/extension/JiBXExtension.java
webservices/axis2/branches/java/1_1/modules/jibx/src/org/apache/axis2/jibx/CodeGenerationUtility.java
Modified: webservices/axis2/branches/java/1_1/modules/codegen/src/org/apache/axis2/wsdl/codegen/extension/JiBXExtension.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_1/modules/codegen/src/org/apache/axis2/wsdl/codegen/extension/JiBXExtension.java?view=diff&rev=473929&r1=473928&r2=473929
==============================================================================
--- webservices/axis2/branches/java/1_1/modules/codegen/src/org/apache/axis2/wsdl/codegen/extension/JiBXExtension.java (original)
+++ webservices/axis2/branches/java/1_1/modules/codegen/src/org/apache/axis2/wsdl/codegen/extension/JiBXExtension.java Sun Nov 12 03:24:28 2006
@@ -46,10 +46,6 @@
// 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 currently requires -E" +
- BINDING_PATH_OPTION + " {file-path} parameter");
- }
try {
// try dummy load of framework class first to check missing jars
Modified: webservices/axis2/branches/java/1_1/modules/jibx/src/org/apache/axis2/jibx/CodeGenerationUtility.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_1/modules/jibx/src/org/apache/axis2/jibx/CodeGenerationUtility.java?view=diff&rev=473929&r1=473928&r2=473929
==============================================================================
--- webservices/axis2/branches/java/1_1/modules/jibx/src/org/apache/axis2/jibx/CodeGenerationUtility.java (original)
+++ webservices/axis2/branches/java/1_1/modules/jibx/src/org/apache/axis2/jibx/CodeGenerationUtility.java Sun Nov 12 03:24:28 2006
@@ -39,6 +39,7 @@
import org.apache.axis2.wsdl.WSDLConstants;
import org.apache.axis2.wsdl.WSDLUtil;
import org.apache.axis2.wsdl.codegen.CodeGenConfiguration;
+import org.apache.axis2.wsdl.codegen.extension.JiBXExtension;
import org.apache.axis2.wsdl.databinding.JavaTypeMapper;
import org.apache.axis2.wsdl.util.Constants;
import org.apache.axis2.wsdl.util.MessagePartInformationHolder;
@@ -90,6 +91,18 @@
s_primitiveSet.add("void");
}
+ private static HashMap s_wrapperMap = new HashMap();
+ static {
+ s_wrapperMap.put("boolean", "Boolean");
+ s_wrapperMap.put("byte", "Byte");
+ s_wrapperMap.put("char", "Character");
+ s_wrapperMap.put("double", "Double");
+ s_wrapperMap.put("float", "Float");
+ s_wrapperMap.put("int", "Integer");
+ s_wrapperMap.put("long", "Long");
+ s_wrapperMap.put("short", "Short");
+ }
+
/** Reserved words for Java (keywords and literals). */
private static final HashSet s_reservedWords = new HashSet();
static {
@@ -154,6 +167,13 @@
s_reservedWords.add("true");
s_reservedWords.add("false");
s_reservedWords.add("null");
+
+ // variable names used by template unwrapped code generation
+ // TODO change templates to use $xxx names, block generation from WSDL
+ s_reservedWords.add("true");
+ s_reservedWords.add("uctx");
+ s_reservedWords.add("child");
+ s_reservedWords.add("wrapper");
}
/**
@@ -180,37 +200,48 @@
* each unwrapped parameter, and the detailed information is set on the
* message information. Sound confusing? Welcome to Axis2 code generation.
*
- * @param path binding path
+ * @param path binding path (<code>null</code> if none)
*/
public void engage(String path) {
- // make sure the binding definition file is present
- File file = new File(path);
- if (!file.exists()) {
- throw new RuntimeException("jibx binding definition file " + path + " not found");
-// CodegenMessages.getMessage("extension.encodedNotSupported"));
+ // make sure the binding definition file is present, if passed
+ File file = null;
+ if (path != null) {
+ file = new File(path);
+ if (!file.exists()) {
+ throw new RuntimeException("jibx binding definition file " + path + " not found");
+ }
}
-
- // Read the JiBX binding definition into memory. The binding definition
- // is only prevalidated so as not to require the user to have all
- // the referenced classes in the classpath, though this does make for
- // added work in finding the namespaces.
try {
- ValidationContext vctx = BindingElement.newValidationContext();
- BindingElement binding =
- BindingElement.readBinding(new FileInputStream(file), path, vctx);
- binding.setBaseUrl(file.toURL());
- vctx.setBindingRoot(binding);
- IncludePrevalidationVisitor ipv = new IncludePrevalidationVisitor(vctx);
- vctx.tourTree(binding, ipv);
- if (vctx.getErrorCount() != 0 || vctx.getFatalCount() != 0) {
- throw new RuntimeException("invalid jibx binding definition file " + path);
- }
- // make sure classes will be generated for abstract mappings
+ // set flag for unwrapping
boolean unwrap = !codeGenConfig.isParametersWrapped();
- if (unwrap && !binding.isForceClasses()) {
- throw new RuntimeException("unwrapped binding must use force-classes='true' option in " + path);
+
+ // initialize the binding information
+ BindingElement binding = null;
+ if (file == null) {
+
+ // unwrapped can be used without a binding, but wrapped requires one
+ if (!unwrap) {
+ throw new RuntimeException("JiBX wrapped support requires a binding definition to be provided using the -E" +
+ JiBXExtension.BINDING_PATH_OPTION + " {file-path} parameter");
+ }
+
+ } else {
+
+ // Read the JiBX binding definition into memory. The binding definition
+ // is only prevalidated so as not to require the user to have all
+ // the referenced classes in the classpath, though this does make for
+ // added work in finding the namespaces.
+ ValidationContext vctx = BindingElement.newValidationContext();
+ binding = BindingElement.readBinding(new FileInputStream(file), path, vctx);
+ binding.setBaseUrl(file.toURL());
+ vctx.setBindingRoot(binding);
+ IncludePrevalidationVisitor ipv = new IncludePrevalidationVisitor(vctx);
+ vctx.tourTree(binding, ipv);
+ if (vctx.getErrorCount() != 0 || vctx.getFatalCount() != 0) {
+ throw new RuntimeException("invalid jibx binding definition file " + path);
+ }
}
// create table with all built-in format definitions
@@ -262,8 +293,15 @@
// collect all the top-level mapping and format definitions
Map elementMap = new HashMap();
Map complexTypeMap = new HashMap();
- collectTopLevelComponents(binding, null, elementMap,
- complexTypeMap, simpleTypeMap);
+ if (binding != null) {
+ collectTopLevelComponents(binding, null, elementMap,
+ complexTypeMap, simpleTypeMap);
+ }
+
+ // make sure classes will be generated for abstract mappings
+ if (unwrap && complexTypeMap.size() > 0 && !binding.isForceClasses()) {
+ throw new RuntimeException("unwrapped binding must use force-classes='true' option in " + path);
+ }
// force off inappropriate option (set by error in options handling)
codeGenConfig.setPackClasses(false);
@@ -356,6 +394,9 @@
}
}
}
+ if (mappedclass == null) {
+ mappedclass = "";
+ }
bindinit.setAttribute("bound-class", mappedclass);
details.add(bindinit);
@@ -510,12 +551,21 @@
param.setAttribute("form", "simple");
param.setAttribute("serializer", format.getSerializerName());
param.setAttribute("deserializer", format.getDeserializerName());
- String dflt = element.getDefaultValue();
- if (dflt == null) {
- dflt = format.getDefaultText();
- }
- if (dflt != null) {
- param.setAttribute("default", dflt);
+
+ // convert primitive types to wrapper types for nillable
+ if (element.isNillable() && s_wrapperMap.containsKey(javatype)) {
+ param.setAttribute("wrapped-primitive", "true");
+ param.setAttribute("value-method", javatype + "Value");
+ javatype = (String)s_wrapperMap.get(javatype);
+ } else {
+ param.setAttribute("wrapped-primitive", "false");
+ String dflt = element.getDefaultValue();
+ if (dflt == null) {
+ dflt = format.getDefaultText();
+ }
+ if (dflt != null) {
+ param.setAttribute("default", dflt);
+ }
}
} else {
@@ -613,11 +663,8 @@
}
int count = 0;
String jname = buff.toString();
- if (!nameset.add(jname)) {
- jname = "_" + jname;
- while (!nameset.add(jname)) {
- jname = buff.toString() + count++;
- }
+ while (!nameset.add(jname)) {
+ jname = buff.toString() + count++;
}
return jname;
}
Added: webservices/axis2/branches/java/1_1/modules/jibx/src/org/apache/axis2/jibx/NullBindingFactory.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_1/modules/jibx/src/org/apache/axis2/jibx/NullBindingFactory.java?view=auto&rev=473929
==============================================================================
--- webservices/axis2/branches/java/1_1/modules/jibx/src/org/apache/axis2/jibx/NullBindingFactory.java (added)
+++ webservices/axis2/branches/java/1_1/modules/jibx/src/org/apache/axis2/jibx/NullBindingFactory.java Sun Nov 12 03:24:28 2006
@@ -0,0 +1,56 @@
+package org.apache.axis2.jibx;
+
+import org.jibx.runtime.IBindingFactory;
+import org.jibx.runtime.IMarshallingContext;
+import org.jibx.runtime.IUnmarshallingContext;
+import org.jibx.runtime.JiBXException;
+import org.jibx.runtime.impl.MarshallingContext;
+import org.jibx.runtime.impl.UnmarshallingContext;
+
+public class NullBindingFactory implements IBindingFactory {
+
+ private static final String[] EMPTY_STRINGS = new String[0];
+
+ public IMarshallingContext createMarshallingContext() throws JiBXException {
+ return new MarshallingContext(EMPTY_STRINGS, EMPTY_STRINGS, EMPTY_STRINGS, this);
+ }
+
+ public IUnmarshallingContext createUnmarshallingContext()
+ throws JiBXException {
+ return new UnmarshallingContext(0, EMPTY_STRINGS, EMPTY_STRINGS, EMPTY_STRINGS, EMPTY_STRINGS, this);
+ }
+
+ public String getCompilerDistribution() {
+ // normally only used by BindingDirectory code, so okay to punt
+ return "";
+ }
+
+ public int getCompilerVersion() {
+ // normally only used by BindingDirectory code, so okay to punt
+ return 0;
+ }
+
+ public String[] getElementNames() {
+ return EMPTY_STRINGS;
+ }
+
+ public String[] getElementNamespaces() {
+ return EMPTY_STRINGS;
+ }
+
+ public String[] getMappedClasses() {
+ return EMPTY_STRINGS;
+ }
+
+ public String[] getNamespaces() {
+ return EMPTY_STRINGS;
+ }
+
+ public String[] getPrefixes() {
+ return EMPTY_STRINGS;
+ }
+
+ public int getTypeIndex(String type) {
+ return -1;
+ }
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org