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().getBytes("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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to