5 Replies Latest reply on Aug 9, 2005 9:08 PM by anil.saldhana

    Contract between JBossWS and JAXB

    thomas.diesler

      Marshalling
      -------------

      For marshalling the WS layer passes to the JAXB layer

      * optional java object instance
      * required URL to the packaged or generated XSDSchema
      * required QName of the root element
      * optional QName of the root complex type
      * optional instance of JavaWsdlMapping

      jaxbMarshaller.setProperty(MarshallerImpl.JAXB_SCHEMA_LOCATION, xsdURL);
      jaxbMarshaller.setProperty(MarshallerImpl.JAXB_TYPE_QNAME, xmlType);
      jaxbMarshaller.setProperty(MarshallerImpl.JAXB_ROOT_QNAME, xmlName);
      jaxbMarshaller.setProperty(MarshallerImpl.JAXB_JAVA_MAPPING, jaxrpcMapping);
      
      StringWriter strwr = new StringWriter();
      jaxbMarshaller.marshal(value, strwr);
      


      If the object value is null, the corresponding XML representation of the nillable element should be marshalled.
      The xmlType is redundant if the xmlName corresponds to a global element definition in schema.
      If the java mapping is null, default mapping rules apply.

      The result is a self contained (i.e. contains all namespace definitions) XML document without the XML declaration.
      In case of an marshalling problem a descriptive exception is thrown.

      Unmarshalling
      ----------------

      For unmarshalling the WS layer passes to the JAXB layer

      * required self contained xml content
      * required URL to the packaged or generated XSDSchema
      * optional QName of the root complex type
      * optional instance of JavaWsdlMapping

      jaxbUnmarshaller.setProperty(MarshallerImpl.JAXB_SCHEMA_LOCATION, xsdURL);
      jaxbUnmarshaller.setProperty(MarshallerImpl.JAXB_TYPE_QNAME, xmlType);
      jaxbUnmarshaller.setProperty(MarshallerImpl.JAXB_JAVA_MAPPING, jaxrpcMapping);
      
      ByteArrayInputStream ins = new ByteArrayInputStream(val.getBytes());
      Object value = jaxbUnmarshaller.unmarshal(ins);
      


      The xmlType is redundant if the root element name corresponds to a global element definition in schema.
      If the java mapping is null, default mapping rules apply.

      The result is an object instance or null. In case of an unmarshalling problem a descriptive exception is thrown.



        • 1. Re: Contract between JBossWS and JAXB
          thomas.diesler

          A single schema location is not sufficient. There may be schema imports or type references from other schemas.

          The contract has been changed to pass a map of schema locations to the JAXB layer


           // Get the xsdSchema location map
           Map<String, List<URL>> xsdURLMap = serContext.getSchemaLocations();
           jaxbUnmarshaller.setProperty(JAXBConstants.JAXB_SCHEMA_LOCATION_MAP, xsdURLMap);
          


          The JAXBMashallerImpl/JAXBUnmarshallerImpl needs to pass the map down to JBossXB. This needs to be done.

          In future we don't want to be dealing with location URLs at all. JBossXB should be able to consume the JBossXSModel, which is the read/write version of the xerces XSModel, directly.

          • 2. Re: Contract between JBossWS and JAXB
            aloubyansky

            As I can see JBossXSModel implements XSModel. Since jbossxb internally uses XSModel, it's not an issue.

            • 3. Re: Contract between JBossWS and JAXB
              anil.saldhana

              JBossXSModel (or XSModel) is the final built Schema Model that is built after taking XSD:include into consideration. If JAXB is just interested in the XSTypeDefinitions, then JBossXSModel will suffice. There is no need to pass in a set of schema urls to JAXB.

              Alex, does JBossXSModel with types/elements/attributes suffice for your needs? Also, JBossXSModel has NamespaceItems which store the locations of the schema files that contributed to that model.

              • 4. Re: Contract between JBossWS and JAXB
                aloubyansky

                The post implies that your XSModel implementation is not complete? What's missing?

                • 5. Re: Contract between JBossWS and JAXB
                  anil.saldhana

                  JBossXSModel is just a read/write based Xerces XSModel implementation. It is complete.