users@jaxb.java.net

Re: XSD Data types

From: Aleksei Valikov <valikov_at_gmx.net>
Date: Mon, 13 Nov 2006 11:25:11 +0100

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