Scudieri, Chris (IT) wrote:
> Ahhh...well that is where things do get tricky.
>
> public class PropertyValue<T>
> {
> protected PropertyTypes type;
>
> @XmlJavaTypeAdapter(PropertyAdapter.class)
> private T value;
>
> public T getValue()
> {
> return value;
> }
>
> public void setValue( T v )
> {
> value = v;
> }
> ..
> }
Yeah, see, this class is not bound to a text in XML. It's bound to a XML
fragment in XML (AKA complex type) where you'd have elements like
<value> and etc.
So that's why it's complaining that @XmlValue cannot be used with such a
type. How's the XML document that you are trying to process look like?
>
> -----Original Message-----
> From: Kohsuke Kawaguchi [mailto:Kohsuke.Kawaguchi_at_Sun.COM]
> Sent: Tuesday, December 19, 2006 1:33 PM
> To: users_at_jaxb.dev.java.net
> Subject: Re: IllegalAnnotationsException when @XmlValue and
> @XmlJavaTypeAdapter both present in xjc generated code.
>
>
> How does the definition of PropertyValue look like?
>
>
> Scudieri, Chris (IT) wrote:
>> Usage of baseType is not well documented so I may be outside of the
>> intention of the Spec.
>> However what XJC is generating is extremely close to what I am looking
>
>> for. I am trying to get an XmlAdapter to marshal/unmarshall the value
>
>> of the Property element and have run into the Following issue:
>>
>> Schema snippet:
>>
>> <xs:complexType name="Property" >
>> <xs:annotation><xs:appinfo>
>> <jaxb:property>
>> <jaxb:baseType>
>> <xjc:javaType name="com.test.PropertyValue"
>> adapter="com.test.PropertyAdapter" />
>> </jaxb:baseType>
>> </jaxb:property>
>> </xs:appinfo></xs:annotation>
>>
>> <xs:simpleContent>
>> <xs:extension base="PropertyType">
>> <xs:attribute name="type" type="PropertyTypes" />
>> </xs:extension>
>> </xs:simpleContent>
>> </xs:complexType>
>>
>> Where:
>> PropertyType is essentially anySimpleType PropertyTypes is a string
>> enum
>>
>>
>>
>> Generated Property.java:
>> public class Property {
>>
>> @XmlValue
>> @XmlJavaTypeAdapter(PropertyAdapter.class)
>> protected PropertyValue value;
>> @XmlAttribute
>> protected PropertyTypes type;
>>
>>
>> However attempting to create a context throws an
>> IllegalAnnotationsException:
>>
>> com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of
>> IllegalAnnotationExceptions @XmlAttribute/_at_XmlValue need to reference
>> a Java type that maps to text in XML.
>> this problem is related to the following location:
>> at protected com.test.PropertyValue
>> com.test.generated.Property.value
>> at com.test.generated.Property
>> at public com.test.generated.Property
>> com.test.generated.ObjectFactory.createProperty()
>> at com.test.generated.ObjectFactory
>>
>> at
>> com.sun.xml.bind.v2.runtime.IllegalAnnotationsException$Builder.check(
>> Il
>> legalAnnotationsException.java:66)
>> at
>> com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContext
>> Im
>> pl.java:405)
>> at
>>
> com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:
>> 253)
>> at
>>
> com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:84)
>> at
>>
> com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:66)
>> at
>> com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:1
>> 32
>> )
>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> at
>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.j
>> av
>> a:39)
>> at
>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccess
>> or
>> Impl.java:25)
>> at java.lang.reflect.Method.invoke(Method.java:585)
>> at
>> javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:132)
>> at javax.xml.bind.ContextFinder.find(ContextFinder.java:285)
>> at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:372)
>> at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:337)
>> at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:244)
>
>
>
> --
> Kohsuke Kawaguchi
> Sun Microsystems kohsuke.kawaguchi_at_sun.com
> --------------------------------------------------------
>
> NOTICE: If received in error, please destroy and notify sender. Sender does not intend to waive confidentiality or privilege. Use of this email is prohibited when received in error.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>
--
Kohsuke Kawaguchi
Sun Microsystems kohsuke.kawaguchi_at_sun.com