users@jaxb.java.net

RE: Root element with anyType

From: Franklin, Brian <brian.franklin_at_ciraden.com>
Date: Fri, 24 Oct 2003 17:18:40 -0400

Oh I forgot to mention something in this email that I did mention in the bug
report.

As far as desired behavior, I think I would like to see the GenericElement
interface extend Element (and not AnyType) and have the get/setValueObject
methods in it, with java.lang.Object as the return and param types.

Brian

-----Original Message-----
From: Franklin, Brian [mailto:brian.franklin_at_ciraden.com]
Sent: Friday, October 24, 2003 4:31 PM
To: 'users_at_jaxb.dev.java.net'
Subject: RE: Root element with anyType


Yeah, I was referring to the BugParade on java.sun.com.

I figured out what was required to trigger the error and came up with a
simple example schema to use. I'll file the report, but I'd like to post
the example here in case possible solutions might need discussion.

Here's the example schema:

--- begin example.xsd ---

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
                targetNamespace="example"
                xmlns:this="example"
                xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
                xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
                jaxb:extensionBindingPrefixes="xjc"
                jaxb:version="1.0">

        <annotation>
                <appinfo>
                        <jaxb:globalBindings>
                                <xjc:typeSubstitution type="complex" />
                        </jaxb:globalBindings>
                </appinfo>
        </annotation>

        <!-- this is equivalent to:
        <element name="GenericElement" type="anyType" />
        -->
        <element name="GenericElement" />

        <complexType name="ExampleType">
                <sequence>
                        <element name="Content" type="anyType" />
                </sequence>
        </complexType>

</schema>

--- end example.xsd ---

Scenario 1:
If you comment out the annotation, the schema compiles. The generated
GenericElement interface extends from org.w3._2001.AnyType (this is probably
where the problem comes in during Scenario 2). The get/setContent methods
in ExampleType both use AnyType as well.

Scenario 2:
Activate type substitution by leaving the annotation alone (of course you'll
need to use xjc -extension example.xsd from the command line). The
GenericElement declaration now generates an error complaining that
java.lang.Object is not an interface. My guess is that this is probably
because the generated GenericElement interface is trying to extend
java.lang.Object instead of AnyType (like it did in Scenario 1). If you
comment out the GenericElement declaration to get it to work, then the
get/setContent methods in ExampleType now use java.lang.Object instead of
AnyType.


I actually prefer the use of java.lang.Object rather than AnyType. From
what I can tell, during unmarshalling, for an element that is declared as
xs:anyType, JAXB will actually use an instance of the proper type if the
type is recognizable from the context path, and if not, will use an AnyType
instance. This seems quite reasonable to me, since AnyType is fairly
annoying to use, especially in a situation where the proper interface type
could've been determined and used instead.

That's my two cents. Thanks for listening,

Brian Franklin


-----Original Message-----
From: Ryan Shoemaker - JavaSoft East [mailto:Ryan.Shoemaker_at_Sun.COM]
Sent: Thursday, October 23, 2003 8:14 PM
To: users_at_jaxb.dev.java.net
Subject: Re: Root element with anyType


Franklin, Brian wrote:

> Second, I think the Bug Database needs to have the version drop-down
entries
> updated for 1.0.2 (and maybe the rest of the new JWSDP components). This
> may be already on the list of to-do's, but I figured I would let you know.
>

Brian,

You're using BugParade[1] on java.sun.com, right? We aren't using the
bug system on java.net yet.

Just file it against 1.0.1 and we will fix the version internally. In
the mean time, we'll also get BugParade updated. Also, just as an FYI
the BugParade process can be slow, so we might not actually see the bug
report for a week or two. It would be great if you could send a copy
of your report to jaxb-comments_at_sun.com as well.

Thanks,

--Ryan

[1] http://java.sun.com/webapps/bugreport/


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
For additional commands, e-mail: users-help_at_jaxb.dev.java.net

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
For additional commands, e-mail: users-help_at_jaxb.dev.java.net

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
For additional commands, e-mail: users-help_at_jaxb.dev.java.net