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 sc...@apache.org on 2009/11/25 23:03:08 UTC
svn commit: r884291 - in /webservices/axis2/trunk/java/modules/jaxws:
src/org/apache/axis2/jaxws/runtime/description/marshal/impl/
src/org/apache/axis2/jaxws/utility/ src/org/apache/axis2/jaxws/wsdl/impl/
test/org/apache/axis2/jaxws/misc/
Author: scheu
Date: Wed Nov 25 22:03:07 2009
New Revision: 884291
URL: http://svn.apache.org/viewvc?rev=884291&view=rev
Log:
AXIS2-4565
Contributor:Rich Scheuerle
A) Examine the namespace on the @RequestWrapper and @ResponseWrapper (if provided) to calculate the
packages needed for JAXBContext construction.
B) WSImport has a slight behavior for NS->PKG than the rule defined in the JAXB spec. WSImport
prepends a "_" to names that conflict with java keywords. The JAXB spec appends a "_".
The code is changed to tolerate both styles.
Plus a verification unit test for B.
Modified:
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/marshal/impl/PackageSetBuilder.java
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/JavaUtils.java
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/wsdl/impl/SchemaReaderImpl.java
webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/misc/NS2PkgTest.java
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/marshal/impl/PackageSetBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/marshal/impl/PackageSetBuilder.java?rev=884291&r1=884290&r2=884291&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/marshal/impl/PackageSetBuilder.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/marshal/impl/PackageSetBuilder.java Wed Nov 25 22:03:07 2009
@@ -59,6 +59,7 @@
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.Collection;
+import java.util.List;
import java.util.Set;
import java.util.TreeSet;
@@ -309,6 +310,25 @@
if (responseWrapperPkg != null) {
set.add(responseWrapperPkg);
}
+
+ // The wrapper class and the element defining the wrapper may be
+ // in different namespaces and packages. So also look at the namespaces.
+ String ns = opDesc.getRequestWrapperTargetNamespace();
+ if (ns != null && ns.length() > 0) {
+ if (log.isDebugEnabled()) {
+ log.debug("TargetNamespace from Request Wrapper annotation = " + ns);
+ }
+ List packages = makePackages(ns);
+ set.addAll(packages);
+ }
+ ns = opDesc.getResponseWrapperTargetNamespace();
+ if (ns != null && ns.length() > 0) {
+ if (log.isDebugEnabled()) {
+ log.debug("TargetNamespace from Response Wrapper annotation = " + ns);
+ }
+ List packages = makePackages(ns);
+ set.addAll(packages);
+ }
// In most doc/literal cases, the @RequestWrapper or @ResponseWrapper classes are successfully found.
// The wrapper classes contain the representation of the parameters, thus the parameters don't need
@@ -458,9 +478,9 @@
// in doc/lit wrapped. The package is determined from the wrapper element in such casses.
if (namespace != null && namespace.length() > 0) {
// Use default namespace to package algorithm
- String pkg = makePackage(namespace);
- if (pkg != null) {
- set.add(pkg);
+ List pkgs = makePackages(namespace);
+ if (pkgs != null) {
+ set.addAll(pkgs);
}
}
} else {
@@ -521,12 +541,12 @@
* Default Namespace to Package algorithm
*
* @param ns
- * @return
+ * @return List of one or more packages
*/
- private static String makePackage(String ns) {
- String pkgName = JavaUtils.getPackageFromNamespace(ns);
- return pkgName;
- }
+ private static List makePackages(String ns) {
+ List packages = JavaUtils.getPackagesFromNamespace(ns);
+ return packages;
+ }
/**
* Return the package associated with the class name. The className may not be specified (in
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/JavaUtils.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/JavaUtils.java?rev=884291&r1=884290&r2=884291&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/JavaUtils.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/JavaUtils.java Wed Nov 25 22:03:07 2009
@@ -28,6 +28,7 @@
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
+import java.util.List;
import java.util.StringTokenizer;
/** Common Java Utilites */
@@ -39,13 +40,44 @@
private JavaUtils() {
}
+
+ /**
+ * @param namespace
+ * @return List of String containing 1 or 2 packages
+ */
+ public static List getPackagesFromNamespace(String namespace) {
+ List list = new ArrayList();
+ // Get a package using JAXB Rules
+ String jaxbPkg = getPackageFromNamespace(namespace, true);
+ list.add(jaxbPkg);
+ if (jaxbPkg.contains("_")) {
+ if (log.isDebugEnabled()) {
+ log.debug("Calling getPackageFromNamespace with wsimport rule:" + namespace);
+ }
+ String altPkg = getPackageFromNamespace(namespace, false); // Using wsimport rule
+ list.add(altPkg);
+ }
+ return list;
+ }
+
/**
* Namespace 2 Package algorithm as defined by the JAXB Specification
*
* @param Namespace
- * @return String represeting Namespace
+ * @return String representing Namespace
+ * @see getPackagesFromNamespace
*/
public static String getPackageFromNamespace(String namespace) {
+ return getPackageFromNamespace(namespace, true);
+ }
+
+ /**
+ * @param Namespace
+ * @param apend underscore to keyword
+ * @return String representing Namespace
+ */
+ public static String getPackageFromNamespace(String namespace,
+ boolean appendUnderscoreToKeyword) {
// The following steps correspond to steps described in the JAXB Specification
if (log.isDebugEnabled()) {
@@ -151,7 +183,11 @@
// 8b: Append _ to java keywords
if (JavaUtils.isJavaKeyword(word)) {
- word = word + "_";
+ if (appendUnderscoreToKeyword) {
+ word = word + "_"; // This is defined by the JAXB Spec
+ } else {
+ word = "_" +word; // Apparently wsimport can generate this style
+ }
}
// 8c: prepend _ if first character cannot be the first character of a java identifier
if (!Character.isJavaIdentifierStart(word.charAt(0))) {
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/wsdl/impl/SchemaReaderImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/wsdl/impl/SchemaReaderImpl.java?rev=884291&r1=884290&r2=884291&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/wsdl/impl/SchemaReaderImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/wsdl/impl/SchemaReaderImpl.java Wed Nov 25 22:03:07 2009
@@ -79,8 +79,10 @@
Set<String> packageList = new TreeSet<String>();
//Add WSDL TargetNamespace
String namespace = wsdlDefinition.getTargetNamespace();
- String packageString = JavaUtils.getPackageFromNamespace(namespace);
- packageList.add(packageString);
+ List packages = JavaUtils.getPackagesFromNamespace(namespace);
+ if (packages != null && packages.size() > 0) {
+ packageList.addAll(packages);
+ }
//Read All Schema Definition in wsdl;
Types types = wsdlDefinition.getTypes();
@@ -114,6 +116,7 @@
//Check if there is Binding customization and read package from it.
String packageString = readSchemaBindingPackageName(schema);
//No binding customization present then get the Targetnamespace of Schema
+ List packages = null;
if (packageString == null) {
//no Schema Binding package name found, this means no jaxb customizations in schema, lets read wsdl
//targetnamespace. Thats what will be used by RI tooling to store java Beans
@@ -127,7 +130,7 @@
return;
}
if (namespace != null) {
- packageString = JavaUtils.getPackageFromNamespace(namespace);
+ packages = JavaUtils.getPackagesFromNamespace(namespace);
}
}
//Gather all imports and process Schema from these imports
@@ -152,6 +155,9 @@
if (packageString != null) {
packageList.add(packageString);
}
+ if (packages != null && packages.size() > 0) {
+ packageList.addAll(packages);
+ }
for (SchemaImport si : importList) {
processImport(si, schemaList, packageList);
}
Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/misc/NS2PkgTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/misc/NS2PkgTest.java?rev=884291&r1=884290&r2=884291&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/misc/NS2PkgTest.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/misc/NS2PkgTest.java Wed Nov 25 22:03:07 2009
@@ -23,6 +23,7 @@
package org.apache.axis2.jaxws.misc;
import junit.framework.TestCase;
+import java.util.List;
import org.apache.axis2.jaxws.utility.JavaUtils;
/**
@@ -35,8 +36,24 @@
String ns1 = "http://example.org/NewBusiness/";
String expectedPkg1 = "org.example.newbusiness";
- String pkg = JavaUtils.getPackageFromNamespace(ns1);
- assertTrue("Expected " + expectedPkg1 + "Received " +pkg, expectedPkg1.equals(pkg));
+ // Test legacy utility method
+ String packageString = JavaUtils.getPackageFromNamespace(ns1);
+ assertTrue(expectedPkg1.equals(packageString));
+
+ // Test new utility method
+ List pkgs = JavaUtils.getPackagesFromNamespace(ns1);
+ assertTrue(pkgs.size() == 1);
+ assertTrue(expectedPkg1.equals(pkgs.get(0)));
+
+ String ns2 = "http://interface.org/NewBusiness/";
+ String expectedPkg2_jaxb = "org.interface_.newbusiness";
+ String expectedPkg2_other = "org._interface.newbusiness";
+
+ // Test new utility for a case where 2 packages will be returned.
+ pkgs = JavaUtils.getPackagesFromNamespace(ns2);
+ assertTrue(pkgs.size() == 2);
+ assertTrue(expectedPkg2_jaxb.equals(pkgs.get(0)));
+ assertTrue(expectedPkg2_other.equals(pkgs.get(1)));
}
public void test02() throws Exception {