Hello, I am new to castor and have a question about the setting attribute
'base' in the schema file. Using the following as a guide...

<xs:complexType>
  <xs:sequence>
    <xs:element name="dataset" maxOccurs="unbounded">
      <xs:complexType>
        <xs:sequence>
          <xs:element name="category" maxOccurs="unbounded">
            <xs:complexType>
              <xs:sequence>
                <xs:element name="view" maxOccurs="unbounded">
                  <xs:complexType>
                    <xs:complexContent>
                      <xs:extension base="viewType"/>
                    </xs:complexContent>
                  </xs:complexType>
                </xs:element>
              </xs:sequence>
              <xs:attribute name="type" type="xs:string" use="required"/>
            </xs:complexType>
          </xs:element>
        </xs:sequence>
        <xs:attribute name="type" type="xs:string" use="required"/>
      </xs:complexType>
    </xs:element>
  </xs:sequence>
</xs:complexType>

Above, there is the <xs:extension base="viewType"/> element, the viewType is
a complexType defined is the schema (not shown here). When I run this schema
through source gen it created ...

class Category {
  ...

public void addView(com.volant.adapters.pidm.model.configuration.View vView)
        throws java.lang.IndexOutOfBoundsException
    {
        _viewList.addElement(vView);
    } //-- void addView(com.volant.adapters.pidm.model.configuration.View)

  ...
}

... for <xs:element name="category" maxOccurs="unbounded"> which is what was
expected. When I tried to marshal my XML I received a ClassCastException. I
traced the exception to the CategoryDescriptor constructor where it created
a handler for Views ...

       handler = (new org.exolab.castor.xml.XMLFieldHandler() {
            public java.lang.Object getValue( java.lang.Object object ) 
                throws IllegalStateException
            {
                Category target = (Category) object;
                return target.getView();
            }
            public void setValue( java.lang.Object object, java.lang.Object
value) 
                throws IllegalStateException, IllegalArgumentException
            {
                try {
                    Category target = (Category) object;
                    target.addView(
(com.volant.adapters.pidm.model.configuration.View) value);
                }
                catch (java.lang.Exception ex) {
                    throw new IllegalStateException(ex.toString());
                }
            }
            public java.lang.Object newInstance( java.lang.Object parent ) {
                return new
com.volant.adapters.pidm.model.configuration.View();
            }
        } );

In the setValue method of the handler there is line of code ...

target.addView( (com.volant.adapters.pidm.model.configuration.View);

Why does the source gen try to cast it to a View? How do I tell the source
gen
To cast it to a ViewType which is the base class of View and instead of
addView(com.volant.adapters.pidm.model.configuration.View vView) it should
be
addView(com.volant.adapters.pidm.model.configuration.ViewType vViewType)

Thanks
J



-------------------------------------------------
If you wish to unsubscribe from this list, please 
send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------

Reply via email to