Keith,
We use a log4j Category instance, for logging. Remove or replace the cat
reference
with the for castor, or remove them.
The code:
----------------------------------------------------------------------------
----
/** Converts a Castor ValueBean instance into a XML String instance. */
public static String asXmlString(Object object, boolean doValidation) {
if (object == null) {
return null;
}
StringWriter strWri = new StringWriter(256);
try {
Marshaller marshaller = new Marshaller(strWri);
marshaller.setValidation(doValidation);
marshaller.marshal(object);
}
catch (MarshalException me) {
cat.warn("Exception while marshalling " +
object.getClass().getName(), me);
}
catch (ValidationException ve) {
cat.warn("Exception while marshalling " +
object.getClass().getName(), ve);
}
catch (IOException ioe) {
cat.warn("Exception while marshalling " +
object.getClass().getName(), ioe);
}
//cat.debug("Marshalled object as xml: " + strWri);
return strWri.toString();
}
----------------------------------------------------------------------------
----
> -----Original Message-----
> From: Keith Visco [mailto:[EMAIL PROTECTED]]
> Sent: 03 October 2002 22:04
> To: [EMAIL PROTECTED]
> Subject: Re: [castor-dev] toString() methods
>
>
>
> Hi Tjeerd,
>
> Sounds like a good approach to solving the issue.
>
> --Keith
>
> "Verhagen, Tjeerd" wrote:
> >
> > Daan, Bruce, Keith,
> >
> > We implemented the toXMLString() in a general class, as a static
> > method asXml(Object, boolean). Where the Object should actually
> > have been a super class / interface, which all Castor generated
> > classes extend / implement. Through the boolean, we can set
> > the validation on/off. This save a lot of simmular code in all
> > the generated castor beans.
> >
> > Method should have been named beter, like:
> > String asXmlString(...)
> > DOM asXmlDom(...)
> > or
> > String toXmlString(...)
> > DOM toXmlDom(...)
> >
> > Maybe there should be some general Castor util class that provides
> > such and simmular functionality.
> >
> > Tjeerd
> >
> > > -----Original Message-----
> > > From: Bruce Snyder [mailto:[EMAIL PROTECTED]]
> > > Sent: 27 September 2002 18:56
> > > To: [EMAIL PROTECTED]
> > > Subject: Re: [castor-dev] toString() methods
> > >
> > >
> > > This one time, at band camp, [EMAIL PROTECTED] said:
> > >
> > > >> <quote>
> > > >> At any rate, in applications I've built in the past where I
> > > >> wasn't using
> > > >> Castor, I implemented both toString() and toXml() methods.
> > > >> </quote>
> > > >
> > > >You lost me at a single blow. Do you mean to distinguish
> > > from toXmlCharArray()? Let's make the option Keith mentioned
> > > earlier a function-name
> > > >in org/exolab/castor/builder/castorbuilder.properties:
> > > >org.exolab.castor.builder.stringName = toBla
> > >
> > > My apologies. What I was talking about was just a general-use
> > > method for
> > > printing out an XML string representation of an object, not
> > > necessarily
> > > for use with Castor XML.
> > >
> > > >Anyway, I can get my hands on a string representation of the
> > > object, I'm just asking for less code in my program.
> > > >
> > > >Here it is:
> > > >
> > > >String xmlString(){
> > > > StringWriter w = new StringWriter();
> > > > this.marshal(w);// maybe the more generic way instatiate a
> > > marshaller:-{
> > > > return w.toString;
> > > >}
> > >
> > > Definitely possible. I've always just encapsulated the
> > > marshal() method
> > > inside my own method called marshal() and the same with
> unMarshal().
> > >
> > > Bruce
> > > --
> > > perl -e 'print
> > > unpack("u30","<0G)U8V4\@4VYY9&5R\"F9E<G)E=\$\!F<FEI+F-O;0\`\`");'
> > >
> > > -----------------------------------------------------------
> > > If you wish to unsubscribe from this mailing, send mail to
> > > [EMAIL PROTECTED] with a subject of:
> > > unsubscribe castor-dev
> > >
> >
> > This e-mail and any attachment is for authorised use by the
> intended recipient(s) only. It may contain proprietary
> material, confidential information and/or be subject to legal
> privilege. It should not be copied, disclosed to, retained
> or used by, any other party. If you are not an intended
> recipient then please promptly delete this e-mail and any
> attachment and all copies and inform the sender. Thank you.
> >
> > -----------------------------------------------------------
> > If you wish to unsubscribe from this mailing, send mail to
> > [EMAIL PROTECTED] with a subject of:
> > unsubscribe castor-dev
>
> -----------------------------------------------------------
> If you wish to unsubscribe from this mailing, send mail to
> [EMAIL PROTECTED] with a subject of:
> unsubscribe castor-dev
>
This e-mail and any attachment is for authorised use by the intended recipient(s)
only. It may contain proprietary material, confidential information and/or be subject
to legal privilege. It should not be copied, disclosed to, retained or used by, any
other party. If you are not an intended recipient then please promptly delete this
e-mail and any attachment and all copies and inform the sender. Thank you.
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev