Issue Details (XML | Word | Printable)

Key: CASTOR-1226
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Werner Guttmann
Reporter: Bertrand Martel
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
castor

Source Generator > included / referenced attribute > wrong java Type

Created: 26/Sep/05 08:59 AM   Updated: 22/Oct/06 03:22 PM
Component/s: XML code generator
Affects Version/s: 0.9.9, 1.0, 1.0.1, 1.0.2, 1.0.3
Fix Version/s: 1.0.4

Time Tracking:
Not Specified

File Attachments: 1. XML File common.xsd (0.3 kB)
2. XML File convoyeur.xsd (0.7 kB)
3. Text File patch.20050929.txt (6 kB)

Environment: Windows
JDK 1.5


 Description  « Hide
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;
}



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Werner Guttmann added a comment - 26/Sep/05 10:15 AM
Bertrand, can you please attach minial XML Schema instances that I could use for testing ?

Werner Guttmann added a comment - 29/Sep/05 03:49 AM
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.

Bertrand Martel added a comment - 18/Nov/05 07:46 AM
You will find attached minimal schemas : convoyeur.xsd includes common.xsd.

The aim is to generate a Convoyeur.java class.

Cheers.

Bertrand.


Bertrand Martel added a comment - 18/Nov/05 07:47 AM
convoyeur.xsd (includes common.xsd)

Bertrand Martel added a comment - 18/Nov/05 07:47 AM
common.xsd (included by convoyeur.xsd)

Bertrand Martel added a comment - 18/Nov/05 07:49 AM
The Convoyeur class has a 'xmlDBId' field that shall be String, not object.

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