users@jaxb.java.net

Re: restriction of a type containing a "ref" element

From: Fran?ois Banel <Francois.Banel_at_filinks.com>
Date: Wed, 04 Jun 2003 12:13:15 +0200

Hello,

thank you for your response.
I tried your test class. I had no error.
But if you add the following lines in you java code :
        javax.xml.bind.Validator v = jc.createValidator();
        v.validate(order);
Then there is the following exception :
DefaultValidationEventHandler: [ERROR]: tag name "TimeLimit" is not
allowed. Possible tag names are:
<com.testfb.datamodel.restriction.TimeLimit>
javax.xml.bind.ValidationException
        at
com.sun.xml.bind.validator.ValidatorImpl.validate(ValidatorImpl.java:118)
        at
com.sun.xml.bind.validator.ValidatorImpl.validate(ValidatorImpl.java:94)
        at com.testfb.Test.main(Test.java:38)

Regards,

Francois Banel
tel : 01 53 34 30 64
mailto:Francois.Banel_at_filinks.com




Ed Mooney <Ed.Mooney_at_Sun.COM>
Sent by: Discussion list for the Java Architecture for XML Binding
<JAXB-INTEREST_at_JAVA.SUN.COM>
03/06/2003 19:15
Please respond to Discussion list for the Java Architecture for XML
Binding

 
        To: JAXB-INTEREST_at_JAVA.SUN.COM
        cc:
        Subject: Re: restriction of a type containing a "ref" element


Hi François,

I was unable to unmarshal your xml file without error using Test.java:

     java Test
     LimitType = String

All I can think of is that perhaps you're loading objects generated from
any earlier version of your schema?

Regards,
--
Ed Mooney         |Sun Microsystems, Inc.|Time flies like
Java Web Services |UBUR02-201            |an arrow, but
Ed.Mooney_at_Sun.COM |1 Network Drive       |fruit flies like
781-442-0459      |Burlington, MA  01803 |a banana. Groucho
François Banel wrote:
> Hello,
>
> I think I have found a bug in the JAXB 1.0 version.
> I have not found any reference to that problem in previous messages,
> so I post it :
>
> in the same namespace, I define an element TimeLimit, and types 
OrderType
> and SimpleOrderType.
> OrderType contains a ref to a TimeLimit element.
> SimpleOrderType is a restriction of OrderType, containing also the 
TimeLimit element.
>
> Then by unmarshalling a correct XML file (correct for XMLSpy, but it 
appears to be simple enough to be correct anyway), I obtain an object
> which cannot be validated by JAXB.
>
> The Validation Handler message is :
> message= "tag name "TimeLimit" is not allowed. Possible tag names are: 
<com.testfb.datamodel.restriction.TimeLimit>"
>
> Am I wrong in defining the schema or is it an error from JAXB ?
>
>
> The sample schema file :
>
> <?xml version="1.0" encoding="UTF-8"?>
> <schema targetNamespace="http://www.datamodel.testfb.com/restriction" xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns="http://www.w3.org/2001/XMLSchema" xmlns:res="http://www.datamodel.testfb.com/restriction" jxb:version="1.0">
>
>  <element name="TimeLimit">
>   <complexType>
>    <sequence>
>     <element name="ExpiryDate" type="date" minOccurs="0"/>
>    </sequence>
>    <attribute name="LimitType" type="string"/>
>   </complexType>
>  </element>
>
>  <complexType name="OrderType">
>   <sequence>
>    <element ref="res:TimeLimit" minOccurs="0"/>
>   </sequence>
>  </complexType>
>
>
>  <complexType name="SimpleOrderType">
>   <complexContent>
>    <restriction base="res:OrderType">
>     <sequence>
>      <element ref="res:TimeLimit" minOccurs="0"/>
>     </sequence>
>    </restriction>
>   </complexContent>
>  </complexType>
>  <element name="Order" type="res:SimpleOrderType"/>
> </schema>
>
>
> The sample xml file :
> <?xml version="1.0" encoding="UTF-8"?>
> <res:Order xmlns:res="http://www.datamodel.testfb.com/restriction" xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.datamodel.testfb.com/restriction
> C:\order_restriction.xsd">
>  <res:TimeLimit LimitType="String">
>   <ExpiryDate>1967-08-13</ExpiryDate>
>  </res:TimeLimit>
> </res:Order>
/*
 * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
import java.io.FileInputStream;
import java.io.IOException;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import com.testfb.datamodel.restriction.Order;
import com.testfb.datamodel.restriction.TimeLimitType;
public class Test {
    public static void main( String[] args ) {
        try {
            JAXBContext jc = JAXBContext.newInstance( 
"com.testfb.datamodel.restriction" );
            Unmarshaller u = jc.createUnmarshaller();
            u.setValidating(true);
            Order order =
                (Order)u.unmarshal( new FileInputStream( "res.xml" ) );
            TimeLimitType limit = order.getTimeLimit();
            System.out.println("LimitType = " + limit.getLimitType());
        } catch( JAXBException je ) {
            je.printStackTrace();
        } catch( IOException ioe ) {
            ioe.printStackTrace();
        }
    }
}