Hi Dean,

Normally, when you create a DataObject in a DataGraph, you serialize the 
DataGraph using SDOUtil.saveDataGraph(), not XMLHelper.save(). Does that 
work properly?

That said, you should also be able to serialize any DataObject using 
XMLHelper.save(). If the object is in a container (e.g., the DataGraph in 
your example) then when you call XMLHelper.save() it's supposed to 
temporarily detach it from it's container, serialize it, and then reattach 
it at the end. So, I would expect your second example to serialize just 
like the first one. It looks to me like there may be a bug in the 
detach/reattach code in this case. Any help tracking it down would be 
appreciated.

Thanks,
Frank

"Dean Povey" <[EMAIL PROTECTED]> wrote on 07/09/2007 09:30:10 PM:

> Hi All,
> 
> I am running across a problem using XMLHelper to generate XML from
> arbitrary DataObjects.  If I create a bare DataObject it seems to work
> fine. If I use the same object contained in a DataDraph it falls in a
> heap.  I am using Tuscany SDO 1.0 Beta1.
> 
> Here is an example that illustrates the problem:
> 
> import java.io.IOException;
> 
> import org.apache.tuscany.sdo.util.SDOUtil;
> 
> import commonj.sdo.DataGraph;
> import commonj.sdo.DataObject;
> import commonj.sdo.Type;
> import commonj.sdo.helper.DataFactory;
> import commonj.sdo.helper.TypeHelper;
> import commonj.sdo.helper.XMLHelper;
> 
> public class Example {
> 
> 
>    private static final String NSURI = "http://example.com/";;
> 
>    public static void main(String[] args) throws IOException {
>       // Create an arbitrary type
>       DataObject exampleType =
> DataFactory.INSTANCE.create("commonj.sdo",
>             "Type");
>       exampleType.set("uri", NSURI);
>       exampleType.set("name", "example");
>       DataObject exampleProperty =
> exampleType.createDataObject("property");
>       exampleProperty.set("name", "property");
>       exampleProperty.set("type",
> TypeHelper.INSTANCE.getType("commonj.sdo", "String"));
>       Type type = TypeHelper.INSTANCE.define(exampleType);
> 
>       // Success
>       DataObject ok = DataFactory.INSTANCE.create(type);
>       ok.set("property", "Helloworld");
>       XMLHelper.INSTANCE.save(ok, NSURI, "example-ok",
> System.out);
> 
>       // Failure
>       System.out.println();
>       DataGraph dg = SDOUtil.createDataGraph();
>       DataObject fails = dg.createRootObject(type);
>       fails.set("property", "Helloworld");
>       XMLHelper.INSTANCE.save(fails, NSURI, "example-fail",
> System.out);
> 
>    }
> }
> 
> 
> This generates the output:
> 
> <?xml version="1.0" encoding="ASCII"?>
> <example-ok xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
> xmlns="http://example.com/"; xsi:type="example"
>     property="Helloworld"/>
> <?xml version="1.0" encoding="ASCII"?>
> <example-fail xmlns="http://example.com/"; href="root.xml#/"/>
> 
> In the later case it has failed to correctly write out the XML.
> 
> Is there something I am missing or doing wrong here?
> 
> Dean.
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to