Thanks Dan!
And likewise I would like to Marshal to an XML string from an arbitrary
object. I tried following your lead with something like this:
/**
* Marshall Object to string
* @param obj
* @return
*/
public String marshal ( Object obj )
{
try
{
Type type = getType( obj.getClass() );
MessageContext mc = new MessageContext();
ByteArrayOutputStream out = new ByteArrayOutputStream();
XMLStreamWriter xsw = STAXUtils.createXMLStreamWriter( out, null, mc );
MessageWriter writer = new JDOMWriter ( new Element (
obj.getClass().getName() ) );
type.writeObject( obj, writer, mc );
return out.toString();
}
catch (Exception e)
{
throw new FABUncheckedException ( e );
}
}
Unfortunately, my string comes out empty :(
I also tried ElementWriter but the same thing happened.
Any ideas?
Cheers,
Adam.
----- Original Message -----
From: "Dan Diephouse" <[EMAIL PROTECTED]>
To: <[email protected]>
Cc: "joey" <[EMAIL PROTECTED]>
Sent: Friday, May 05, 2006 3:39 PM
Subject: Re: [xfire-user] Using Aegis outside of XFire?
Hi Adam,
The answer is yes and no :-) Unfortunately, Aegis isn't completely
independent of xfire-core, so you will need that as a dependency.
Here is some pseudocode:
XMLStreamReader xsr = ...;
MessageReader reader = new ElementReader(xsr);
Type type = typeMapping.getType(reader.getName());
Object o = type.readObject(reader, new MessageContext();
This could all be pretty easily wrapped in nice Marshaller/Unmarshaller
classes :-)
So yes, it should work just fine.
- Dan
Adam Chesney wrote:
Hi,
I really like the Aegis stuff in XFire.
Is it possible to use Aegis binding outside of XFire? Sort of like
XMLBeans and Castor?
Ideally I would like to be able to wrap up the binding context stuff and
do things like:
AegisBindingContext context = new AegisBindingContext();
//configure type mapping etc
then call:
ArbitraryObject obj = someObject;
String xml = context.marshall(someObject);
and conversely:
obj = (ArbitraryObject) context.unmarshall ( xml,
ArbitraryObject.class );
And then, might it be possible to produce a Schema (.xsd file) for an
arbitrary class?
I haven't really investigated how easy this might be, but if it is not
too much work, then I am up for doing it. However, my guess is that it is
far from trivial.
Cheers,
Adam Chesney
Head of Core Development
Multicom Products Ltd
=====================================================
Tel: (+44) 117 908 1254 (Direct)
Mobile (+44) 7780 962 961
email: [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
This communication is intended solely for the addressee and is
confidential.
If you are not the intended recipient, any disclosure, copying,
distribution
or any action taken or omitted to be taken in reliance on it, is
prohibited
and may be unlawful.
Although this e-mail and any attachments are believed to be free of any
virus, or any other defect which might affect any computer or IT system
into
which they are received and opened, it is the responsibility of the
recipient to ensure that they are virus free and no responsibility is
accepted by Multicom Products Limited for any loss or damage arising in
any
way from receipt or use thereof.
--
Dan Diephouse
Envoi Solutions
http://envoisolutions.com
http://netzooid.com/blog