Hi Pete,

Well, I didn't know about DataFactory << operator, but I did it manually,
LoL, and it looked like the same when I define using xsd and manually.

The reason to avoid using xsd definition is that the das user would need the
das_runtime.lib and also config.xsd, however it is not a good practice for a
library.

I debugged the sdo and look like it defines a DASValue when load using xsd
and also sets the rootElementName on DataFactoryImpl. When I define manually
I set only the rootElementName, but not the DASValue. I think when the
XMLHelper reads the xml it uses this DASValue object set when the xsd is
loaded, and that is why I'm saying the xml load NEEDS xsd definition.

Above the both methods, manually and using xsd, now complete:

Manually:
commonj::sdo::DataFactoryPtr dataFactory =
commonj::sdo::DataFactory::getDataFactory();
   ((commonj::sdo::DataFactoryImpl&)
*dataFactory).setRootElementName("Config");
   dataFactory->addType(DAS_NAMESPACE, "Table");
   dataFactory->addType(DAS_NAMESPACE, "Relationship");
   dataFactory->addType(DAS_NAMESPACE, "KeyPair");
   dataFactory->addType(DAS_NAMESPACE, "Column");
   dataFactory->addType(DAS_NAMESPACE, "Config");

   const commonj::sdo::Type& table = dataFactory->getType(DAS_NAMESPACE,
"Table");
   const commonj::sdo::Type& relationship =
dataFactory->getType(DAS_NAMESPACE, "Relationship");
   const commonj::sdo::Type& keyPair = dataFactory->getType(DAS_NAMESPACE,
"KeyPair");
   const commonj::sdo::Type& column = dataFactory->getType(DAS_NAMESPACE,
"Column");
   const commonj::sdo::Type& config = dataFactory->getType(DAS_NAMESPACE,
"Config");

   dataFactory->addPropertyToType(table, "Column", column, true, false,
true);
   dataFactory->addPropertyToType(table, "tableName", SDO_NAMESPACE,
"String", false, false, true);
   dataFactory->addPropertyToType(table, "typeName", SDO_NAMESPACE,
"String", false, false, true);

   dataFactory->addPropertyToType(config, "Table", table, true, false,
true);
   dataFactory->addPropertyToType(config, "Relationship", relationship,
true, false, true);
   dataFactory->addPropertyToType(config, "uri", SDO_NAMESPACE, "String",
false, false, true);

   dataFactory->addPropertyToType(relationship, "KeyPair", keyPair, true,
false, true);
   dataFactory->addPropertyToType(relationship, "name", SDO_NAMESPACE,
"String", false, false, true);
   dataFactory->addPropertyToType(relationship, "primaryKeyTable",
SDO_NAMESPACE, "String", false, false, true);
   dataFactory->addPropertyToType(relationship, "foreignKeyTable",
SDO_NAMESPACE, "String", false, false, true);
   dataFactory->addPropertyToType(relationship, "many", SDO_NAMESPACE,
"Boolean", false, false, true);
   dataFactory->setDefault(relationship, "many", true);

   dataFactory->addPropertyToType(keyPair, "primaryKeyColumn",
SDO_NAMESPACE, "String", false, false, true);
   dataFactory->addPropertyToType(keyPair, "foreignKeyColumn",
SDO_NAMESPACE, "String", false, false, true);

   dataFactory->addPropertyToType(column, "columnName", SDO_NAMESPACE,
"String", false, false, true);
   dataFactory->addPropertyToType(column, "sqlType", SDO_NAMESPACE,
"String", false, false, true);
   dataFactory->addPropertyToType(column, "propertyName", SDO_NAMESPACE,
"String", false, false, true);
   dataFactory->addPropertyToType(column, "primaryKey", SDO_NAMESPACE,
"Boolean", false, false, true);
   dataFactory->setDefault(column, "primaryKey", false);

   dataFactory->resolve();

   commonj::sdo::XMLHelperPtr xmlh =
commonj::sdo::HelperProvider::getXMLHelper(dataFactory);
   commonj::sdo::XMLDocumentPtr doc = xmlh->loadFile(xmlFile.c_str(),
DAS_NAMESPACE);
   commonj::sdo::DataObjectPtr root = doc->getRootDataObject();

Using xsd:

commonj::sdo::DataFactoryPtr dataFactory =
commonj::sdo::DataFactory::getDataFactory();
   commonj::sdo::XSDHelperPtr xsdh =
commonj::sdo::HelperProvider::getXSDHelper(dataFactory);
   xsdh->defineFile("config.xsd");

   commonj::sdo::XMLHelperPtr xmlh =
commonj::sdo::HelperProvider::getXMLHelper(dataFactory);
   commonj::sdo::XMLDocumentPtr doc = xmlh->loadFile(xmlFile.c_str());
   commonj::sdo::DataObjectPtr root = doc->getRootDataObject();

config.xsd:

<xsd:schema
  xmlns:config="http:///org.apache.tuscany.das.rdb/config.xsd";
  xmlns:xsd="http://www.w3.org/2001/XMLSchema";
  targetNamespace="http:///org.apache.tuscany.das.rdb/config.xsd";
  elementFormDefault="qualified">

  <xsd:element name="Config" type="config:Config"/>

  <xsd:complexType name="Config">
     <xsd:all>
       <xsd:element maxOccurs="unbounded" minOccurs="0" name="Table"
type="config:Table"/>
       <xsd:element maxOccurs="unbounded" minOccurs="0" name="Relationship"
type="config:Relationship"/>
     </xsd:all>
     <xsd:attribute name="uri" type="xsd:string"/>
  </xsd:complexType>

  <xsd:complexType name="Relationship">
     <xsd:all>
        <xsd:element maxOccurs="unbounded" minOccurs="1" name="KeyPair"
type="config:KeyPair"/>
     </xsd:all>
     <xsd:attribute name="name" type="xsd:string"/>
     <xsd:attribute name="primaryKeyTable" type="xsd:string"
use="required"/>
     <xsd:attribute name="foreignKeyTable" type="xsd:string"
use="required"/>
     <xsd:attribute name="many" type="xsd:boolean" default="true"/>
  </xsd:complexType>

  <xsd:complexType name="Table">
     <xsd:all>
        <xsd:element maxOccurs="unbounded" minOccurs="0" name="Column"
type="config:Column"/>
     </xsd:all>
     <xsd:attribute name="tableName" type="xsd:string" use="required"/>
     <xsd:attribute name="typeName" type="xsd:string"/>
  </xsd:complexType>

  <xsd:complexType name="KeyPair">
     <xsd:attribute name="primaryKeyColumn" type="xsd:string"
use="required"/>
     <xsd:attribute name="foreignKeyColumn" type="xsd:string"
use="required"/>
  </xsd:complexType>

  <xsd:complexType name="Column">
     <xsd:attribute name="columnName" type="xsd:string" use="required"/>
   <xsd:attribute name="sqlType" type="xsd:string" use="required"/>
     <xsd:attribute name="propertyName" type="xsd:string"/>
     <xsd:attribute name="primaryKey" type="xsd:boolean" default="false"/>
  </xsd:complexType>

</xsd:schema>

config.xml:

<Config xmlns="http:///org.apache.tuscany.das.rdb/config.xsd";>

   <Table tableName="department">
         <Column sqlType="integer" columnName="id" primaryKey="true"/>
       <Column sqlType="varchar" columnName="name" primaryKey="true"/>
   </Table>

   <Relationship primaryKeyTable="department" foreignKeyTable="employee"
many="true">
         <KeyPair primaryKeyColumn="id" foreignKeyColumn="department_id"/>
       <KeyPair primaryKeyColumn="name"
foreignKeyColumn="department_name"/>
   </Relationship>

</Config>

Thanks,
Adriano Crestani

On 6/5/07, Pete Robbins <[EMAIL PROTECTED] > wrote:

You should be able to define the Types and Properties manually if you want

to. I would ask WHY you want to do this as using a schema is a lot
simpler!

Could you post your config.xsd and config.xml?

If you add a line

cout << dataFactory << endl;

That should print the Types and Properties you have defined and you can
compare that to the Types/Properties defined by loading the schema.

Cheers,



On 04/06/07, Adriano Crestani <[EMAIL PROTECTED]> wrote:
>
> Is there a way to load data from a XML file without a XML schema file,
> only
> defining the graph type and properties manually on code?
>
> The code bellow works:
>
> DataFactoryPtr dataFactory = DataFactory::getDataFactory();
> XSDHelperPtr xsdh = HelperProvider::getXSDHelper(dataFactory);
> xsdh->defineFile("config.xsd");
>
> XMLHelperPtr xmlh = HelperProvider::getXMLHelper(dataFactory);
> XMLDocumentPtr doc = xmlh->loadFile(" config.xml");
> DataObjectPtr root = doc->getRootDataObject();
>
> But when I defining manually the graph struct it does not:
>
> DataFactoryPtr dataFactory = DataFactory::getDataFactory();
> dataFactory->addType(DAS_NAMESPACE, "Table");
> const Type& table = dataFactory->getType(DAS_NAMESPACE, "Table");
> dataFactory->addPropertyToType(table, "tableName", SDO_NAMESPACE,
> "String",
> false, false, true);
> dataFactory->addPropertyToType(table, "typeName", SDO_NAMESPACE,
"String",
> false, false, true);
>
> dataFactory->resolve();


This method is not intended to be called by a client. I don't think it
should even be on the DataFactory interface.

XMLHelperPtr xmlh = HelperProvider::getXMLHelper(dataFactory);
> XMLDocumentPtr doc = xmlh->loadFile(" config.xml", DAS_NAMESPACE);
> DataObjectPtr root = doc->getRootDataObject(); // the root data object
> returned is NULL
>
> Adriano Crestani
>

Cheers,

--
Pete

Reply via email to