Return-Path: X-Original-To: apmail-axis-java-commits-archive@minotaur.apache.org Delivered-To: apmail-axis-java-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C00B26BF2 for ; Thu, 16 Jun 2011 14:06:59 +0000 (UTC) Received: (qmail 42728 invoked by uid 500); 16 Jun 2011 14:06:59 -0000 Delivered-To: apmail-axis-java-commits-archive@axis.apache.org Received: (qmail 42705 invoked by uid 500); 16 Jun 2011 14:06:59 -0000 Mailing-List: contact java-commits-help@axis.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: java-dev@axis.apache.org Delivered-To: mailing list java-commits@axis.apache.org Received: (qmail 42698 invoked by uid 99); 16 Jun 2011 14:06:59 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 16 Jun 2011 14:06:59 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 16 Jun 2011 14:06:53 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 9380B23889C5; Thu, 16 Jun 2011 14:06:31 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1136443 - in /axis/axis2/java/core/trunk/modules: adb/src/org/apache/axis2/databinding/typemapping/ adb/src/org/apache/axis2/databinding/utils/ adb/src/org/apache/axis2/rpc/receivers/ adb/test/org/apache/axis2/databinding/utils/ kernel/src... Date: Thu, 16 Jun 2011 14:06:31 -0000 To: java-commits@axis.apache.org From: sagara@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110616140631.9380B23889C5@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: sagara Date: Thu Jun 16 14:06:30 2011 New Revision: 1136443 URL: http://svn.apache.org/viewvc?rev=1136443&view=rev Log: Fixed AXIS2-5063 Provide support for complex object types. 1.) Added mapping between XSD types to Java types in TypeTable . 2.) Modified BeanUtil and RPCUtil to include xsd:type details in response messages when returning a Object or Object Array. 3.) Created new test case - TypeTableTest and enhanced BeanUtilTest. 4.) Modified RPCMessageReceivers to support 2.) 5.) Updated osgi module pom file to import javax.xml.datatype package . Added: axis/axis2/java/core/trunk/modules/kernel/test/org/apache/axis2/description/java2wsdl/TypeTableTest.java (with props) Modified: axis/axis2/java/core/trunk/modules/adb/src/org/apache/axis2/databinding/typemapping/SimpleTypeMapper.java axis/axis2/java/core/trunk/modules/adb/src/org/apache/axis2/databinding/utils/BeanUtil.java axis/axis2/java/core/trunk/modules/adb/src/org/apache/axis2/databinding/utils/Constants.java axis/axis2/java/core/trunk/modules/adb/src/org/apache/axis2/rpc/receivers/RPCInOutAsyncMessageReceiver.java axis/axis2/java/core/trunk/modules/adb/src/org/apache/axis2/rpc/receivers/RPCMessageReceiver.java axis/axis2/java/core/trunk/modules/adb/src/org/apache/axis2/rpc/receivers/RPCUtil.java axis/axis2/java/core/trunk/modules/adb/test/org/apache/axis2/databinding/utils/BeanUtilTest.java axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/description/java2wsdl/TypeTable.java axis/axis2/java/core/trunk/modules/osgi/pom.xml Modified: axis/axis2/java/core/trunk/modules/adb/src/org/apache/axis2/databinding/typemapping/SimpleTypeMapper.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/adb/src/org/apache/axis2/databinding/typemapping/SimpleTypeMapper.java?rev=1136443&r1=1136442&r2=1136443&view=diff ============================================================================== --- axis/axis2/java/core/trunk/modules/adb/src/org/apache/axis2/databinding/typemapping/SimpleTypeMapper.java (original) +++ axis/axis2/java/core/trunk/modules/adb/src/org/apache/axis2/databinding/typemapping/SimpleTypeMapper.java Thu Jun 16 14:06:30 2011 @@ -19,10 +19,12 @@ package org.apache.axis2.databinding.typemapping; +import org.apache.axiom.attachments.ByteArrayDataSource; import org.apache.axiom.attachments.utils.DataHandlerUtils; import org.apache.axiom.om.OMElement; import org.apache.axiom.om.OMNode; import org.apache.axiom.om.OMText; +import org.apache.axis2.databinding.types.HexBinary; import org.apache.axis2.databinding.utils.ConverterUtil; import org.apache.axis2.context.MessageContext; import org.apache.axis2.description.AxisService; @@ -188,6 +190,22 @@ public class SimpleTypeMapper { } } return null; + } + + /** + * Gets the DataHandler according to hexBin value. + * + * @param element the element + * @param hexBin the hex bin + * @return the DataHandler object + */ + public static DataHandler getDataHandler(OMElement element, boolean hexBin) { + if(hexBin){ + ByteArrayDataSource byteArrayDataSource = new ByteArrayDataSource( + HexBinary.decode(element.getText())); + return new DataHandler(byteArrayDataSource); + } + return getDataHandler(element); } @@ -327,5 +345,32 @@ public class SimpleTypeMapper { public static Object makeDate(String source) { return ConverterUtil.convertToDate(source); } + + + /** + * Checks weather passed parameter class is java.lang.Object[] or not. + * + * @param obj the Class type of particular object. + * @return true, if is object array + */ + public static boolean isObjectArray(Class obj) { + if (obj.getComponentType().getName().equals(Object.class.getName())) { + return true; + } + return false; + } + + /** + * Checks weather passed parameter class is java.lang.Object or not. + * + * @param obj the Class type of particular object. + * @return true, if is object type + */ + public static boolean isObjectType(Class obj) { + if (obj.getName().equals(Object.class.getName())) { + return true; + } + return false; + } } Modified: axis/axis2/java/core/trunk/modules/adb/src/org/apache/axis2/databinding/utils/BeanUtil.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/adb/src/org/apache/axis2/databinding/utils/BeanUtil.java?rev=1136443&r1=1136442&r2=1136443&view=diff ============================================================================== --- axis/axis2/java/core/trunk/modules/adb/src/org/apache/axis2/databinding/utils/BeanUtil.java (original) +++ axis/axis2/java/core/trunk/modules/adb/src/org/apache/axis2/databinding/utils/BeanUtil.java Thu Jun 16 14:06:30 2011 @@ -38,6 +38,7 @@ import java.util.List; import java.util.Map; import java.util.TreeMap; +import javax.activation.DataHandler; import javax.xml.namespace.QName; import javax.xml.stream.XMLStreamReader; @@ -256,15 +257,23 @@ public class BeanUtil { } else { addTypeQname(elemntNameSpace, propertyQnameValueList, property, beanName, processingDocLitBare); - if (Object.class.equals(ptype)) { - if ((value instanceof Integer) || - (value instanceof Short) || - (value instanceof Long) || - (value instanceof Float)) { - propertyQnameValueList.add(value.toString()); - continue; - } - } + if (Object.class.equals(ptype)) { + //this is required to match this element prefix as + //root element's prefix. + QName qNamefortheType = (QName) typeTable + .getComplexSchemaMap().get( + getClassName(beanClass)); + OMFactory fac = OMAbstractFactory.getOMFactory(); + OMElement element = fac + .createOMElement(new QName(elemntNameSpace + .getNamespaceURI(), property.getName(), + qNamefortheType.getPrefix())); + element.addChild(fac.createOMText(SimpleTypeMapper + .getStringValue(value))); + addInstanceTypeAttribute(fac, element, value, typeTable); + propertyQnameValueList.add(element); + continue; + } propertyQnameValueList.add(value); } @@ -329,6 +338,7 @@ public class BeanUtil { // and retrieve the class. String instanceTypeName = beanElement.getAttributeValue(new QName(Constants.XSI_NAMESPACE, "type")); + boolean hexBin = false; if (instanceTypeName != null) { MessageContext messageContext = MessageContext.getCurrentMessageContext(); // we can have this support only at the server side. we need to find the axisservice @@ -337,6 +347,10 @@ public class BeanUtil { AxisService axisService = messageContext.getAxisService(); if (axisService != null) { QName typeQName = beanElement.resolveQName(instanceTypeName); + //Need this flag to differentiate "xsd:hexBinary" and "xsd:base64Binary" data. + if(org.apache.ws.commons.schema.constants.Constants.XSD_HEXBIN.equals(typeQName)){ + hexBin = true; + } TypeTable typeTable = axisService.getTypeTable(); String className = typeTable.getClassNameForQName(typeQName); if (className != null) { @@ -357,6 +371,10 @@ public class BeanUtil { if (beanElement.getAttribute(nilAttName) != null) { return null; } + + if(beanClass.getName().equals(DataHandler.class.getName())){ + return SimpleTypeMapper.getDataHandler(beanElement,hexBin); + } if (beanClass.isArray()) { ArrayList valueList = new ArrayList(); @@ -884,13 +902,22 @@ public class BeanUtil { } } else { - if (SimpleTypeMapper.isSimpleType(arg)) { - if (partName == null) { - objects.add("arg" + argCount); - } else { - objects.add(partName); - } - objects.add(SimpleTypeMapper.getStringValue(arg)); + if (SimpleTypeMapper.isSimpleType(arg)) { + OMElement element; + OMFactory fac = OMAbstractFactory.getOMFactory(); + if(partName != null){ + element = fac.createOMElement(partName, null); + }else{ + String eleName = "arg" + argCount; + element = fac.createOMElement(eleName, null); + } + element.addChild(fac.createOMText(SimpleTypeMapper + .getStringValue(arg))); + if (SimpleTypeMapper.isObjectArray(args.getClass())) { + addInstanceTypeAttribute(fac, element, arg, typeTable); + } + objects.add(element.getQName()); + objects.add(element); } else { if (partName == null) { objects.add(new QName("arg" + argCount)); @@ -981,5 +1008,40 @@ public class BeanUtil { omElement.getLocalName(), faultCode, e); } } + + /** + * Adds the instance type attribute to the passed OMElement. + * + * e.g - + * String Value + * + * + * + * @param fac the SOAPFactory instance. + * @param child the child OMElement to add attributes. + * @param method the java reflection method + * @param resObject the res object + * @param typeTable the type table of particular Axis2 service + */ + public static void addInstanceTypeAttribute(OMFactory fac, + OMElement element, Object resObject, + TypeTable typeTable) { + if(typeTable == null){ + return; + } + OMNamespace xsiNS = fac.createOMNamespace(Constants.XSI_NAMESPACE, + Constants.DEFAULT_XSI_NAMESPACE_PREFIX); + OMNamespace xsdNS = fac.createOMNamespace(Constants.XSD_NAMESPACE, + Constants.DEFAULT_XSD_NAMESPACE_PREFIX); + element.declareNamespace(xsiNS); + element.declareNamespace(xsdNS); + QName xsdType = typeTable.getSimpleSchemaTypeName(resObject.getClass() + .getName()); + String attrValue = xsdType.getPrefix() + ":" + xsdType.getLocalPart(); + element.addAttribute(Constants.XSI_TYPE_ATTRIBUTE, attrValue, xsiNS); + } + } Modified: axis/axis2/java/core/trunk/modules/adb/src/org/apache/axis2/databinding/utils/Constants.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/adb/src/org/apache/axis2/databinding/utils/Constants.java?rev=1136443&r1=1136442&r2=1136443&view=diff ============================================================================== --- axis/axis2/java/core/trunk/modules/adb/src/org/apache/axis2/databinding/utils/Constants.java (original) +++ axis/axis2/java/core/trunk/modules/adb/src/org/apache/axis2/databinding/utils/Constants.java Thu Jun 16 14:06:30 2011 @@ -29,6 +29,9 @@ public interface Constants { static String TRUE = "true"; static String XSI_NAMESPACE = "http://www.w3.org/2001/XMLSchema-instance"; static String XSD_NAMESPACE = "http://www.w3.org/2001/XMLSchema"; + static String XSI_TYPE_ATTRIBUTE = "type"; + static String DEFAULT_XSI_NAMESPACE_PREFIX = "xsi"; + static String DEFAULT_XSD_NAMESPACE_PREFIX = "xs"; static Object OM_ATTRIBUTE_KEY = new OMAttribKey(); static Object OM_ELEMENT_KEY = new OMElementKey(); Modified: axis/axis2/java/core/trunk/modules/adb/src/org/apache/axis2/rpc/receivers/RPCInOutAsyncMessageReceiver.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/adb/src/org/apache/axis2/rpc/receivers/RPCInOutAsyncMessageReceiver.java?rev=1136443&r1=1136442&r2=1136443&view=diff ============================================================================== --- axis/axis2/java/core/trunk/modules/adb/src/org/apache/axis2/rpc/receivers/RPCInOutAsyncMessageReceiver.java (original) +++ axis/axis2/java/core/trunk/modules/adb/src/org/apache/axis2/rpc/receivers/RPCInOutAsyncMessageReceiver.java Thu Jun 16 14:06:30 2011 @@ -123,7 +123,7 @@ public class RPCInOutAsyncMessageReceive Parameter generateBare = service.getParameter(Java2WSDLConstants.DOC_LIT_BARE_PARAMETER); if (generateBare!=null && "true".equals(generateBare.getValue())) { RPCUtil.processResonseAsDocLitBare(resObject, service, - envelope, fac, ns, + method, envelope, fac, ns, bodyContent, outMessage); } else { RPCUtil.processResponseAsDocLitWrapped(resObject, service, Modified: axis/axis2/java/core/trunk/modules/adb/src/org/apache/axis2/rpc/receivers/RPCMessageReceiver.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/adb/src/org/apache/axis2/rpc/receivers/RPCMessageReceiver.java?rev=1136443&r1=1136442&r2=1136443&view=diff ============================================================================== --- axis/axis2/java/core/trunk/modules/adb/src/org/apache/axis2/rpc/receivers/RPCMessageReceiver.java (original) +++ axis/axis2/java/core/trunk/modules/adb/src/org/apache/axis2/rpc/receivers/RPCMessageReceiver.java Thu Jun 16 14:06:30 2011 @@ -147,7 +147,7 @@ public class RPCMessageReceiver extends Parameter generateBare = service.getParameter(Java2WSDLConstants.DOC_LIT_BARE_PARAMETER); if (generateBare!=null && "true".equals(generateBare.getValue())) { RPCUtil.processResonseAsDocLitBare(resObject, service, - envelope, fac, ns, + method, envelope, fac, ns, bodyContent, outMessage); } else { RPCUtil.processResponseAsDocLitWrapped(resObject, service, Modified: axis/axis2/java/core/trunk/modules/adb/src/org/apache/axis2/rpc/receivers/RPCUtil.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/adb/src/org/apache/axis2/rpc/receivers/RPCUtil.java?rev=1136443&r1=1136442&r2=1136443&view=diff ============================================================================== --- axis/axis2/java/core/trunk/modules/adb/src/org/apache/axis2/rpc/receivers/RPCUtil.java (original) +++ axis/axis2/java/core/trunk/modules/adb/src/org/apache/axis2/rpc/receivers/RPCUtil.java Thu Jun 16 14:06:30 2011 @@ -45,7 +45,6 @@ import javax.xml.stream.XMLStreamReader; import java.lang.reflect.Array; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.lang.reflect.Type; import java.util.Collection; public class RPCUtil { @@ -84,6 +83,7 @@ public class RPCUtil { child = fac.createOMElement(RETURN_WRAPPER, null); } child.addChild(fac.createOMText(child, SimpleTypeMapper.getStringValue(resObject))); + addInstanceTypeInfo(fac, child, method, resObject, typeTable); bodyContent.addChild(child); } else { bodyContent = fac.createOMElement( @@ -115,6 +115,7 @@ public class RPCUtil { Object resObject, OMElement bodyContent, OMNamespace ns, + Method method, SOAPEnvelope envelope, boolean qualified, TypeTable typeTable, @@ -127,6 +128,7 @@ public class RPCUtil { } else if (SimpleTypeMapper.isSimpleType(resObject)) { bodyContent = fac.createOMElement( partName, ns); + addInstanceTypeInfo(fac, bodyContent, method, resObject, typeTable); bodyContent.addChild(fac.createOMText(bodyContent, SimpleTypeMapper.getStringValue(resObject))); } else { @@ -145,6 +147,15 @@ public class RPCUtil { envelope.getBody().addChild(bodyContent); } } + + public static void processObjectAsDocLitBare(SOAPFactory fac, + Object resObject, OMElement bodyContent, OMNamespace ns, + SOAPEnvelope envelope, boolean qualified, TypeTable typeTable, + String partName) { + processObjectAsDocLitBare(fac, resObject, bodyContent, ns, null, + envelope, qualified, typeTable, partName); + + } public static Object[] processRequest(OMElement methodElement, Method method, ObjectSupplier objectSupplier, String[] parameterNames) @@ -234,6 +245,7 @@ public class RPCUtil { public static void processResonseAsDocLitBare(Object resObject, AxisService service, + Method method, SOAPEnvelope envelope, SOAPFactory fac, OMNamespace ns, @@ -311,6 +323,7 @@ public class RPCUtil { resObject, bodyContent, ns, + method, envelope, service.isElementFormDefault(), service.getTypeTable(), @@ -320,6 +333,7 @@ public class RPCUtil { resObject, bodyContent, ns, + method, envelope, service.isElementFormDefault(), null, @@ -331,7 +345,16 @@ public class RPCUtil { } outMessage.setEnvelope(envelope); } + + public static void processResonseAsDocLitBare(Object resObject, + AxisService service, SOAPEnvelope envelope, SOAPFactory fac, + OMNamespace ns, OMElement bodyContent, MessageContext outMessage) + throws Exception { + processResonseAsDocLitBare(resObject, service, null, envelope, fac, ns, + bodyContent, outMessage); + } + /** * This method is use to to crete the reposne when , the return value is null * @@ -469,4 +492,14 @@ public class RPCUtil { } outMessage.setEnvelope(envelope); } + + private static void addInstanceTypeInfo(SOAPFactory fac, OMElement element, + Method method, Object resObject, TypeTable typeTable) { + Class returnType = method.getReturnType(); + // add instanceTypeInfo only if return type is java.lang.Object + if (SimpleTypeMapper.isObjectType(returnType)) { + BeanUtil.addInstanceTypeAttribute(fac, element, resObject, + typeTable); + } + } } Modified: axis/axis2/java/core/trunk/modules/adb/test/org/apache/axis2/databinding/utils/BeanUtilTest.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/adb/test/org/apache/axis2/databinding/utils/BeanUtilTest.java?rev=1136443&r1=1136442&r2=1136443&view=diff ============================================================================== --- axis/axis2/java/core/trunk/modules/adb/test/org/apache/axis2/databinding/utils/BeanUtilTest.java (original) +++ axis/axis2/java/core/trunk/modules/adb/test/org/apache/axis2/databinding/utils/BeanUtilTest.java Thu Jun 16 14:06:30 2011 @@ -23,6 +23,7 @@ import org.apache.axiom.om.*; import org.apache.axiom.soap.SOAPFactory; import org.apache.axis2.AxisFault; import org.apache.axis2.context.MessageContext; +import org.apache.axis2.description.AxisService; import org.apache.axis2.description.java2wsdl.TypeTable; import org.apache.axis2.engine.DefaultObjectSupplier; import org.apache.axis2.engine.ObjectSupplier; @@ -33,6 +34,8 @@ import javax.activation.DataHandler; import javax.mail.util.ByteArrayDataSource; import javax.xml.namespace.QName; +import java.io.ByteArrayInputStream; +import java.math.BigInteger; import java.util.List; @@ -66,7 +69,6 @@ public class BeanUtilTest extends TestCa MessageContext msgContext = new MessageContext(); msgContext.setEnvelope(omFactory.createSOAPEnvelope()); - MessageContext.setCurrentMessageContext(msgContext); } @@ -186,4 +188,83 @@ public class BeanUtilTest extends TestCa assertTrue(e.getMessage().contains("Brisbane")); } } + + public void testDeserializeWithArrayLocalNameForString() throws Exception { + omElement.declareNamespace(omFactory.createOMNamespace(Constants.XSD_NAMESPACE, "xs")); + + omElement.setText("World"); + omElement.addAttribute(createTypeAttribute("xs:string")); + + Object result = BeanUtil.deserialize(String.class, omElement, objectSupplier, null); + assertNotNull("Result can not be null",result); + assertEquals("Not the expected Class",String.class,result.getClass()); + assertEquals("Not the expected value","World",result); + + } + + public void testDeserializeWithArrayLocalNameForInt() throws Exception { + omElement.declareNamespace(omFactory.createOMNamespace(Constants.XSD_NAMESPACE, "xs")); + + omElement.setText("1000"); + omElement.addAttribute(createTypeAttribute("xs:int")); + + Object result = BeanUtil.deserialize(Integer.class, omElement, objectSupplier, null); + assertNotNull("Result can not be null",result); + assertEquals("Not the expected Class",Integer.class,result.getClass()); + assertEquals("Not the expected value",1000,result); + + } + public void testDeserializeWithArrayLocalNameForInteger() throws Exception { + omElement.declareNamespace(omFactory.createOMNamespace(Constants.XSD_NAMESPACE, "xs")); + + omElement.setText("100000"); + omElement.addAttribute(createTypeAttribute("xs:integer")); + + Object result = BeanUtil.deserialize(BigInteger.class, omElement, objectSupplier, null); + assertNotNull("Result can not be null",result); + assertEquals("Not the expected Class",BigInteger.class,result.getClass()); + assertEquals("Not the expected value",new BigInteger("100000"),result); + + } + public void testDeserializeWithArrayLocalNameForBase64Binary() throws Exception { + omElement.declareNamespace(omFactory.createOMNamespace(Constants.XSD_NAMESPACE, "xs")); + + omElement.setText("SGVsbG8gV29ybGQ="); + omElement.addAttribute(createTypeAttribute("xs:base64Binary")); + + Object result = BeanUtil.deserialize(DataHandler.class, omElement, objectSupplier, null); + assertNotNull("Result can not be null",result); + assertEquals("Not the expected Class",DataHandler.class,result.getClass()); + assertEquals("Not the expected value","Hello World",toStr((ByteArrayInputStream) ((DataHandler)result).getContent())); + + } + public void testDeserializeWithArrayLocalNameForHexBinary() throws Exception { + AxisService service = new AxisService(); + service.setTypeTable(new TypeTable()); + MessageContext.getCurrentMessageContext().setAxisService(service); + omElement.declareNamespace(omFactory.createOMNamespace(Constants.XSD_NAMESPACE, "xs")); + + omElement.setText("48656c6c6f20576f726c64"); + omElement.addAttribute(createTypeAttribute("xs:hexBinary")); + + Object result = BeanUtil.deserialize(DataHandler.class, omElement, objectSupplier, null); + assertNotNull("Result can not be null",result); + assertEquals("Not the expected Class",DataHandler.class,result.getClass()); + assertEquals("Not the expected value","Hello World",toStr((ByteArrayInputStream) ((DataHandler)result).getContent())); + + } + + private static String toStr(ByteArrayInputStream is) { + int size = is.available(); + char[] theChars = new char[size]; + byte[] bytes = new byte[size]; + + is.read(bytes, 0, size); + for (int i = 0; i < size;) + theChars[i] = (char)(bytes[i++]&0xff); + + return new String(theChars); + } + + } Modified: axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/description/java2wsdl/TypeTable.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/description/java2wsdl/TypeTable.java?rev=1136443&r1=1136442&r2=1136443&view=diff ============================================================================== --- axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/description/java2wsdl/TypeTable.java (original) +++ axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/description/java2wsdl/TypeTable.java Thu Jun 16 14:06:30 2011 @@ -20,7 +20,11 @@ package org.apache.axis2.description.java2wsdl; import org.apache.axiom.om.OMElement; +import org.apache.ws.commons.schema.constants.Constants; +import javax.activation.DataHandler; +import javax.xml.datatype.Duration; +import javax.xml.datatype.XMLGregorianCalendar; import javax.xml.namespace.QName; import java.util.ArrayList; import java.util.HashMap; @@ -28,9 +32,11 @@ import java.util.Hashtable; import java.util.List; import java.util.Map; import java.util.Vector; -import java.util.concurrent.ConcurrentHashMap; +import java.math.BigDecimal; +import java.math.BigInteger; import java.net.URI; + public class TypeTable { private static HashMap simpleTypetoxsd; @@ -42,6 +48,11 @@ public class TypeTable { * this map is used to keep the class names with the Qnames. */ private Map qNameToClassMap; + /** + * Keep simpleType to Java mapping separately so that + * this table does not not populate it over and over. + */ + private static Map qNameToJavaTypeMap; public TypeTable() { //complex type table is resetted every time this is @@ -54,6 +65,7 @@ public class TypeTable { * change and we need not populate it over and over */ static{ populateSimpleTypes(); + populateJavaTypeMap(); } /* populate the simpletype hashmap */ @@ -147,6 +159,50 @@ public class TypeTable { simpleTypetoxsd.put("base64Binary", new QName(Java2WSDLConstants.URI_2001_SCHEMA_XSD, "base64Binary", "xs")); } + + private static void populateJavaTypeMap(){ + /* + * This Table populated according to the JAXB 2.0 XSD2Java binding. + * According to following table http://download.oracle.com/javaee/5/tutorial/doc/bnazq.html#bnazu + */ + qNameToJavaTypeMap = new HashMap(); + qNameToJavaTypeMap.put(Constants.XSD_STRING, String.class.getName()); + qNameToJavaTypeMap.put(Constants.XSD_INT, Integer.class.getName()); + qNameToJavaTypeMap.put(Constants.XSD_INTEGER, BigInteger.class.getName()); + qNameToJavaTypeMap.put(Constants.XSD_LONG, Long.class.getName()); + qNameToJavaTypeMap.put(Constants.XSD_SHORT, Short.class.getName()); + qNameToJavaTypeMap.put(Constants.XSD_DECIMAL, BigDecimal.class.getName()); + qNameToJavaTypeMap.put(Constants.XSD_FLOAT, Float.class.getName()); + qNameToJavaTypeMap.put(Constants.XSD_DOUBLE, Double.class.getName()); + qNameToJavaTypeMap.put(Constants.XSD_BOOLEAN, Boolean.class.getName()); + qNameToJavaTypeMap.put(Constants.XSD_BYTE, Byte.class.getName()); + qNameToJavaTypeMap.put(Constants.XSD_QNAME, QName.class.getName()); + qNameToJavaTypeMap.put(Constants.XSD_UNSIGNEDINT, Long.class.getName()); + qNameToJavaTypeMap.put(Constants.XSD_UNSIGNEDSHORT, Integer.class.getName()); + qNameToJavaTypeMap.put(Constants.XSD_UNSIGNEDBYTE, Short.class.getName()); + qNameToJavaTypeMap.put(Constants.XSD_UNSIGNEDLONG, BigInteger.class.getName()); + qNameToJavaTypeMap.put(Constants.XSD_TIME, XMLGregorianCalendar.class.getName()); + qNameToJavaTypeMap.put(Constants.XSD_DATE, XMLGregorianCalendar.class.getName()); + qNameToJavaTypeMap.put(Constants.XSD_DATETIME, XMLGregorianCalendar.class.getName()); + qNameToJavaTypeMap.put(Constants.XSD_DURATION, Duration.class.getName()); + qNameToJavaTypeMap.put(Constants.XSD_NOTATION, QName.class.getName()); + qNameToJavaTypeMap.put(Constants.XSD_ANYURI, URI.class.getName()); + qNameToJavaTypeMap.put(Constants.XSD_ANY, Object.class.getName()); + qNameToJavaTypeMap.put(Constants.XSD_ANYSIMPLETYPE, Object.class.getName()); + qNameToJavaTypeMap.put(Constants.XSD_ANYTYPE, Object.class.getName()); + qNameToJavaTypeMap.put(Constants.XSD_NONNEGATIVEINTEGER, BigInteger.class.getName()); + qNameToJavaTypeMap.put(Constants.XSD_NONPOSITIVEINTEGER, BigInteger.class.getName()); + qNameToJavaTypeMap.put(Constants.XSD_NEGATIVEINTEGER, Integer.class.getName()); + qNameToJavaTypeMap.put(Constants.XSD_POSITIVEINTEGER, Integer.class.getName()); + qNameToJavaTypeMap.put(Constants.XSD_NORMALIZEDSTRING,String.class.getName()); + qNameToJavaTypeMap.put(Constants.XSD_POSITIVEINTEGER, Integer.class.getName()); + qNameToJavaTypeMap.put(Constants.XSD_POSITIVEINTEGER, Integer.class.getName()); + qNameToJavaTypeMap.put(Constants.XSD_POSITIVEINTEGER, Integer.class.getName()); + qNameToJavaTypeMap.put(Constants.XSD_POSITIVEINTEGER, Integer.class.getName()); + qNameToJavaTypeMap.put(Constants.XSD_BASE64, DataHandler.class.getName()); + qNameToJavaTypeMap.put(Constants.XSD_HEXBIN, DataHandler.class.getName()); + + } /** * Return the schema type QName given the type class name @@ -193,10 +249,21 @@ public class TypeTable { public QName getComplexSchemaType(String name) { return (QName) complexTypeMap.get(name); - } - + } + + /** + * Gets the class name for QName. + * first try the complex types if not try the simple types. + * + * @param qname the qname + * @return the class name for QName + */ public String getClassNameForQName(QName qname) { - return this.qNameToClassMap.get(qname); + String className = this.qNameToClassMap.get(qname); + if(className == null){ + className = qNameToJavaTypeMap.get(qname); + } + return className; } public void addClassNameForQName(QName qname, String className) { Added: axis/axis2/java/core/trunk/modules/kernel/test/org/apache/axis2/description/java2wsdl/TypeTableTest.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/kernel/test/org/apache/axis2/description/java2wsdl/TypeTableTest.java?rev=1136443&view=auto ============================================================================== --- axis/axis2/java/core/trunk/modules/kernel/test/org/apache/axis2/description/java2wsdl/TypeTableTest.java (added) +++ axis/axis2/java/core/trunk/modules/kernel/test/org/apache/axis2/description/java2wsdl/TypeTableTest.java Thu Jun 16 14:06:30 2011 @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.axis2.description.java2wsdl; + +import java.math.BigInteger; + +import javax.activation.DataHandler; +import javax.xml.namespace.QName; + +import junit.framework.TestCase; + +import org.apache.ws.commons.schema.constants.Constants; + +/** + * The Class TypeTableTest is used to test + * {@link org.apache.axis2.description.java2wsdl.TypeTable TypeTable} class. + * + * @since 1.7.0 + * + */ +public class TypeTableTest extends TestCase { + + /** The type table. */ + private TypeTable typeTable; + + /* (non-Javadoc) + * @see junit.framework.TestCase#setUp() + */ + @Override + protected void setUp() throws Exception { + super.setUp(); + typeTable = new TypeTable(); + } + + /** + * Test get class name for QName. + */ + public void testGetClassNameForQName() { + assertEquals("Failed to receive expected Class type", + String.class.getName(), + typeTable.getClassNameForQName(Constants.XSD_STRING)); + + assertEquals("Failed to receive expected Class type", + BigInteger.class.getName(), + typeTable.getClassNameForQName(Constants.XSD_INTEGER)); + + assertEquals("Failed to receive expected Class type", + QName.class.getName(), + typeTable.getClassNameForQName(Constants.XSD_QNAME)); + + assertEquals("Failed to receive expected Class type", + Object.class.getName(), + typeTable.getClassNameForQName(Constants.XSD_ANY)); + + assertEquals("Failed to receive expected Class type", + DataHandler.class.getName(), + typeTable.getClassNameForQName(Constants.XSD_BASE64)); + + assertEquals("Failed to receive expected Class type", + DataHandler.class.getName(), + typeTable.getClassNameForQName(Constants.XSD_HEXBIN)); + + assertNull("NULl value expected", + typeTable.getClassNameForQName(Constants.XSD_LANGUAGE)); + } + +} Propchange: axis/axis2/java/core/trunk/modules/kernel/test/org/apache/axis2/description/java2wsdl/TypeTableTest.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: axis/axis2/java/core/trunk/modules/osgi/pom.xml URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/osgi/pom.xml?rev=1136443&r1=1136442&r2=1136443&view=diff ============================================================================== --- axis/axis2/java/core/trunk/modules/osgi/pom.xml (original) +++ axis/axis2/java/core/trunk/modules/osgi/pom.xml Thu Jun 16 14:06:30 2011 @@ -112,6 +112,7 @@ javax.xml.transform;resolution:=optional, javax.xml.transform.dom;resolution:=optional, javax.xml.transform.stream;resolution:=optional, + javax.xml.datatype.*, org.apache.axiom.*, org.apache.commons.fileupload.*, org.apache.commons.httpclient.*,