users@jaxb.java.net

RE: Re: XSD Data types

From: <HeruMartinus.Salim_at_infineon.com>
Date: Mon, 13 Nov 2006 14:10:59 +0100

Hi,

I have tried. But when I call propertyInfo.getSchemaType, it returns
null.

An what is so not understandable, when I'm calling propertyInfo.ref(),
for the simple fields, they're not returning of List of type
CBuiltinLeafInfo, but List of type
com.sun.tools.xjc.model.nav.EagerNClass, which is neither a subinterface
of CBuiltinLeafInfo, nor of CTypeInfo.
And when I try to cast it to CBuiltinLeafInfo, and later call the
getTypeName() method, it shows
"{http://www.w3.org/2001/XMLSchema}string" which is not expected (It's
however just the baseclass, not the IntegerExpr which is the subclass of
string).

Regards,
Heru

-----Original Message-----
From: Aleksei Valikov [mailto:valikov_at_gmx.net]
Sent: Monday, November 13, 2006 11:25 AM
To: users_at_jaxb.dev.java.net
Subject: Re: XSD Data types

Hi.

> I'm trying to get the type of an XSD element.
> So far I can only get the type of the generated Java Code using:
>
> Map<String, JFieldVar> fields = co.implClass.fields(); Set<String>
> fieldNames = fields.keySet(); for(String fieldName: fieldNames) {
> //String fieldName = iterator.next();
> JFieldVar field = fields.get(fieldName);
> System.out.println("Name: " + fieldName + "\tField: " +
> field.type().name() + "\n");
> if(field.type().name().equals("String"))
> {
> co.implClass.direct(getStringMethodTemplate(fieldName));
> }
> }
>
> Which I get the type inside the if expression (field.type().name()).
>
> But what I expect, when possible I would like to get the value of
> IntegerExpr which is below defined <xsd:simpleType name="IntegerExpr">
> <xsd:restriction base="xsd:string"/> </xsd:simpleType>
>
> Here is the sample of the element definition <xsd:complexType
> name="BitField">
> <xsd:complexContent>
> <xsd:extension base="essence:SingleSourceNode">
> <xsd:sequence>
> <xsd:element maxOccurs="unbounded" minOccurs="0"
> name="enumeration" type="essence:Enumeration"/>
> <xsd:element name="Offset" type="essence:IntegerExpr"/>
> <xsd:element name="Width" type="essence:IntegerExpr"/>
> <xsd:element name="AccessType" type="essence:AccessType"/>
> </xsd:sequence>
> </xsd:extension>
> </xsd:complexContent>
> </xsd:complexType>
>
> So what is expected, to get the value of "essence:IntegerExpr" when
> traversing through the field "Offset"
>
> How can we get that value? Which API can be used?

You should work with Outline/ClassOutline/FieldOutline.

Outline is given to your plugin through the run(...) method, you can
start there and walk through the structure of classOutlines and
fieldOutlines.

 From the fieldOutline you can fieldOutline.getPropertyInfo() which
describes the property. From there on try the following:
1. propertyInfo.getSchemaType().
2. Analyze propertyInfo.getSchemaComponent().
3. propertyInfo.ref() gives you types (CTypeInfo) which this property
can accept. For simple fields, CTypeInfo is CBuiltinLeafInfo and from
CBuiltinLeafInfo you can getTypeName() - this will be the QName of the
base simple type (ex. xsd:string).

Hope this helps.

Bye.
/lexi

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
For additional commands, e-mail: users-help_at_jaxb.dev.java.net