Skip to main content

@XmlValue polymorphism

4 replies [Last post]
ratoo
Offline
Joined: 2007-08-27

Hello,

Here is my problem: I have 2 simple classes (types)

<br />
public class SimpleType1<br />
{<br />
   @XmlValue<br />
   public String value;<br />
}<br />

and

<br />
public class SimpleType2<br />
{<br />
    @XmlValue<br />
    @XmlMimeType("application/octet-stream")<br />
    public DataHandler handler;<br />
}<br />

then I have a complex class (type) with a simple context:

<br />
public class ComplexType<br />
{<br />
   @XmlAttribute<br />
   public String name;<br />
   @XmlValue<br />
   public Object context<br />
}<br />

I can't use Object because I get an exception:
@XmlValue need to reference a Java type that maps to text in XML.

So I can make another class and make SimpleType1 and SimpleType1 inherit from it:

<br />
public class SimpleTypeParent<br />
{<br />
    @XmlValue<br />
    public ??? getContent()<br />
    {<br />
    }<br />
}<br />

but again - I can not use String here because of DataHandler (in SimpleType2)...

Is there a way to encode DataHandler to a "text-plain" (make it work like a String)?

Thank you in advance,

Ratoo

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Glen Mazza

metro wrote:
>
> Is there a way to encode DataHandler to a "text-plain" (make it work like
> a String)?
>

Pardon the non-answer, but combining elements with the DataHandler seems
strange. Normally the DataHandler is used in the Response object for
MTOM...in that case, you're going to be limited to one data element[1] (the
DataHandler) anyway. See the WSDL here[2] (Step #5), which, when wsimport
is run, will create a Response object with a single element, the
DataHandler.

But I may be wrong here...what I would recommend is modifying my WSDL[2] and
adding a string element to the getWeatherForecastResponse element. When you
run wsimport on it, look at the generated Java class--that may give you an
idea of how to proceed.

Glen

[1]
http://groups.google.com/group/webservicesprogramming/browse_thread/thre...
[2] http://www.jroller.com/gmazza/date/20071102#NWSstep5

--
View this message in context: http://www.nabble.com/%40XmlValue-polymorthism-tp18847772p18882081.html
Sent from the Metro - Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@metro.dev.java.net
For additional commands, e-mail: users-help@metro.dev.java.net

ratoo
Offline
Joined: 2007-08-27

Hello Glen,

Unfortunately I am not the master of my destiny :-)

My situation that we already have a type system and a class... say "MyString" that is encoded as a complex type with a simple context.

I made a new type "MyBinary" (base64binary) that is perfectly encoded using XOP/MTOM.
The problem is that there is a huge ontology that is done using usual string. People just don't want to change it. The only way to me to introduce streaming is to modify "MyString" so that it can accept (and codify) both xs:string and xs:base64Binary...

Anyway thank you for post,

Ratoo

ratoo
Offline
Joined: 2007-08-27

withdrawn

ratoo
Offline
Joined: 2007-08-27

Hello,

I found this bug:
http://bugs.sun.com/bugdatabase/view_bug.do;jsessionid=5a62a5ba2819f43e2...

So actually I can not do:

[code]
@XmlValue
@XmlSchemaType(name = "anySimpleType")
protected Object value;
[/code]
JAXB 2.1 specs page 78:

"Java Mapping for XML Schema Built-in Types" Table.

Anyway if it works there is a problem with distinguishing between xs:string and base64 encoded base64binary types...

I'll try to sole through a custom XmlAdaptor,

Big thanx to all,

Ratoo