On 05/06/07, Adriano Crestani <[EMAIL PROTECTED]> wrote:
>
> Defining via a schema will have created a Type DAS_NAMESPACE#RootType
and
> properties will have been added to this for e.g. Config from the
> <xsd:element name="Config" type="config:Config"/>. Your manual version
> does
> not do this.
>
> So, when you mean to create a RootType and adding Config as a property,
> you
> mean this?:
>
> dataFactory->create(DAS_NAMESPACE, "RootType");
> dataFactory->create(DAS_NAMESPACE, "Config");
> dataFactory->addPropertyToType(DAS_NAMESPACE, "RootType", "Config",
> DAS_NAMESPACE, "Config");
Yes, that's what loading a schema would do.
I don't quite understand that... I would assume a das user would need the
> das library! ... but I haven't looked into das a lot so I don't know
what
> the api is or what the user is trying to do here!!
>
> DAS framework must be configured before usage, it can be done via code
or
> via xml. Anyway, the DAS needs to read the xml config file to set up the
> framework. I'm trying to use SDO feature that loads data from xml to
> retrieve the config info from xml file. The problem is if the DAS to
> depend
> on a xsd file to generate the sdo graph structure every time it is
> executed,
> so the user will need both, the xsd file and das_runtime.lib :s
>
> Adriano Crestani
>
> On 6/5/07, Pete Robbins <[EMAIL PROTECTED]> wrote:
> >
> > On 05/06/07, Adriano Crestani <[EMAIL PROTECTED]> wrote:
> > >
> > > 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.
> >
> >
> > Defining via a schema will have created a Type DAS_NAMESPACE#RootType
> and
> > properties will have been added to this for e.g. Config from the
> > <xsd:element name="Config" type="config:Config"/>. Your manual version
> > does
> > not do this.
> >
> > 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 don't quite understand that... I would assume a das user would need
> the
> > das library! ... but I haven't looked into das a lot so I don't know
> what
> > the api is or what the user is trying to do here!!
> >
> > 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.
> >
> >
> > The DASValue is a way of appending the schema information to the Types
> and
> > Properties. This should not be necessary in your case but is again a
> > reason
> > to use schema.
> >
> > I will need to look into the SDO code to see what the rootElementName
> is.
> > I'm not sure what it does but I AM 100% sure you shouldn't set it from
a
> > client. You should not need to use any API on DataFactoryImpl (or
> > any.....Impl class). The user API is defined in DataFactory.h
> >
> >
> > 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
> > > >
> > >
> >
> > This may be a bug in the SDOSAX2Parser. I'll try and look into it
later
> > today. When loading the xml the top level element (<Config> in this
> case)
> > should be a property on the RootType (which is undefined in your
manual
> > case). I'll need to check the rules for loading xml without a schema
in
> > the
> > spec, I know there are some other issues in this area.
> >
> > If the user of DAS needs to load xml against a DAS schema I'm sure
they
> > won't want to do all that defineType stuff so I'm still not sure what
> the
> > purpose of this is. If DAS owns the schema then it should be loading
it
> > and,
> > if necessary, providing an API to return an XMLHelper that can load
the
> > users config file??
> >
> > Cheers,
> >
> > --
> > Pete
> >
>
--
Pete