JaxMe FrequentlyAskedQuestions

General Questions

Required JDK version

What JDK version does JaxMe require? Does it run with JDK 1.2?

The intention is, that JaxMe runs with JDK 1.2. However, the following should be noted:

1. The developers are using 1.4, or later.

2. Whereever known, 1.4 specific features are encapsulated. However, there might be other places.

3. Noone checks, whether the prerequisite jar files are running with 1.2.

In other words: You are on your own. Go ahead and try. We promise, to handle any 1.2 specific problems as a bug. Nothing more, nothing less.

Thread Safety

What are the issues around JaxMe usage in a multi-threaded environment?

JaxMe's JAXBContext was carefully designed to be fully thread safe and reentrant. The suggested use is to have a factory method, that reads the context from a static variable.

JaxMe's marshallers and unmarshallers are not thread safe in the following sense: Unlike the context, these are configurable. For example, the marshaller has a property causing it to emit an XML declaration or not.

However, they *are* thread safe and reentrant, as long as you don't change the properties. The suggested use is indeed, to create one marshaller, unmarshaller, or validator per possible configuration, store it in a factory or static variable and use it. The actual marshalling and unmarshalling has been carefully coded to put all required information (besides the properties, of course) into JMXmlSerializer.Data, or JMHandler.Data, respectively.

Note, though, that this use of marshallers and unmarshallers is definitely *not* portable. Thread safety and similar questions are definitely not covered by the SPEC. Even worse, IMO it wasn't even considered well, because otherwise the marshaller and its configuration would have been clearly separated. JAXB marshallers and unmarshallers are definitely heavyweighted objects.

Generation Questions (Ant)

Unable To Derive Package Name From Empty Namespace

My generation fails with the following message:

Unable to derive package name from an empty namespace URI. 
Use the schemaBinding to specify a package name.

What is a schema binding and how do I set it?

First of all, the error message is most probably caused by a bug, which is already fixed in CVS. See http://nagoya.apache.org/jira/browse/JAXME-18 for details.

Second, the schema binding can mean different things.

- "Schema binding" as an abstract word describes the binding of a schema to classes

- In this particular case, the XML tag jaxb:schemaBindings is meant, which allows to

      <xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>
        <xs:annotation><xs:appinfo>
          <jaxb:schemaBindings xmlns:jaxb=''>
            <jaxb:package name='com.foo.xml'/>
          <jaxb:schemaBindings>
        </xs:appinfo></xs:annotation>
        ...
      </xs:schema>

Marshalling

How do I unmarshal an XML document from a string?

I tryed to unmarshal an XML document from a String and i had this exception:

java.net.MalformedURLException: no protocol

Using this example code:

        String sXML = "<?xml version='1.0' encoding='UTF-8'?><MYDOC><EXAMPLE>Only an example</EXAMPLE></MYDOC>";
        JAXBContext jaxbContext = JAXBContext.newInstance("wgs.cq.xml");
        Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
        unmarshaller.setValidating(false);
        return unmarshaller.unmarshal(new InputSource(sXML));

How do I unmarshal an XML document from a string?

To unmarshall an XML document from a String you need to use the unmarshal method with the InputSource parameter and you had to use the constructor with a StringReader, because the constructor InputSource(String) has the meaning, that the argument is the URL of a file being loaded, not the actual file.

Here's an example:

import java.io.StringReader;
import java.io.InputStream;

import org.xml.sax.InputSource;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;

try {
   String sXML = "<?xml version='1.0' encoding='UTF-8'?><MYDOC><EXAMPLE>Only an example</EXAMPLE></MYDOC>";
   JAXBContext jaxbContext = JAXBContext.newInstance("wgs.cq.xml");
   Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
   unmarshaller.setValidating(false);
   return unmarshaller.unmarshal(new InputSource(new StringReader(sXML)));
} catch(JAXBException e) {}

Unmarshalling

See the separate page on /Unmarshalling.

JaxMe/FrequentlyAskedQuestions (last edited 2009-09-20 22:48:14 by localhost)