You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jaxme-dev@ws.apache.org by Ricardo Brito Da Rocha <ri...@cern.ch> on 2005/11/15 19:01:45 UTC

enumerations, URIs and arrays

Hi all.

I've been trying out JaxMe (0.5) as an alternative JAXB implementation that doesn't make me depend on the whole JWSDP bundle.

I'm stuck with some issues, where i'm hoping you can help me. I'm generating java sources by calling the xjc ant target and giving
it a XSD file. Goal is build XML documents using the generated Java objects. Here goes nothing...

* Enumerations
There seems to be no proper mapping made for Simple Types with xsd:enumeration restrictions. All i get is a basic get/set method
that retrieves and takes a string, respectively. This is not very useful. I've tried something similar while generating stubs from
WSDL files using Axis, and got nice classes mapping to the enumeration (using jdk 1.4). Is there any internal restriction in the
Handler or any other type of classes underneath?

* URIs
Defining an element of type 'xsd:anyURI' leaves me with a string, again. I was expecting to end up with a java.net.URL, so that it
would be automatically validated (as i go from java to XML, not the opposite).

* Arrays
I'm defining Array like structures using unbounded elements. Two issues here: The first is that i get a java.util.List, instead of a
proper strong-typed array of the object type. The second is that the interface only exposes a get method, no set. I've looked and
played a bit with the way i'm generating the objects and can't seem to find any way to actual set these values.

Are these features that do not exist yet or am i doing something wrong?

If no such features exist, could you point me to a similar library that can fit to these requirements (and doesn't come with 70MB of
libraries to fulfill other goals)?

Thanks in advance,
  Ricardo

PS: One thing that may be useful to know is that i define all fields using xsd:element inside xsd:sequence. No xsd:attribute at all.

Re: enumerations, URIs and arrays

Posted by Jochen Wiedmann <jo...@gmail.com>.
Ricardo Brito Da Rocha wrote:

> * Enumerations
> There seems to be no proper mapping made for Simple Types with xsd:enumeration restrictions. All i get is a basic get/set method
> that retrieves and takes a string, respectively.

The JAXB specification requests, that by default

   a) only the nmtoken type should be mapped to an enumeration
      classes and
   b) only for globally declared simple types.

To override a), you need to use the attribute 
jaxb:globalBindings/@typesafeEnumBase. See src/test/jaxb/enumeration.xsd 
for an example. That switch works globally, for all globally declared 
simple types.

To override b), you'll add a jaxb:typesafeEnumClass element to the 
simple type in question. See the same file for an example. However, this 
switch works only for that particular simple type.


> * URIs
> Defining an element of type 'xsd:anyURI' leaves me with a string, again. I was expecting to end up with a java.net.URL, so that it
> would be automatically validated (as i go from java to XML, not the opposite).

Not all URI's can be mapped to URL's. However, you can do that for 
yourself using the jaxb:globalBindings/jaxb:javaType customization. See 
src/test/jaxb/xjcSerializable.xsd for an example.


> * Arrays
> I'm defining Array like structures using unbounded elements. Two issues here: The first is that i get a java.util.List, instead of a
> proper strong-typed array of the object type. The second is that the interface only exposes a get method, no set. I've looked and
> played a bit with the way i'm generating the objects and can't seem to find any way to actual set these values.

Again, I agree that I'd prefer to have things the way you want it. But 
the JAXB specification states, that arrays must be explicitly enabled, 
for example by setting jaxb:globalBindings/@collectionType="indexed".


> PS: One thing that may be useful to know is that i define all fields using xsd:element inside xsd:sequence. No xsd:attribute at all.

That doesn't matter at all. :-) Atomic elements and attributes are both 
easy to handle.


Jochen


---------------------------------------------------------------------
To unsubscribe, e-mail: jaxme-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: jaxme-dev-help@ws.apache.org