castor

Source Generator > included / referenced attribute > wrong java Type

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 0.9.9, 1.0, 1.0.1, 1.0.2, 1.0.3
  • Fix Version/s: 1.0.4
  • Component/s: XML code generator
  • Labels:
    None
  • Environment:
    Windows
    JDK 1.5
  • Number of attachments :
    3

Description

Hello,

When you reference an attribute from an included Schema, the generated java code sets the type to default : java.lang.Object, although I set the referenced attribute's type to xs:string.

eg :

included common.xsd schema extract :

<xs:attribute name="xmlDBId" type="xs:string" />

including toto.xsd schema extract :

<xs:include schemaLocation="common.xsd"/>
<xs:element name="SourceInfos">
<xs:complexType>
<xs:sequence>
<xs:element ref="SourceID"/>
</xs:sequence>
<xs:attribute ref="xmlDBId" />
</xs:complexType>
</xs:element>

===> Java code extract :

/**

  • Field _xmlDBId
    */
    private java.lang.Object _xmlDBId;

===> Patch proposal oforg.exolab.castor.builder.SourceFactory

private void processAttributes(ComplexType complexType, FactoryState state) {

if (complexType == null)
return;

Enumeration enumeration = complexType.getAttributeDecls();
XMLBindingComponent component = new XMLBindingComponent(_config);
if (_binding != null) component.setBinding(_binding);
while (enumeration.hasMoreElements()) {
AttributeDecl attr = (AttributeDecl)enumeration.nextElement();

component.setView(attr);

//-- if we have a new SimpleType...generate ClassInfo
SimpleType sType = attr.getSimpleType();

// TODO : check if new version of Castor (> 0.9.9) solves this
// Included (->referenced) attributes does not have right java type
// eg xmldbId (type = xs:string) ===> java.lang.Object
// Look for referenced type (if any) for setting type.
// BEGIN-PATCH
if (sType == null)
{
if (attr.getReference() != null)

{ attr.setSimpleType(attr.getReference().getSimpleType()); }

}
// END-PATCH

if (sType != null) {
if ( ! (SimpleTypesFactory.isBuiltInType(sType.getTypeCode())) )

if (sType.getSchema() == component.getSchema())
{
if (state.resolve(sType) == null) {
if (sType.hasFacet(Facet.ENUMERATION)) { createSourceCode(sType, state.getSGStateInfo()); }
}
}
}
FieldInfo fieldInfo = memberFactory.createFieldInfo(component, state);
handleField(fieldInfo, state);
}
return;
}

  1. common.xsd
    18/Nov/05 7:47 AM
    0.3 kB
    Bertrand Martel
  2. convoyeur.xsd
    18/Nov/05 7:47 AM
    0.7 kB
    Bertrand Martel
  3. patch.20050929.txt
    29/Sep/05 3:49 AM
    6 kB
    Werner Guttmann

Activity

Hide
Werner Guttmann added a comment -

Bertrand, can you please attach minial XML Schema instances that I could use for testing ?

Show
Werner Guttmann added a comment - Bertrand, can you please attach minial XML Schema instances that I could use for testing ?
Hide
Werner Guttmann added a comment -

Patch that includes Bertrand's suggested change as well as an initial approach towards building a CTF regression test for this. The latter is mainly for communication with Keith.

Show
Werner Guttmann added a comment - Patch that includes Bertrand's suggested change as well as an initial approach towards building a CTF regression test for this. The latter is mainly for communication with Keith.
Hide
Bertrand Martel added a comment -

You will find attached minimal schemas : convoyeur.xsd includes common.xsd.

The aim is to generate a Convoyeur.java class.

Cheers.

Bertrand.

Show
Bertrand Martel added a comment - You will find attached minimal schemas : convoyeur.xsd includes common.xsd. The aim is to generate a Convoyeur.java class. Cheers. Bertrand.
Hide
Bertrand Martel added a comment -

convoyeur.xsd (includes common.xsd)

Show
Bertrand Martel added a comment - convoyeur.xsd (includes common.xsd)
Hide
Bertrand Martel added a comment -

common.xsd (included by convoyeur.xsd)

Show
Bertrand Martel added a comment - common.xsd (included by convoyeur.xsd)
Hide
Bertrand Martel added a comment -

The Convoyeur class has a 'xmlDBId' field that shall be String, not object.

xmlDBId is defined (as xs:string) into common.xsd

Show
Bertrand Martel added a comment - The Convoyeur class has a 'xmlDBId' field that shall be String, not object. xmlDBId is defined (as xs:string) into common.xsd

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: