Author: dsosnoski Date: Fri May 18 04:59:28 2007 New Revision: 539407 URL: http://svn.apache.org/viewvc?view=rev&rev=539407 Log: AXIS2-2670 - simpleType reference with unwrapped AXIS2-2669 - JiBX serialization can generate malformed XML AXIS2-2453 - JiBX creates illegal parameter names with dashes/hyphens
Modified: webservices/axis2/branches/java/1_2/modules/jibx/src/org/apache/axis2/jibx/CodeGenerationUtility.java webservices/axis2/branches/java/1_2/modules/jibx/src/org/apache/axis2/jibx/JiBXDataSource.java webservices/axis2/branches/java/1_2/modules/jibx/src/org/apache/axis2/jibx/template/JibXDatabindingTemplate.xsl Modified: webservices/axis2/branches/java/1_2/modules/jibx/src/org/apache/axis2/jibx/CodeGenerationUtility.java URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_2/modules/jibx/src/org/apache/axis2/jibx/CodeGenerationUtility.java?view=diff&rev=539407&r1=539406&r2=539407 ============================================================================== --- webservices/axis2/branches/java/1_2/modules/jibx/src/org/apache/axis2/jibx/CodeGenerationUtility.java (original) +++ webservices/axis2/branches/java/1_2/modules/jibx/src/org/apache/axis2/jibx/CodeGenerationUtility.java Fri May 18 04:59:28 2007 @@ -34,6 +34,8 @@ import org.apache.ws.commons.schema.XmlSchemaParticle; import org.apache.ws.commons.schema.XmlSchemaSequence; import org.apache.ws.commons.schema.XmlSchemaSimpleType; +import org.apache.ws.commons.schema.XmlSchemaSimpleTypeContent; +import org.apache.ws.commons.schema.XmlSchemaSimpleTypeRestriction; import org.apache.ws.commons.schema.XmlSchemaType; import org.jibx.binding.model.BindingElement; import org.jibx.binding.model.ElementBase; @@ -764,7 +766,8 @@ nons = nons || itemname.getNamespaceURI().length() == 0; param.setAttribute("ns", itemname.getNamespaceURI()); param.setAttribute("name", itemname.getLocalPart()); - param.setAttribute("java-name", toJavaName(itemname.getLocalPart(), nameset)); + String javaname = toJavaName(itemname.getLocalPart(), nameset); + param.setAttribute("java-name", javaname); param.setAttribute("nillable", Boolean.toString(element.isNillable())); boolean optional = element.getMinOccurs() == 0; param.setAttribute("optional", Boolean.toString(optional)); @@ -777,9 +780,24 @@ // simple type translates to format element in binding FormatElement format = (FormatElement)simpleTypeMap.get(typename); if (format == null) { + + // check for restriction with simple base, and treat as base if so + XmlSchemaSimpleType stype = (XmlSchemaSimpleType)element.getSchemaType(); + XmlSchemaSimpleTypeContent content = stype.getContent(); + if (content instanceof XmlSchemaSimpleTypeRestriction) { + QName tname = ((XmlSchemaSimpleTypeRestriction)content).getBaseTypeName(); + if (SCHEMA_NAMESPACE.equals(tname.getNamespaceURI())) { + format = (FormatElement)simpleTypeMap.get(tname); + if (format != null) { + typename = tname; + } + } + } + } + if (format == null) { throw new RuntimeException("Cannot unwrap element " + - qname + ": no format definition found for type " + - typename + " (used by element " + itemname + ')'); + qname + ": no format definition found for type " + + typename + " (used by element " + itemname + ')'); } javatype = format.getTypeName(); param.setAttribute("form", "simple"); @@ -898,7 +916,7 @@ // it's used here to fit into the ADB-based code generation model QName partqname = WSDLUtil.getPartQName(opName.getLocalPart(), WSDLConstants.INPUT_PART_QNAME_SUFFIX, - itemname.getLocalPart()); + javaname); partNameList.add(partqname); // add type mapping so we look like ADB @@ -1064,6 +1082,8 @@ bindingMap.put(format, binding); } else if (child.type() == ElementBase.MAPPING_ELEMENT) { + + // record only abstract mappings with type names, and mappings with names MappingElement mapping = (MappingElement)child; bindingMap.put(mapping, binding); if (mapping.isAbstract() && mapping.getTypeQName() != null) { @@ -1072,9 +1092,7 @@ registerElement(mapping.getTypeQName(), mapping, complexTypeMap); - } else if (mapping.getName() == null) { - throw new RuntimeException("Non-abstract mapping for class " + mapping.getClassName() + " needs element name."); - } else { + } else if (mapping.getName() != null) { // register concrete mappings as element conversions String uri = mapping.getUri(); Modified: webservices/axis2/branches/java/1_2/modules/jibx/src/org/apache/axis2/jibx/JiBXDataSource.java URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_2/modules/jibx/src/org/apache/axis2/jibx/JiBXDataSource.java?view=diff&rev=539407&r1=539406&r2=539407 ============================================================================== --- webservices/axis2/branches/java/1_2/modules/jibx/src/org/apache/axis2/jibx/JiBXDataSource.java (original) +++ webservices/axis2/branches/java/1_2/modules/jibx/src/org/apache/axis2/jibx/JiBXDataSource.java Fri May 18 04:59:28 2007 @@ -45,9 +45,15 @@ /** Element name (only used with [EMAIL PROTECTED] #marshallerIndex}). */ private final String elementName; + + /** Element namespace URI (only used with [EMAIL PROTECTED] #marshallerIndex}). */ + private final String elementNamespace; /** Element namespace prefix (only used with [EMAIL PROTECTED] #marshallerIndex}). */ private final String elementNamespacePrefix; + + /** Element namespace index (only used with [EMAIL PROTECTED] #marshallerIndex}). */ + private final int elementNamespaceIndex; /** Indexes of namespaces to be opened (only used with [EMAIL PROTECTED] #marshallerIndex}). */ private final int[] openNamespaceIndexes; @@ -71,7 +77,8 @@ marshallerIndex = -1; dataObject = obj; bindingFactory = factory; - elementName = elementNamespacePrefix = null; + elementName = elementNamespace = elementNamespacePrefix = null; + elementNamespaceIndex = -1; openNamespaceIndexes = null; openNamespacePrefixes = null; } @@ -82,54 +89,105 @@ * @param obj * @param index * @param name + * @param uri * @param prefix * @param nsindexes * @param nsprefixes * @param factory */ - public JiBXDataSource(Object obj, int index, String name, String prefix, + public JiBXDataSource(Object obj, int index, String name, String uri, String prefix, int[] nsindexes, String[] nsprefixes, IBindingFactory factory) { if (index < 0) { throw new IllegalArgumentException("index value must be non-negative"); } marshallerIndex = index; + dataObject = obj; + bindingFactory = factory; + boolean found = false; + String[] nss = factory.getNamespaces(); + int nsidx = -1; + for (int i = 0; i < nsindexes.length; i++) { + if (uri.equals(nss[nsindexes[i]])) { + nsidx = nsindexes[i]; + prefix = nsprefixes[i]; + found = true; + break; + } + } elementName = name; + elementNamespace = uri; elementNamespacePrefix = prefix; + if (!found) { + for (int i = 0; i < nss.length; i++) { + if (uri.equals(nss[i])) { + nsidx = i; + break; + } + } + if (nsidx >= 0) { + int[] icpy = new int[nsindexes.length+1]; + icpy[0] = nsidx; + System.arraycopy(nsindexes, 0, icpy, 1, nsindexes.length); + nsindexes = icpy; + String[] scpy = new String[nsprefixes.length+1]; + scpy[0] = prefix; + System.arraycopy(nsprefixes, 0, scpy, 1, nsprefixes.length); + nsprefixes = scpy; + } else { + throw new IllegalStateException("Namespace not found"); + } + } + elementNamespaceIndex = nsidx; openNamespaceIndexes = nsindexes; openNamespacePrefixes = nsprefixes; - dataObject = obj; - bindingFactory = factory; } /** - * Internal method to handle the actual marshalling. - * + * Internal method to handle the actual marshalling. If the source object is marshallable it's + * it's just marshalled directly, without worrying about redundant namespace declarations and + * such. If it needs to be handled with an abstract mapping, the handling is determined by the + * 'full' flag. When this is <code>true</code> all namespaces are declared directly, while if + * <code>false</code> the namespaces must have previously been declared on some enclosing + * element of the output. This allows the normal case of marshalling within the context of a + * SOAP message to be handled efficiently, while still generating correct XML if the element is + * marshalled directly (as when building the AXIOM representation for use by WS-Security). + * + * @param full * @param ctx * @throws JiBXException */ - private void marshal(IMarshallingContext ctx) throws JiBXException { + private void marshal(boolean full, IMarshallingContext ctx) throws JiBXException { try { if (marshallerIndex < 0) { ((IMarshallable)dataObject).marshal(ctx); } else { - - // open namespaces from wrapper element IXMLWriter wrtr = ctx.getXmlWriter(); - wrtr.openNamespaces(openNamespaceIndexes, openNamespacePrefixes); String name = elementName; - if (!"".equals(elementNamespacePrefix)) { - name = elementNamespacePrefix + ':' + name; + int nsidx = 0; + if (full) { + + // declare all namespaces on start tag + nsidx = elementNamespaceIndex; + wrtr.startTagNamespaces(nsidx, name, openNamespaceIndexes, openNamespacePrefixes); + + } else { + + // configure writer with namespace declared in enclosing scope + wrtr.openNamespaces(openNamespaceIndexes, openNamespacePrefixes); + if (!"".equals(elementNamespacePrefix)) { + name = elementNamespacePrefix + ':' + name; + } + wrtr.startTagOpen(0, name); } - wrtr.startTagOpen(0, name); - + // marshal object representation (may include attributes) into element IMarshaller mrsh = ctx.getMarshaller(marshallerIndex, bindingFactory .getMappedClasses()[marshallerIndex]); mrsh.marshal(dataObject, ctx); - wrtr.endTag(0, name); + wrtr.endTag(nsidx, name); } ctx.getXmlWriter().flush(); @@ -143,10 +201,12 @@ */ public void serialize(OutputStream output, OMOutputFormat format) throws XMLStreamException { try { + + // marshal with all namespace declarations, since external state unknown IMarshallingContext ctx = bindingFactory.createMarshallingContext(); - ctx.setOutput(output, - format == null ? null : format.getCharSetEncoding()); - marshal(ctx); + ctx.setOutput(output, format == null ? null : format.getCharSetEncoding()); + marshal(true, ctx); + } catch (JiBXException e) { throw new XMLStreamException("Error in JiBX marshalling", e); } @@ -157,9 +217,12 @@ */ public void serialize(Writer writer, OMOutputFormat format) throws XMLStreamException { try { + + // marshal with all namespace declarations, since external state unknown IMarshallingContext ctx = bindingFactory.createMarshallingContext(); ctx.setOutput(writer); - marshal(ctx); + marshal(true, ctx); + } catch (JiBXException e) { throw new XMLStreamException("Error in JiBX marshalling", e); } @@ -170,11 +233,31 @@ */ public void serialize(XMLStreamWriter xmlWriter) throws XMLStreamException { try { - IXMLWriter writer = new StAXWriter(bindingFactory.getNamespaces(), - xmlWriter); + + // check if namespaces already declared for abstract mapping + boolean full = true; + String[] nss = bindingFactory.getNamespaces(); + if (marshallerIndex >= 0) { + String prefix = xmlWriter.getPrefix(elementNamespace); + if (elementNamespacePrefix.equals(prefix)) { + full = false; + for (int i = 0; i < openNamespaceIndexes.length; i++) { + String uri = nss[i]; + prefix = xmlWriter.getPrefix(uri); + if (!openNamespacePrefixes[i].equals(prefix)) { + full = true; + break; + } + } + } + } + + // marshal with all namespace declarations, since external state unknown + IXMLWriter writer = new StAXWriter(nss, xmlWriter); IMarshallingContext ctx = bindingFactory.createMarshallingContext(); ctx.setXmlWriter(writer); - marshal(ctx); + marshal(full, ctx); + } catch (JiBXException e) { throw new XMLStreamException("Error in JiBX marshalling", e); } Modified: webservices/axis2/branches/java/1_2/modules/jibx/src/org/apache/axis2/jibx/template/JibXDatabindingTemplate.xsl URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_2/modules/jibx/src/org/apache/axis2/jibx/template/JibXDatabindingTemplate.xsl?view=diff&rev=539407&r1=539406&r2=539407 ============================================================================== --- webservices/axis2/branches/java/1_2/modules/jibx/src/org/apache/axis2/jibx/template/JibXDatabindingTemplate.xsl (original) +++ webservices/axis2/branches/java/1_2/modules/jibx/src/org/apache/axis2/jibx/template/JibXDatabindingTemplate.xsl Fri May 18 04:59:28 2007 @@ -87,13 +87,7 @@ if (bindingFactory == null) { throw new RuntimeException(bindingErrorMessage); } - org.jibx.runtime.IMarshallable marshallable = - (org.jibx.runtime.IMarshallable)param; - int index = marshallable.JiBX_getIndex(); - org.apache.axis2.jibx.JiBXDataSource source = - new org.apache.axis2.jibx.JiBXDataSource(marshallable, bindingFactory); - org.apache.axiom.om.OMNamespace namespace = factory.createOMNamespace(bindingFactory.getElementNamespaces()[index], null); - return factory.createOMElement(source, bindingFactory.getElementNames()[index], namespace); + return (mappedChild(param, factory)); } else if (param == null) { throw new RuntimeException("Cannot bind null value of type <xsl:value-of select="@type"/>"); } else { @@ -185,15 +179,15 @@ } <xsl:choose> <xsl:when test="out-wrapper/return-element/@form='complex' and out-wrapper/return-element/@type-index=''"> - org.apache.axiom.om.OMDataSource src = new org.apache.axis2.jibx.JiBXDataSource((org.jibx.runtime.IMarshallable)result, bindingFactory); + wrapper.addChild(mappedChild(result, factory)); </xsl:when> <xsl:otherwise> - org.apache.axiom.om.OMDataSource src = new org.apache.axis2.jibx.JiBXDataSource(result, _type_index<xsl:value-of select="out-wrapper/return-element/@type-index"/>, "<xsl:value-of select='out-wrapper/return-element/@name'/>", "<xsl:value-of select='out-wrapper/return-element/@prefix'/>", bindingNamespaceIndexes, bindingNamespacePrefixes, bindingFactory); - </xsl:otherwise> - </xsl:choose> + org.apache.axiom.om.OMDataSource src = new org.apache.axis2.jibx.JiBXDataSource(result, _type_index<xsl:value-of select="out-wrapper/return-element/@type-index"/>, "<xsl:value-of select='out-wrapper/return-element/@name'/>", "<xsl:value-of select='out-wrapper/return-element/@ns'/>", "<xsl:value-of select='out-wrapper/return-element/@prefix'/>", bindingNamespaceIndexes, bindingNamespacePrefixes, bindingFactory); org.apache.axiom.om.OMNamespace appns = factory.createOMNamespace("<xsl:value-of select='out-wrapper/return-element/@ns'/>", ""); org.apache.axiom.om.OMElement child = factory.createOMElement(src, "<xsl:value-of select='out-wrapper/return-element/@name'/>", appns); wrapper.addChild(child); + </xsl:otherwise> + </xsl:choose> } } </xsl:when> @@ -257,15 +251,15 @@ } <xsl:choose> <xsl:when test="out-wrapper/return-element/@form='complex' and out-wrapper/return-element/@type-index=''"> - org.apache.axiom.om.OMDataSource src = new org.apache.axis2.jibx.JiBXDataSource((org.jibx.runtime.IMarshallable)result, bindingFactory); + wrapper.addChild(mappedChild(result, factory)); </xsl:when> <xsl:otherwise> - org.apache.axiom.om.OMDataSource src = new org.apache.axis2.jibx.JiBXDataSource(result, _type_index<xsl:value-of select="out-wrapper/return-element/@type-index"/>, "<xsl:value-of select='out-wrapper/return-element/@name'/>", "<xsl:value-of select='out-wrapper/return-element/@prefix'/>", bindingNamespaceIndexes, bindingNamespacePrefixes, bindingFactory); - </xsl:otherwise> - </xsl:choose> + org.apache.axiom.om.OMDataSource src = new org.apache.axis2.jibx.JiBXDataSource(result, _type_index<xsl:value-of select="out-wrapper/return-element/@type-index"/>, "<xsl:value-of select='out-wrapper/return-element/@name'/>", "<xsl:value-of select='out-wrapper/return-element/@ns'/>", "<xsl:value-of select='out-wrapper/return-element/@prefix'/>", bindingNamespaceIndexes, bindingNamespacePrefixes, bindingFactory); org.apache.axiom.om.OMNamespace appns = factory.createOMNamespace("<xsl:value-of select='out-wrapper/return-element/@ns'/>", ""); org.apache.axiom.om.OMElement child = factory.createOMElement(src, "<xsl:value-of select='out-wrapper/return-element/@name'/>", appns); wrapper.addChild(child); + </xsl:otherwise> + </xsl:choose> } </xsl:when> <xsl:otherwise> @@ -615,15 +609,13 @@ if (bindingFactory == null) { throw new RuntimeException(bindingErrorMessage); } - org.apache.axiom.om.OMDataSource src = new org.apache.axis2.jibx.JiBXDataSource((org.jibx.runtime.IMarshallable)<xsl:call-template name="parameter-or-array-item"/>, bindingFactory); - org.apache.axiom.om.OMNamespace appns = factory.createOMNamespace("<xsl:value-of select='@ns'/>", ""); - child = factory.createOMElement(src, "<xsl:value-of select='@name'/>", appns); + child = mappedChild(<xsl:call-template name="parameter-or-array-item"/>, factory); </xsl:when> <xsl:when test="@form='complex'"> if (bindingFactory == null) { throw new RuntimeException(bindingErrorMessage); } - org.apache.axiom.om.OMDataSource src = new org.apache.axis2.jibx.JiBXDataSource(<xsl:call-template name="parameter-or-array-item"/>, _type_index<xsl:value-of select="@type-index"/>, "<xsl:value-of select='@name'/>", "<xsl:value-of select='@prefix'/>", bindingNamespaceIndexes, bindingNamespacePrefixes, bindingFactory); + org.apache.axiom.om.OMDataSource src = new org.apache.axis2.jibx.JiBXDataSource(<xsl:call-template name="parameter-or-array-item"/>, _type_index<xsl:value-of select="@type-index"/>, "<xsl:value-of select='@name'/>", "<xsl:value-of select='@ns'/>", "<xsl:value-of select='@prefix'/>", bindingNamespaceIndexes, bindingNamespacePrefixes, bindingFactory); org.apache.axiom.om.OMNamespace appns = factory.createOMNamespace("<xsl:value-of select='@ns'/>", ""); child = factory.createOMElement(src, "<xsl:value-of select='@name'/>", appns); </xsl:when> @@ -652,69 +644,69 @@ --> <!-- Called by main template to create utility methods --> <xsl:template name="stub-utility-methods"> - - private Exception convertException(Exception ex) throws java.rmi.RemoteException { - if (ex instanceof org.apache.axis2.AxisFault) { - org.apache.axis2.AxisFault f = (org.apache.axis2.AxisFault)ex; - org.apache.axiom.om.OMElement faultElt = f.getDetail(); - if (faultElt != null) { - if (faultExceptionNameMap.containsKey(faultElt.getQName())) { - try { - - // first create the actual exception - String exceptionClassName = (String)faultExceptionClassNameMap.get(faultElt.getQName()); - Class exceptionClass = Class.forName(exceptionClassName); - Exception e = (Exception)exceptionClass.newInstance(); - - // build the message object from the details - String messageClassName = (String)faultMessageMap.get(faultElt.getQName()); - Class messageClass = Class.forName(messageClassName); - Object messageObject = fromOM(faultElt, messageClass, null); - java.lang.reflect.Method m = exceptionClass.getMethod("setFaultMessage", - new Class[] { messageClass }); - m.invoke(e, new Object[] { messageObject }); - return e; - - } catch (ClassCastException e) { - // we cannot intantiate the class - throw the original - // Axis fault - throw f; - } catch (ClassNotFoundException e) { - // we cannot intantiate the class - throw the original - // Axis fault - throw f; - } catch (NoSuchMethodException e) { - // we cannot intantiate the class - throw the original - // Axis fault - throw f; - } catch (java.lang.reflect.InvocationTargetException e) { - // we cannot intantiate the class - throw the original - // Axis fault - throw f; - } catch (IllegalAccessException e) { - // we cannot intantiate the class - throw the original - // Axis fault - throw f; - } catch (InstantiationException e) { - // we cannot intantiate the class - throw the original - // Axis fault - throw f; - } - } else { + + private Exception convertException(Exception ex) throws java.rmi.RemoteException { + if (ex instanceof org.apache.axis2.AxisFault) { + org.apache.axis2.AxisFault f = (org.apache.axis2.AxisFault)ex; + org.apache.axiom.om.OMElement faultElt = f.getDetail(); + if (faultElt != null) { + if (faultExceptionNameMap.containsKey(faultElt.getQName())) { + try { + + // first create the actual exception + String exceptionClassName = (String)faultExceptionClassNameMap.get(faultElt.getQName()); + Class exceptionClass = Class.forName(exceptionClassName); + Exception e = (Exception)exceptionClass.newInstance(); + + // build the message object from the details + String messageClassName = (String)faultMessageMap.get(faultElt.getQName()); + Class messageClass = Class.forName(messageClassName); + Object messageObject = fromOM(faultElt, messageClass, null); + java.lang.reflect.Method m = exceptionClass.getMethod("setFaultMessage", + new Class[] { messageClass }); + m.invoke(e, new Object[] { messageObject }); + return e; + + } catch (ClassCastException e) { + // we cannot intantiate the class - throw the original + // Axis fault + throw f; + } catch (ClassNotFoundException e) { + // we cannot intantiate the class - throw the original + // Axis fault + throw f; + } catch (NoSuchMethodException e) { + // we cannot intantiate the class - throw the original + // Axis fault + throw f; + } catch (java.lang.reflect.InvocationTargetException e) { + // we cannot intantiate the class - throw the original + // Axis fault + throw f; + } catch (IllegalAccessException e) { + // we cannot intantiate the class - throw the original + // Axis fault + throw f; + } catch (InstantiationException e) { + // we cannot intantiate the class - throw the original + // Axis fault throw f; } } else { throw f; } - - } else if (ex instanceof RuntimeException) { - throw (RuntimeException)ex; - } else if (ex instanceof java.rmi.RemoteException) { - throw (java.rmi.RemoteException)ex; } else { - throw org.apache.axis2.AxisFault.makeFault(ex); + throw f; } + + } else if (ex instanceof RuntimeException) { + throw (RuntimeException)ex; + } else if (ex instanceof java.rmi.RemoteException) { + throw (java.rmi.RemoteException)ex; + } else { + throw org.apache.axis2.AxisFault.makeFault(ex); } + } </xsl:template> @@ -726,110 +718,118 @@ <!-- Called by main template to handle static binding data and methods. --> <xsl:template match="initialize-binding"> <xsl:variable name="nscount" select="count(binding-namespace)"/> - private static final org.jibx.runtime.IBindingFactory bindingFactory; - private static final String bindingErrorMessage; - private static final int[] bindingNamespaceIndexes; - private static final String[] bindingNamespacePrefixes; + private static final org.jibx.runtime.IBindingFactory bindingFactory; + private static final String bindingErrorMessage; + private static final int[] bindingNamespaceIndexes; + private static final String[] bindingNamespacePrefixes; <xsl:apply-templates mode="generate-index-fields" select="abstract-type"/> - static { - org.jibx.runtime.IBindingFactory factory = null; - String message = null; - try { + static { + org.jibx.runtime.IBindingFactory factory = null; + String message = null; + try { <xsl:choose> <xsl:when test="string-length(normalize-space(@binding-name)) > 0"> - factory = org.jibx.runtime.BindingDirectory.getFactory("<xsl:value-of select="@binding-name"/>", "<xsl:value-of select="@binding-package"/>", <xsl:choose><xsl:when test="string-length(normalize-space(/class/@name))>0"><xsl:value-of select="/class/@name"/></xsl:when><xsl:otherwise><xsl:value-of select="/interface/@name"/></xsl:otherwise></xsl:choose>.class.getClassLoader()); + factory = org.jibx.runtime.BindingDirectory.getFactory("<xsl:value-of select="@binding-name"/>", "<xsl:value-of select="@binding-package"/>", <xsl:choose><xsl:when test="string-length(normalize-space(/class/@name))>0"><xsl:value-of select="/class/@name"/></xsl:when><xsl:otherwise><xsl:value-of select="/interface/@name"/></xsl:otherwise></xsl:choose>.class.getClassLoader()); </xsl:when> <xsl:when test="string-length(normalize-space(@bound-class)) > 0"> - factory = org.jibx.runtime.BindingDirectory.getFactory(<xsl:value-of select="@bound-class"/>.class); + factory = org.jibx.runtime.BindingDirectory.getFactory(<xsl:value-of select="@bound-class"/>.class); </xsl:when> <xsl:otherwise> - factory = new org.apache.axis2.jibx.NullBindingFactory(); + factory = new org.apache.axis2.jibx.NullBindingFactory(); </xsl:otherwise> </xsl:choose> - message = null; - } catch (Exception e) { message = e.getMessage(); } - bindingFactory = factory; - bindingErrorMessage = message; + message = null; + } catch (Exception e) { message = e.getMessage(); } + bindingFactory = factory; + bindingErrorMessage = message; <xsl:apply-templates mode="set-index-fields" select="abstract-type"/> - int[] indexes = null; - String[] prefixes = null; - if (factory != null) { - - // check for xsi namespace included - String[] nsuris = factory.getNamespaces(); - int xsiindex = nsuris.length; - while (--xsiindex >= 0 && - !"http://www.w3.org/2001/XMLSchema-instance".equals(nsuris[xsiindex])); - - // get actual size of index and prefix arrays to be allocated - int nscount = <xsl:value-of select="$nscount"/>; - int usecount = nscount; - if (xsiindex >= 0) { - usecount++; - } - - // allocate and initialize the arrays - indexes = new int[usecount]; - prefixes = new String[usecount]; + int[] indexes = null; + String[] prefixes = null; + if (factory != null) { + + // check for xsi namespace included + String[] nsuris = factory.getNamespaces(); + int xsiindex = nsuris.length; + while (--xsiindex >= 0 && + !"http://www.w3.org/2001/XMLSchema-instance".equals(nsuris[xsiindex])); + + // get actual size of index and prefix arrays to be allocated + int nscount = <xsl:value-of select="$nscount"/>; + int usecount = nscount; + if (xsiindex >= 0) { + usecount++; + } + + // allocate and initialize the arrays + indexes = new int[usecount]; + prefixes = new String[usecount]; <xsl:for-each select="binding-namespace"> <xsl:variable name="nsindex" select="count(preceding-sibling::binding-namespace)"/> - indexes[<xsl:value-of select="$nsindex"/>] = nsIndex("<xsl:value-of select='@ns'/>", nsuris); - prefixes[<xsl:value-of select="$nsindex"/>] = "<xsl:value-of select='@prefix'/>"; + indexes[<xsl:value-of select="$nsindex"/>] = nsIndex("<xsl:value-of select='@ns'/>", nsuris); + prefixes[<xsl:value-of select="$nsindex"/>] = "<xsl:value-of select='@prefix'/>"; </xsl:for-each> - if (xsiindex >= 0) { - indexes[nscount] = xsiindex; - prefixes[nscount] = "xsi"; - } - + if (xsiindex >= 0) { + indexes[nscount] = xsiindex; + prefixes[nscount] = "xsi"; } - bindingNamespaceIndexes = indexes; - bindingNamespacePrefixes = prefixes; + } - - private static int nsIndex(String uri, String[] uris) { - for (int i = 0; i < uris.length; i++) { - if (uri.equals(uris[i])) { - return i; - } + bindingNamespaceIndexes = indexes; + bindingNamespacePrefixes = prefixes; + } + + private static int nsIndex(String uri, String[] uris) { + for (int i = 0; i < uris.length; i++) { + if (uri.equals(uris[i])) { + return i; } - throw new IllegalArgumentException("Namespace " + uri + " not found in binding directory information"); } - - private static void addMappingNamespaces(org.apache.axiom.soap.SOAPFactory factory, org.apache.axiom.om.OMElement wrapper, String nsuri, String nspref) { - String[] nss = bindingFactory.getNamespaces(); - for (int i = 0; i < bindingNamespaceIndexes.length; i++) { - int index = bindingNamespaceIndexes[i]; - String uri = nss[index]; - String prefix = bindingNamespacePrefixes[i]; - if (!nsuri.equals(uri) || !nspref.equals(prefix)) { - wrapper.declareNamespace(factory.createOMNamespace(uri, prefix)); - } + throw new IllegalArgumentException("Namespace " + uri + " not found in binding directory information"); + } + + private static void addMappingNamespaces(org.apache.axiom.soap.SOAPFactory factory, org.apache.axiom.om.OMElement wrapper, String nsuri, String nspref) { + String[] nss = bindingFactory.getNamespaces(); + for (int i = 0; i < bindingNamespaceIndexes.length; i++) { + int index = bindingNamespaceIndexes[i]; + String uri = nss[index]; + String prefix = bindingNamespacePrefixes[i]; + if (!nsuri.equals(uri) || !nspref.equals(prefix)) { + wrapper.declareNamespace(factory.createOMNamespace(uri, prefix)); } } - - private static org.jibx.runtime.impl.UnmarshallingContext getNewUnmarshalContext(org.apache.axiom.om.OMElement param) - throws org.jibx.runtime.JiBXException { - if (bindingFactory == null) { - throw new RuntimeException(bindingErrorMessage); - } - org.jibx.runtime.impl.UnmarshallingContext ctx = - (org.jibx.runtime.impl.UnmarshallingContext)bindingFactory.createUnmarshallingContext(); - org.jibx.runtime.IXMLReader reader = new org.jibx.runtime.impl.StAXReaderWrapper(param.getXMLStreamReaderWithoutCaching(), "SOAP-message", true); - ctx.setDocument(reader); - ctx.toTag(); - return ctx; + } + + private static org.jibx.runtime.impl.UnmarshallingContext getNewUnmarshalContext(org.apache.axiom.om.OMElement param) + throws org.jibx.runtime.JiBXException { + if (bindingFactory == null) { + throw new RuntimeException(bindingErrorMessage); } - - <!-- shouldn't be needed when no actual binding, but called by fault conversion code so must be left in for now --> - private static Object fromOM(org.apache.axiom.om.OMElement param, Class type, - java.util.Map extraNamespaces) { - try { - org.jibx.runtime.impl.UnmarshallingContext ctx = getNewUnmarshalContext(param); - return ctx.unmarshalElement(type); - } catch (Exception e) { - throw new RuntimeException(e); - } + org.jibx.runtime.impl.UnmarshallingContext ctx = + (org.jibx.runtime.impl.UnmarshallingContext)bindingFactory.createUnmarshallingContext(); + org.jibx.runtime.IXMLReader reader = new org.jibx.runtime.impl.StAXReaderWrapper(param.getXMLStreamReaderWithoutCaching(), "SOAP-message", true); + ctx.setDocument(reader); + ctx.toTag(); + return ctx; + } + + private org.apache.axiom.om.OMElement mappedChild(Object value, org.apache.axiom.om.OMFactory factory) { + org.jibx.runtime.IMarshallable mrshable = (org.jibx.runtime.IMarshallable)value; + org.apache.axiom.om.OMDataSource src = new org.apache.axis2.jibx.JiBXDataSource(mrshable, bindingFactory); + int index = mrshable.JiBX_getIndex(); + org.apache.axiom.om.OMNamespace appns = factory.createOMNamespace(bindingFactory.getElementNamespaces()[index], ""); + return factory.createOMElement(src, bindingFactory.getElementNames()[index], appns); + } + + <!-- shouldn't be needed when no actual binding, but called by fault conversion code so must be left in for now --> + private static Object fromOM(org.apache.axiom.om.OMElement param, Class type, + java.util.Map extraNamespaces) { + try { + org.jibx.runtime.impl.UnmarshallingContext ctx = getNewUnmarshalContext(param); + return ctx.unmarshalElement(type); + } catch (Exception e) { + throw new RuntimeException(e); } + } </xsl:template> <!-- Called by "initialize-binding" template to generate mapped class index fields. --> --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]