harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Spark Shen" <smallsmallor...@gmail.com>
Subject Re: [classlib][beans]PersistentDelegates implementations(Re: [jira] Updated: (HARMONY-4473) [classlib][beans] Current bean implementation does not persist awt.Choice properly)
Date Fri, 20 Jul 2007 01:41:25 GMT
2007/7/19, Alexei Zakharov <alexei.zakharov@gmail.com>:
>
> Yeah, thanks, this one is nice. :) I was waiting for the link to some
> piece of code indeed but does not matter. I've found an example in the
> patch you submitted for HARMONY-4473. I wonder why didn't we need this
> before? Perhaps all our previous persistence delegates were too simple
> - there was no PDs for collection types.
>
> Anyway, I agree that it would be more convenient to place persistence
> delegates to  "java.beans" directly. However, in this case *all* our
> PDs should be moved to this package IMO.


Yes, under this situation, all of them should be moved.

In the beginning, I wanted to use as much as existing contribution, so I
left some in o.a.h.beans, package. As things going on, It turns out that
move to java.beans package is a better choice now.

And thanks for your help so far.

With Best Regards,
>
> 2007/7/19, Spark Shen <smallsmallorgan@gmail.com>:
> > 2007/7/19, Alexei Zakharov <alexei.zakharov@gmail.com>:
> > >
> > > > In awt related persistence delegates, I need to do a check first:
> > > > 1 .PersistenceDelegate pd = enc.getPersistenceDelegate(
> oldVal.getClass
> > > ());
> > > >
> > > > 2. if (!pd.mutatesTo(oldVal, newVal)) {
> > > >         // Do something here.
> > > >     }
> > >
> > > Do you mean here, that oldVal, newVal and pd are completely unrelated
> > > to the persistence delegate that encapsulates this logic? Just try to
> > > guess why do you need this - access methods of one persistence
> > > delegate from another persistence delegate. Can you show the complete
> > > context of this?
> >
> >
> > Initialize method is used to
> > <cite from Java Doc>
> > Produce a series of statements with side effects on newInstance so that
> the
> > new instance becomes *equivalent* to oldInstance.
> > </cite from Java Doc>
> >
> > In my implementation, oldVal is some property get from oldInstance and
> > newVal is the corresponding property of the newInstance. If oldVal &
> newVal
> > is mutable, oldVal will be set to newInstance and replace newVal. That's
> how
> > the side effects work.
> >
> > Delegate used to check mutability for oldVal & newVal most likely is not
> the
> > same as that for oldInstance & newInstance, so get the delegate on the
> fly
> > is needed.
> >
> > Will this explaination be OK this time? : - )
> >
> > Regards,
> > >
> > > 2007/7/18, Spark Shen <smallsmallorgan@gmail.com>:
> > > > 2007/7/18, Alexei Zakharov <alexei.zakharov@gmail.com>:
> > > > >
> > > > > Spark,
> > > > >
> > > > > > As you can see, put these delegates into o.a.h.beans package
> would
> > > > > result in
> > > > > > tweaked code.
> > > > >
> > > > > Sorry, looks like I miss your idea.  Do we need to call some
> > > > > package-protected methods here? Could you please explain in more
> > > > > details?
> > > >
> > > >
> > > > OK, sorry for not explain myself clearly.
> > > >
> > > > In awt related persistence delegates, I need to do a check first:
> > > > 1 .PersistenceDelegate pd = enc.getPersistenceDelegate(
> oldVal.getClass
> > > ());
> > > >
> > > > 2. if (!pd.mutatesTo(oldVal, newVal)) {
> > > >         // Do something here.
> > > >     }
> > > >
> > > > As you can see, in the first step, I get the persistence delegate
> for
> > > old
> > > > value. And in the 2nd step, if this delegate says old value and new
> > > value
> > > > are mutable, then I will do something. But mutatesTo method invoked
> in
> > > the
> > > > if statement is a protected method, if I put awt delegates into
> > > > o.a.h.beanspackage, I need to do many extra work to implement
> similar
> > > > logic as above,
> > > > and the result code may become complex and ugly.
> > > >
> > > > Based on that, I prefer to move those delegates in o.a.h.beans into
> > > > java.beans.
> > > >
> > > > Thanks!
> > > > >
> > > > > 2007/7/18, Spark Shen <smallsmallorgan@gmail.com>:
> > > > > > 2007/7/18, Yang Paulex <paulex.yang@gmail.com>:
> > > > > > >
> > > > > > > Spark,
> > > > > > >
> > > > > > > I noticed that you were working at the persistent delegation
> > > > > > > implementations
> > > > > > > recently, thanks for this enhancement.
> > > > > >
> > > > > > I am now adding  persistence delegate for some classes of awt
> > > package.
> > > > > > Please refer to HY-4473 for detailed information.
> > > > > >
> > > > > > But I'm a little confused on this
> > > > > > > patch and some others before, seems you are adding the
> > > implementations
> > > > > to
> > > > > > > java.beans package, but in our former implementations,
there
> are
> > > some
> > > > > for
> > > > > > > primitive types in o.a.h.beans, I suppose they are actually
> stuffs
> > > in
> > > > > same
> > > > > > > category, so does it make sense to make them in same package?
> > > > > >
> > > > > >
> > > > > > I planed to put all the persistence delegates into
> o.a.h.beanspackage,
> > > > > but
> > > > > > encounter problem. Persistence delegate of awt classes need
to
> first
> > > > > check
> > > > > > whether target value and new value will be mutable, as below´╝Ü
> > > > > > <snip>
> > > > > > PersistenceDelegate pd = enc
> > > > > >     .getPersistenceDelegate(targetVal.getClass());
> > > > > > if (!pd.mutatesTo(targetVal, newVal)) {
> > > > > >     Statement setterStm = new Statement(oldInstance, "add",
new
> > > Object[]
> > > > > {
> > > > > > oldVal });
> > > > > >     enc.writeStatement(setterStm);
> > > > > > }
> > > > > > </snip>
> > > > > > As you can see, put these delegates into o.a.h.beans package
> would
> > > > > result in
> > > > > > tweaked code.
> > > > > >
> > > > > > I agree to put all delegates into one place. Since that way,
> code
> > > would
> > > > > be
> > > > > > more readable. And given the awt delegates implementation, my
> > > preferred
> > > > > > destination is java.beans package.
> > > > > >
> > > > > >
> > > > > > 2007/7/18, spark shen (JIRA) <jira@apache.org>:
> > > > > > > >
> > > > > > > >
> > > > > > > >      [
> > > > > > > >
> > > > > > >
> > > > >
> > >
> https://issues.apache.org/jira/browse/HARMONY-4473?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
> > > > > > > ]
> > > > > > > >
> > > > > > > > spark shen updated HARMONY-4473:
> > > > > > > > --------------------------------
> > > > > > > >
> > > > > > > >     Attachment: HY-4473.patch
> > > > > > > >
> > > > > > > > > [classlib][beans] Current bean implementation
does not
> persist
> > > > > > > > awt.Choice properly
> > > > > > > > >
> > > > > > > >
> > > > > > >
> > > > >
> > >
> ----------------------------------------------------------------------------------
> > > > > > > > >
> > > > > > > > >                 Key: HARMONY-4473
> > > > > > > > >                 URL:
> > > > > > > https://issues.apache.org/jira/browse/HARMONY-4473
> > > > > > > > >             Project: Harmony
> > > > > > > > >          Issue Type: Bug
> > > > > > > > >          Components: Classlib
> > > > > > > > >            Reporter: spark shen
> > > > > > > > >            Assignee: Tony Wu
> > > > > > > > >         Attachments: HY-4473.patch, HY-4473.sh
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > The following test case will throw StackOverflowError
on
> > > Harmony
> > > > > but
> > > > > > > > pass on RI:
> > > > > > > > > public void test_writeObject_java_awt_Choice()
{
> > > > > > > > >         ByteArrayOutputStream byteArrayOutputStream
= new
> > > > > > > > ByteArrayOutputStream();
> > > > > > > > >         XMLEncoder encoder = new XMLEncoder(new
> > > > > BufferedOutputStream(
> > > > > > > > >             byteArrayOutputStream));
> > > > > > > > >         Choice choice = new Choice();
> > > > > > > > >         encoder.writeObject(choice);
> > > > > > > > >         encoder.close();
> > > > > > > > >         DataInputStream stream = new DataInputStream(new
> > > > > > > > ByteArrayInputStream(
> > > > > > > > >                 byteArrayOutputStream.toByteArray()));
> > > > > > > > >         XMLDecoder decoder = new XMLDecoder(stream);
> > > > > > > > >         Choice aChoice = (Choice) decoder.readObject();
> > > > > > > > >         assertEquals(choice.getFocusTraversalKeysEnabled
> (),
> > > > > aChoice
> > > > > > > > >                 .getFocusTraversalKeysEnabled());
> > > > > > > > >     }
> > > > > > > > > Besides Choice, the awt classes need special
treatment
> are:
> > > > > > > > > SystemColor,
> > > > > > > > > TextAttribute,
> > > > > > > > > MenuShortcut,
> > > > > > > > > awt.Component,
> > > > > > > > > awt.Container,
> > > > > > > > > Menu,
> > > > > > > > > MenuBar,
> > > > > > > > > awt.List,
> > > > > > > > > BorderLayout,
> > > > > > > > > CardLayout,
> > > > > > > > > GridLayout,
> > > > > > > > > Insets,
> > > > > > > > > Point,
> > > > > > > > > ScrollPane
> > > > > > > >
> > > > > > > > --
> > > > > > > > This message is automatically generated by JIRA.
> > > > > > > > -
> > > > > > > > You can reply to this email to add a comment to the
issue
>
> --
> Alexei Zakharov,
> Intel ESSD
>



-- 
Spark Shen
China Software Development Lab, IBM
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message