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 / First Aid / July 2008

Tip: Looking for answers? Try searching our database.

AbstractTableModel not compatible with Swing

Thread view: 
thufir - 03 Jul 2008 09:41 GMT
What happens when AbstractTableModel is no longer compatible with Swing?

I kinda see how to use it, but don't see how XMLEncoder would work in its
place.

"Warning:  Serialized objects of this class will not be compatible with
future Swing releases. The current serialization support is appropriate
for short term storage or RMI between applications running the same
version of Swing. As of 1.4, support for long term storage of all
JavaBeansTM  has been added to the java.beans package. Please see
XMLEncoder. "

http://java.sun.com/javase/6/docs/api/javax/swing/table/
AbstractTableModel.html

thanks,

Thufir
Sabine Dinis Blochberger - 03 Jul 2008 10:40 GMT
> What happens when AbstractTableModel is no longer compatible with Swing?

First of all, it only refers to Serialized objects.

> I kinda see how to use it, but don't see how XMLEncoder would work in its
> place.

>-
XMLEncoder:

The XMLEncoder class is a complementary alternative to the
ObjectOutputStream and can used to generate a textual representation of
a JavaBean in the same way that the ObjectOutputStream can be used to
create binary representation of Serializable objects. For example, the
following fragment can be used to create a textual representation the
supplied JavaBean and all its properties:
      XMLEncoder e = new XMLEncoder(
                         new BufferedOutputStream(
                             new FileOutputStream("Test.xml")));
      e.writeObject(new JButton("Hello, world"));
      e.close();

Despite the similarity of their APIs, the XMLEncoder class is
exclusively designed for the purpose of archiving graphs of JavaBeans as
textual representations of their public properties. Like Java source
files, documents written this way have a natural immunity to changes in
the implementations of the classes involved. The ObjectOutputStream
continues to be recommended for interprocess communication and general
purpose serialization.
-<

So, for serializing JavaBeans, you would use XMLEncoder instead of
AbstractTableModel.
Signature

Sabine Dinis Blochberger

Op3racional
www.op3racional.eu

Sabine Dinis Blochberger - 03 Jul 2008 10:42 GMT
> > What happens when AbstractTableModel is no longer compatible with Swing?
> >
> > I kinda see how to use it, but don't see how XMLEncoder would work in its
> > place.

See <http://java.sun.com/products/jfc/tsc/articles/persistence4/> for
"Using XMLEncoder".
Signature

Sabine Dinis Blochberger

Op3racional
www.op3racional.eu

Sabine Dinis Blochberger - 03 Jul 2008 11:40 GMT
> See <http://java.sun.com/products/jfc/tsc/articles/persistence4/> for
> "Using XMLEncoder".

Ok, When clicking the link in my message, I get to a different page then
what I linked to (the URL is the same). :/

See the article I meant by putting "java using xmlencoder" in a serach
engine.
Signature

Sabine Dinis Blochberger

Op3racional
www.op3racional.eu

thufir - 03 Jul 2008 11:23 GMT
> So, for serializing JavaBeans, you would use XMLEncoder instead of
> AbstractTableModel.

So, if I have a Person bean, or even a Coffee bean, then persistence
would be through XMLEncoder.  If beans persist as XML, then there's no
direct database connectivity, it almost seems.  Almost a turn away from
RDBMS (and the "quagmire" which it entails).

So, rather than using an TableModel, I would just persist all the data as
XML.  Where does the RDBMS come into play?  (I'm reading that link which
you provided.)

-Thufir
Sabine Dinis Blochberger - 03 Jul 2008 11:47 GMT
> > So, for serializing JavaBeans, you would use XMLEncoder instead of
> > AbstractTableModel.
[quoted text clipped - 7 lines]
> XML.  Where does the RDBMS come into play?  (I'm reading that link which
> you provided.)

I'm not versed in Persistance at all. It seems that there are
"delegates", which you can create, so that could be a way to translate
XML to RDBMS.

Or perhaps Hibernate <http://www.hibernate.org/> is of interest to you.
It looks like a very powerful tool - it is very well known and widely
used.

Seems you have a learning curve ahead of you, best of luck. Hopefully,
someone more knowledgeable in this newsgroup will still have some more
ideas.
Signature

Sabine Dinis Blochberger

Op3racional
www.op3racional.eu

Lew - 03 Jul 2008 12:25 GMT
> Almost a turn away from
> RDBMS (and the "quagmire" which it entails).

Why do you call an RDBMS a "quagmire" (in quotes)?

Signature

Lew

thufir - 03 Jul 2008 15:41 GMT
>> Almost a turn away from
>> RDBMS (and the "quagmire" which it entails).
>
> Why do you call an RDBMS a "quagmire" (in quotes)?

Not an RDBMS itself, but ORM.

See:

http://en.wikipedia.org/wiki/Object-
Relational_impedance_mismatch#External_links

and click on:

The Vietnam of Computer Science - Examples of mismatch problems

-Thufir
RedGrittyBrick - 03 Jul 2008 14:40 GMT
>> So, for serializing JavaBeans, you would use XMLEncoder instead of
>> AbstractTableModel.

I have the feeling that the OP may have been sidetracked by the mention
of Serialization.

> So, if I have a Person bean, or even a Coffee bean, then persistence
> would be through XMLEncoder.  If beans persist as XML, then there's no
[quoted text clipped - 4 lines]
> XML.  Where does the RDBMS come into play?  (I'm reading that link which
> you provided.)

You still need a model. You still need a data store of some kind.

I see no point in serializing your Person bean to XML and then trying to
store the XML into a traditional RDBMS. I'd skip the XML step.

I'd use JDBC to directly store the Person bean as a record in a Person
table. Typically I do this using JDBC in the model classes (MVC
pattern). Usually I pass Data Transfer Objects (DTO) between View and
Model. I imagine your Person bean can be used as a DTO.

If you'd prefer something take care of the Object-Relational Mapping for
you then you should probably look at Hibernate & Spring and read about
JPA. I'd try JDBC first if you are not familiar with any of these.

I believe any of these approaches have a significant learning curve.

Signature

RGB

thufir - 03 Jul 2008 15:34 GMT
> I'd use JDBC to directly store the Person bean as a record in a Person
> table. Typically I do this using JDBC in the model classes (MVC
[quoted text clipped - 4 lines]
> you then you should probably look at Hibernate & Spring and read about
> JPA. I'd try JDBC first if you are not familiar with any of these.

OK,  thanks.

-Thufir
RedGrittyBrick - 03 Jul 2008 14:58 GMT
> What happens when AbstractTableModel is no longer compatible with Swing?

AFAIK it isn't and never will be incompatible, at least not for reasons
to do with Serialization.

> I kinda see how to use it, but don't see how XMLEncoder would work in its
> place.
>
> "Warning:  Serialized objects of this class will not be compatible with
> future Swing releases. [... from AbstractTableModel API docs]

AFAIK that just means that if you serialize your AbstractTableModel to
XML with the current release of Swing and some time later try to
deserialize that XML using a later release of Swing, the "old" XML
format may be unusable.

For me this is a good reason not to rely on Serialization for long term
persistence. I'd only use it as intended - e.g. passing objects across a
network (as in RMI). In that case, I guess you should take care that
client and server apps were built with the same version of the JDK.
Perhaps this is a reason why SOAP is a better idea than RMI.

I can't imagine why you'd serialize an AbstractTableModel. That isn't
the sort of object I'd expect to see involved in remote method calls.
And certainly not in long term persistence of data - as in storing
Person beans in a database.

Caveat Emptor: I've used Swing and JDBC but I've never serialized an
object. There is much I don't know.

Signature

RGB



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



©2008 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.