tuscany-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Millies, Sebastian" <sebastian.mill...@ids-scheer.com>
Subject RE: About dynamically create Type mapping to xml schema
Date Tue, 14 May 2013 06:58:31 GMT
Hello grovecai,

XSD sequences are model groups that may be flattened in the resulting SDO model.
Look at section "9.3.2 Mapping of XSD Elements" of the SDO 2.1.0 spec. It says:

Element in all, choice, or sequence
<[GROUP] maxOccurs=[G_MAX]>
<element name=[NAME]
type=[TYPE]
maxOccurs=[E_MAX] />
</[GROUP] >
where
[GROUP] = all, choice, sequence
* Element groups and model
groups are treated as if they
were expanded in place.
* A property is created for every element
many=true when E_MAX or G_MAX
is > 1

So I believe the result you're getting is in accordance with the SDO spec, at least that's
how
I read the spec.

Best,
Sebastian

From: grovecai [mailto:grovecai@gmail.com]
Sent: Tuesday, May 14, 2013 5:09 AM
To: user@tuscany.apache.org
Subject: About dynamically create Type mapping to xml schema

Hi, guys

I need to dynamically create type mapping to the below schema:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"<http://www.w3.org/2001/XMLSchema>
xmlns="http://example.com/IPO"<http://example.com/IPO>
targetNamespace="http://example.com/IPO"<http://example.com/IPO>>
    <xsd:element name="purchaseOrder" type="PurchaseOrder"/>
    <xsd:complexType name="PurchaseOrder">
        <xsd:sequence>
            <xsd:element name="shipTo" type="xsd:string" minOccurs="0"/>
            <xsd:element name="billTo" type="xsd:string" minOccurs="0"/>
            <xsd:element name="items" type="xsd:string" minOccurs="0" maxOccurs="unbounded"/>
        </xsd:sequence>
    </xsd:complexType>
</xsd:schema>
Here is my code:
       HelperContext helperContext = SDOUtil.createHelperContext();
        DataFactory df = helperContext.getDataFactory();
        DataObject typeDef = df.create("commonj.sdo", "Type");
        typeDef.set("uri", "http://example.com/IPO"<http://example.com/IPO>);
        typeDef.set("name", "PurchaseOrder");

        DataObject propDef = typeDef.createDataObject("property");
        propDef.set("name", "shipTo");
        propDef.set("type",
                helperContext.getTypeHelper().getType("commonj.sdo", "String"));

        propDef = typeDef.createDataObject("property");
        propDef.set("name", "billTo");
        propDef.set("type",
                helperContext.getTypeHelper().getType("commonj.sdo", "String"));

        propDef = typeDef.createDataObject("property");
        propDef.set("name", "items");
        propDef.set("type",
                helperContext.getTypeHelper().getType("commonj.sdo", "String"));
        propDef.set("many", true);

        Type type  = helperContext.getTypeHelper().define(typeDef);
        List types = new ArrayList<Type>();
        types.add(type);

        System.out.println(helperContext.getXSDHelper().generate(types));

The created type actually map to the below schema:
<xs:schema xmlns:sdo="commonj.sdo" xmlns:sdoJava="commonj.sdo/java"
xmlns:stn_1="http://example.com/IPO"<http://example.com/IPO> xmlns:xs="http://www.w3.org/2001/XMLSchema"<http://www.w3.org/2001/XMLSchema>
attributeFormDefault="qualified" elementFormDefault="qualified"
targetNamespace="http://example.com/IPO"<http://example.com/IPO>>
    <xs:complexType abstract="false" name="PurchaseOrder">
        <xs:sequence>
            <xs:element maxOccurs="unbounded" minOccurs="0" name="items"/>
        </xs:sequence>
        <xs:attribute name="shipTo" type="xs:string"/>
        <xs:attribute name="billTo" type="xs:string"/>
    </xs:complexType>
    <xs:element name="purchaseOrder" type="stn_1:PurchaseOrder"/>
</xs:schema>
What did I missed? I want "shipTo" and "billTo" to be elements contained in sequence, not
as attribute contained directly in complexType. Any hint may be helpful. Thank you!


Regards,

Grovecai


Software AG - Sitz/Registered office: Uhlandstra?e 12, 64297 Darmstadt, Germany - Registergericht/Commercial
register: Darmstadt HRB 1562 - Vorstand/Management Board: Karl-Heinz Streibich (Vorsitzender/Chairman),
Dr. Wolfram Jost, Arnd Zinnhardt; - Aufsichtsratsvorsitzender/Chairman of the Supervisory
Board: Dr. Andreas Bereczky - http://www.softwareag.com


Mime
View raw message