Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2006

Tip: Looking for answers? Try searching our database.

Serialization

Thread view: 
dmcreyno - 07 Dec 2006 15:13 GMT
I have a need to export an object hierarchy to several different
formats (xml, pdf, msword, etc). Each format will contain unique
information about the obejcts. For instance, the word doc might contain
information about the object's depth in the structure while the pdf
version omits this info.

I was trying to play around with serialization (as opposed to
toString()), so that I could encapsulate the unique behaviors in
decorator classes. That way, to change the protocl, all I need to do is
change the decorator. If I need a new protocol, then the only existing
code that gets changed is the decorator factory and the client making
use of the factory. The underlying algorithm should be unaltered.

I've had somewhat limit success with Externalizable. thoughts? ideas?
am i smoking crack?
Chris Uppal - 08 Dec 2006 15:51 GMT
> I have a need to export an object hierarchy to several different
> formats (xml, pdf, msword, etc). [...]
>
> I was trying to play around with serialization

I really don't see what serialization has to do with this.

Given your stated requirements, it's not completely clear that there would be
any significant gain in sharing code between the different formats (if you have
to write different information, in a different order, in a different form then
there's not too much left that's the same ;-).  If that's the case then just
write as many kinds of document writer as you need (there may be some shared
code in opening files, and so on, but not a lot).

If, there /is/ more sharable code -- say they all would transverse the object
network in the same order, then it seems reasonable to factor that out.  One
way would be to have an object who's job it was to traverse the network in some
defined order, issuing callbacks to a formatting/writing object as it went.
You can make that as simple or fancy as you like.  E.g the Traverser might keep
some sort of registry to previously written data, so the Writer could make
back-references to previously seen stuff.  Or the API between Traverser and
Writer might be rich enough that the Writer could influence the traversal
order.

   -- chris
Daniel Pitts - 08 Dec 2006 19:11 GMT
> I have a need to export an object hierarchy to several different
> formats (xml, pdf, msword, etc). Each format will contain unique
[quoted text clipped - 11 lines]
> I've had somewhat limit success with Externalizable. thoughts? ideas?
> am i smoking crack?

I say its the crack....

What you probably want to look into is MVC.

You have a model, and I assume some sort of controller, what your
stated requirements ask for is a set of views.  and XML view, a PDF
view, etc...  Each view should be implemented to be independant of the
Controller (Application logic manipulating the Model), and should only
rely on observable properties of the Model (the Model, in good design,
should handle domain logic, and only expose what is necessary for the
View to render.)

The Model shouldn't be dependent on either the Controller or any of the
View's.

Look into templating technology to implement your Views.  If this is a
webapp, JSP's could work nicely.  Also look into Velocity or
Freemarker. You might also want to look into existing PDF generating
API's.

Hope this helps.

- Daniel.
Andrew Thompson - 09 Dec 2006 01:52 GMT
> I have a need to export an object hierarchy to several different
> formats (xml, pdf, msword, etc).  ....

Had you considered producing just a single XML,
then using XSLT to produce the PDF, DOC and other
(cut-down) XML files?

Andrew T.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.