From 19e2a4048613e0c5bc00ba7d67ebf14cf0baa291 Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Wed, 17 Sep 2008 05:40:57 +0000 Subject: Fix TUSCANY-2531 git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@696156 13f79535-47bb-0310-9956-ffa450edef68 --- .../ws/wsdlgen/Interface2WSDLGenerator.java | 10 +++--- .../sca/databinding/jaxb/JAXBContextHelper.java | 39 +++++++++++++++++++--- .../sca/databinding/jaxb/JAXBTypeHelper.java | 33 +----------------- 3 files changed, 42 insertions(+), 40 deletions(-) diff --git a/branches/sca-equinox/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/Interface2WSDLGenerator.java b/branches/sca-equinox/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/Interface2WSDLGenerator.java index c84e2e3ebe..933534cc79 100644 --- a/branches/sca-equinox/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/Interface2WSDLGenerator.java +++ b/branches/sca-equinox/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/Interface2WSDLGenerator.java @@ -400,18 +400,20 @@ public class Interface2WSDLGenerator { if ("".equals(nsURI)) { xsElement.setAttribute("type", typeName.getLocalPart()); addSchemaImport(schema, "", schemaDoc); - } else if (targetNS.equals(nsURI)) { - xsElement.setAttribute("type", typeName.getLocalPart()); } else if (SCHEMA_NS.equals(nsURI)) { xsElement.setAttribute("type", "xs:" + typeName.getLocalPart()); } else { Map prefixMap = prefixMaps.get(schema); String prefix = prefixMap.get(nsURI); if (prefix == null) { - prefix = "ns" + i++; + if (targetNS.equals(nsURI)) { + prefix = "tns"; + } else { + prefix = "ns" + i++; + addSchemaImport(schema, nsURI, schemaDoc); + } prefixMap.put(nsURI, prefix); schema.setAttributeNS(XMLNS_NS, "xmlns:" + prefix, nsURI); - addSchemaImport(schema, nsURI, schemaDoc); } xsElement.setAttribute("type", prefix + ":" + typeName.getLocalPart()); } diff --git a/branches/sca-equinox/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextHelper.java b/branches/sca-equinox/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextHelper.java index 6d66f10a8e..ef832bfb68 100644 --- a/branches/sca-equinox/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextHelper.java +++ b/branches/sca-equinox/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextHelper.java @@ -18,7 +18,6 @@ */ package org.apache.tuscany.sca.databinding.jaxb; -import java.beans.Introspector; import java.io.IOException; import java.lang.reflect.GenericArrayType; import java.lang.reflect.ParameterizedType; @@ -374,7 +373,7 @@ public class JAXBContextHelper { elementNamespace = namespace; } if (elementName.equals("##default")) { - elementName = Introspector.decapitalize(javaType.getSimpleName()); + elementName = jaxbDecapitalize(javaType.getSimpleName()); } elementQName = new QName(elementNamespace, elementName); } @@ -389,13 +388,13 @@ public class JAXBContextHelper { } if (typeName.equals("##default")) { - typeName = Introspector.decapitalize(javaType.getSimpleName()); + typeName = jaxbDecapitalize(javaType.getSimpleName()); } typeQName = new QName(typeNamespace, typeName); } else { XmlEnum xmlEnum = javaType.getAnnotation(XmlEnum.class); if (xmlEnum != null) { - name = Introspector.decapitalize(javaType.getSimpleName()); + name = jaxbDecapitalize(javaType.getSimpleName()); typeQName = new QName(namespace, name); } } @@ -405,6 +404,38 @@ public class JAXBContextHelper { return new XMLType(elementQName, typeQName); } + /** + * The JAXB RI doesn't implement the decapitalization algorithm in the + * JAXB spec. See Sun bug 6505643 for details. This means that instead + * of calling java.beans.Introspector.decapitalize() as the JAXB spec says, + * Tuscany needs to mimic the incorrect JAXB RI algorithm. + */ + public static String jaxbDecapitalize(String name) { + // find first lower case char in name + int lower = name.length(); + for (int i = 0; i < name.length(); i++) { + if (Character.isLowerCase(name.charAt(i))) { + lower = i; + break; + } + } + + int decap; + if (name.length() == 0) { + decap = 0; // empty string: nothing to do + } else if (lower == 0) { + decap = 0; // first char is lower case: nothing to do + } else if (lower == 1) { + decap = 1; // one upper followed by lower: decapitalize 1 char + } else if (lower < name.length()) { + decap = lower - 1; // n uppers followed by at least one lower: decapitalize n-1 chars + } else { + decap = name.length(); // all upper case: decapitalize all chars + } + + return name.substring(0, decap).toLowerCase() + name.substring(decap); + } + public static Node generateSchema(JAXBContext context) throws Exception { SchemaOutputResolverImpl resolver = new SchemaOutputResolverImpl(); context.generateSchema(resolver); diff --git a/branches/sca-equinox/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBTypeHelper.java b/branches/sca-equinox/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBTypeHelper.java index 573e636884..a60a882801 100644 --- a/branches/sca-equinox/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBTypeHelper.java +++ b/branches/sca-equinox/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBTypeHelper.java @@ -73,43 +73,12 @@ public class JAXBTypeHelper implements XMLTypeHelper { xmlType = ((XMLType)logical).getTypeName(); } if (xmlType == null) { - xmlType = new QName(jaxbRIDecapitalize(javaType.getSimpleName())); + xmlType = new QName(JAXBContextHelper.jaxbDecapitalize(javaType.getSimpleName())); } return new TypeInfo(xmlType, false, null); } } - /** - * The JAXB RI doesn't implement the decapitalization algorithm in the - * JAXB spec. See Sun bug 6505643 for details. This means that we need - * to mimic the incorrect algorithm for references from wrapper schemas. - */ - private String jaxbRIDecapitalize(String name) { - // find first lower case char in name - int lower = name.length(); - for (int i = 0; i < name.length(); i++) { - if (Character.isLowerCase(name.charAt(i))) { - lower = i; - break; - } - } - - int decap; - if (name.length() == 0) { - decap = 0; // empty string: nothing to do - } else if (lower == 0) { - decap = 0; // first char is lower case: nothing to do - } else if (lower == 1) { - decap = 1; // one upper followed by lower: decapitalize 1 char - } else if (lower < name.length()) { - decap = lower - 1; // n uppers followed by at least one lower: decapitalize n-1 chars - } else { - decap = name.length(); // all upper case: decapitalize all chars - } - - return name.substring(0, decap).toLowerCase() + name.substring(decap); - } - /* public List getSchemaDefinitions(XSDFactory factory, ModelResolver resolver) { List definitions = new ArrayList(); -- cgit v1.2.3