This was also asked for back in Jun 2006, although I don't
think Brian was
using a FilterXmlObject... maybe just a custom serializer.
http://mail-archives.apache.org/mod
_mbox/xmlbeans-user/200606.mbox/%3c99479F4
D39C9244F8E17E688193A3DD89ED06A repbex02.amer.bea.com%3e
Was there ever anything done in this area?
Thanks,
cory
-----Original Message-----
From: Cory Virok [mailto:cvirok vmware.com]
Sent: Thursday, October 11, 2007 9:37 AM
To: user xmlbeans.apache.org
Subject: Using Custom XmlObject
I have a somewhat simple problem and I am 90% of the way
there with the
solution.
Problem:
I have an XML document that I create on the fly but I have
*very* large text
segments for some of the nodes. I want to be able to create
the document via
the strongly typed schema-generated classes from scomp and
then be able to
hook into the serialization of the XML tree so that when the
serialization
gets to a particular node in the tree, it will read from an
input stream that
contains my large amount of data and pipe it to the output
stream that I gave
to save().
I figured that instead of writing my own serializer/tree
walker, I would just
try and use a custom XmlObject implementation. Currently, I
have something
that extends FilterXmlObject and is hooking into the save(*)
methods. So, if
I call save(*) on it, the input stream gets read and piped
to the output
stream given to save(*).
My problem is... I can't get the FilterXmlObject into the
document! I see
lots of documentation about using FilterXmlObject but I
haven't found *any*
examples of how to get it into the tree.
Here's some code for all that just skipped the long verbage:
(just the
relevant bits)
public class PayloadInjector extends FilterXmlObject
{
private final XmlObject innerXmlObj;
private transient InputStream ins;
public PayloadInjector(XmlObject obj) {
if(obj == null) {
throw new NullPointerException();
}
this.innerXmlObj = obj;
}
Override
public XmlObject underlyingXmlObject()
{
return innerXmlObj;
}
Override
public void save(OutputStream os, XmlOptions options)
throws IOException
{
BufferedReader bin = new BufferedReader(new
InputStreamReader(ins));
String line;
while((line = bin.readLine()) != null) {
os.write(line.getBytes());
}
}
public void setInputStream(InputStream ins) {
if(ins == null) {
throw new NullPointerException();
}
this.ins = ins;
}
}
================
Override
protected void setUp() throws Exception
{
doc = FooDocument.Factory.newInstance(defaultOpts);
Foo foo = doc.addNewFoo();
pref = foo.addNewPreference();
pref.setStringValue("REPLACE ME!");
injectBuilder = new StringBuilder("YAY!, you
injected some data!");
ins = new
java.io.ByteArrayInputStream(injectBuilder.toString().getByt
es("UTF-8"));
}
public void testSaveOutputStreamXmlOptions()
{
ByteArrayOutputStream baos = new
ByteArrayOutputStream();
PayloadInjector pi = new PayloadInjector(pref);
pi.setInputStream(ins);
/* !!!!!!!!!!!!!!!!!!!!!!!!!!
* How do I get this node into doc??
* !!!!!!!!!!!!!!!!!!!!!!!!!!
*/
try {
doc.save(baos); // visually look for
} catch (IOException e) {
e.printStackTrace();
fail("Caught IOException");
}
System.out.println(baos.toString());
}
All help is appreciated.
Thanks,
cory
------------------------------------------------------------
---------
To unsubscribe, e-mail: user-unsubscribe xmlbeans.apache.org
For additional commands, e-mail: user-help xmlbeans.apache.org
------------------------------------------------------------
---------
To unsubscribe, e-mail: user-unsubscribe xmlbeans.apache.org
For additional commands, e-mail: user-help xmlbeans.apache.org
|