You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@tuscany.apache.org by Dean Povey <De...@quest.com> on 2007/07/10 03:30:10 UTC

Problem with using DataGraph and XMLHelper

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: tuscany-user-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-user-help@ws.apache.org


RE: Problem with using DataGraph and XMLHelper

Posted by Dean Povey <De...@quest.com>.
> 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?

It does indeed.  That should at least keep me going. 

> 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.
> 

Indeed. I will have a quick poke, but this quickly becomes black magic
to me :-).

Dean.



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-user-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-user-help@ws.apache.org


Re: Problem with using DataGraph and XMLHelper

Posted by kelvin goodson <ke...@gmail.com>.
I opened https://issues.apache.org/jira/browse/TUSCANY-1421 to cover this
issue.
Thanks for the concise problem description, it can be the main body of the
test for the issue.
Regards, Kelvin.

On 10/07/07, Frank Budinsky <fr...@ca.ibm.com> wrote:
>
> 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" <De...@quest.com> 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: tuscany-user-unsubscribe@ws.apache.org
> > For additional commands, e-mail: tuscany-user-help@ws.apache.org
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tuscany-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: tuscany-user-help@ws.apache.org
>
>

Re: Problem with using DataGraph and XMLHelper

Posted by Frank Budinsky <fr...@ca.ibm.com>.
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" <De...@quest.com> 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: tuscany-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: tuscany-user-help@ws.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-user-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-user-help@ws.apache.org