You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by "Jingkei Ly (JIRA)" <ji...@apache.org> on 2009/10/15 13:02:31 UTC

[jira] Created: (HARMONY-6355) Unable to set persistenceDelegate for a class via BeanInfo

Unable to set persistenceDelegate for a class via BeanInfo
----------------------------------------------------------

                 Key: HARMONY-6355
                 URL: https://issues.apache.org/jira/browse/HARMONY-6355
             Project: Harmony
          Issue Type: Bug
          Components: Classlib
    Affects Versions: 5.0M11
            Reporter: Jingkei Ly


As mentioned in HARMONY-6354, XMLEncoder is unable to encode an enum. One workaround (described in the comments of this bug report for the RI: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5015403) is to create a custom persistence delegate and set the persistenceDelegate for the enum via the BeanInfo's bean descriptor, i.e.:

BeanInfo info = Introspector.getBeanInfo(MyEnum.class);
info.getBeanDescriptor().setValue("persistenceDelegate", new MyCustonPersistenceDelegate());

When you use XMLEncoder.encode(), it should use the persistenceDelegate specified in the BeanDescriptor - this works in the RI, but not in Harmony.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Assigned: (HARMONY-6355) Unable to set persistenceDelegate for a class via BeanInfo

Posted by "Kevin Zhou (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HARMONY-6355?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Kevin Zhou reassigned HARMONY-6355:
-----------------------------------

    Assignee: Kevin Zhou

> Unable to set persistenceDelegate for a class via BeanInfo
> ----------------------------------------------------------
>
>                 Key: HARMONY-6355
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6355
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>    Affects Versions: 5.0M11
>            Reporter: Jingkei Ly
>            Assignee: Kevin Zhou
>         Attachments: HARMONY-6355.diff
>
>
> As mentioned in HARMONY-6354, XMLEncoder is unable to encode an enum. One workaround (described in the comments of this bug report for the RI: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5015403) is to create a custom persistence delegate and set the persistenceDelegate for the enum via the BeanInfo's bean descriptor, i.e.:
> BeanInfo info = Introspector.getBeanInfo(MyEnum.class);
> info.getBeanDescriptor().setValue("persistenceDelegate", new MyCustonPersistenceDelegate());
> When you use XMLEncoder.encode(), it should use the persistenceDelegate specified in the BeanDescriptor - this works in the RI, but not in Harmony.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (HARMONY-6355) Unable to set persistenceDelegate for a class via BeanInfo

Posted by "Li Jing Qin (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-6355?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12767275#action_12767275 ] 

Li Jing Qin commented on HARMONY-6355:
--------------------------------------

Thanks Ly. I have a patch about this issue. Would you please try it on your local?

> Unable to set persistenceDelegate for a class via BeanInfo
> ----------------------------------------------------------
>
>                 Key: HARMONY-6355
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6355
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>    Affects Versions: 5.0M11
>            Reporter: Jingkei Ly
>         Attachments: HARMONY-6355.diff
>
>
> As mentioned in HARMONY-6354, XMLEncoder is unable to encode an enum. One workaround (described in the comments of this bug report for the RI: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5015403) is to create a custom persistence delegate and set the persistenceDelegate for the enum via the BeanInfo's bean descriptor, i.e.:
> BeanInfo info = Introspector.getBeanInfo(MyEnum.class);
> info.getBeanDescriptor().setValue("persistenceDelegate", new MyCustonPersistenceDelegate());
> When you use XMLEncoder.encode(), it should use the persistenceDelegate specified in the BeanDescriptor - this works in the RI, but not in Harmony.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (HARMONY-6355) Unable to set persistenceDelegate for a class via BeanInfo

Posted by "Jingkei Ly (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-6355?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12766012#action_12766012 ] 

Jingkei Ly commented on HARMONY-6355:
-------------------------------------

package test;

import java.beans.BeanInfo;
import java.beans.DefaultPersistenceDelegate;
import java.beans.Encoder;
import java.beans.Expression;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.XMLEncoder;
import java.io.FileOutputStream;

public class TestStaticDelegate {

	public static void main(String[] args) throws Exception {
		FileOutputStream os = new FileOutputStream("test1.xml");

		XMLEncoder encoder = new XMLEncoder(os);
		encoder.writeObject(NumbersEnum2.ONE);
		encoder.flush();
		encoder.close();

	}
}

class EnumPersistenceDelegate extends DefaultPersistenceDelegate {
	private static EnumPersistenceDelegate INSTANCE = new EnumPersistenceDelegate();

	@SuppressWarnings("unchecked")
	public static void installFor(Enum<?>[] values) {
		Class<? extends Enum> declaringClass = values[0].getDeclaringClass();
		installFor(declaringClass);
		for (Enum<?> e : values) {
			if (e.getClass() != declaringClass) {
				installFor(e.getClass());
			}
		}
	}

	@SuppressWarnings("unchecked")
	private static void installFor(Class<? extends Enum> enumClass) {
		try {
			BeanInfo info = Introspector.getBeanInfo(enumClass);
			info.getBeanDescriptor().setValue("persistenceDelegate", INSTANCE);
		} catch (IntrospectionException exception) {
			throw new RuntimeException("Unable to persist enumerated type "
					+ enumClass, exception);
		}
	}

	@Override
	protected Expression instantiate(Object oldInstance, Encoder out) {
		Enum<?> e = (Enum<?>) oldInstance;
		return new Expression(Enum.class, "valueOf", new Object[] {
				e.getDeclaringClass(), e.name() });
	}

	@Override
	protected boolean mutatesTo(Object oldInstance, Object newInstance) {
		return oldInstance == newInstance;
	}
}

==================================================================

package test;

public enum NumbersEnum2 {
	ONE, TWO;
	
	static {
		EnumPersistenceDelegate.installFor(NumbersEnum2.values());
	}
}

Running this prints this message to stderr:
Exception during encoding:java.lang.Exception: failed to write expression: NumbersEnum2=Class.new();
Continue...

Whereas it runs without problem in the RI.

> Unable to set persistenceDelegate for a class via BeanInfo
> ----------------------------------------------------------
>
>                 Key: HARMONY-6355
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6355
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>    Affects Versions: 5.0M11
>            Reporter: Jingkei Ly
>
> As mentioned in HARMONY-6354, XMLEncoder is unable to encode an enum. One workaround (described in the comments of this bug report for the RI: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5015403) is to create a custom persistence delegate and set the persistenceDelegate for the enum via the BeanInfo's bean descriptor, i.e.:
> BeanInfo info = Introspector.getBeanInfo(MyEnum.class);
> info.getBeanDescriptor().setValue("persistenceDelegate", new MyCustonPersistenceDelegate());
> When you use XMLEncoder.encode(), it should use the persistenceDelegate specified in the BeanDescriptor - this works in the RI, but not in Harmony.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (HARMONY-6355) Unable to set persistenceDelegate for a class via BeanInfo

Posted by "Jingkei Ly (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-6355?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12766010#action_12766010 ] 

Jingkei Ly commented on HARMONY-6355:
-------------------------------------

This example demonstrates the problem:


> Unable to set persistenceDelegate for a class via BeanInfo
> ----------------------------------------------------------
>
>                 Key: HARMONY-6355
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6355
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>    Affects Versions: 5.0M11
>            Reporter: Jingkei Ly
>
> As mentioned in HARMONY-6354, XMLEncoder is unable to encode an enum. One workaround (described in the comments of this bug report for the RI: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5015403) is to create a custom persistence delegate and set the persistenceDelegate for the enum via the BeanInfo's bean descriptor, i.e.:
> BeanInfo info = Introspector.getBeanInfo(MyEnum.class);
> info.getBeanDescriptor().setValue("persistenceDelegate", new MyCustonPersistenceDelegate());
> When you use XMLEncoder.encode(), it should use the persistenceDelegate specified in the BeanDescriptor - this works in the RI, but not in Harmony.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (HARMONY-6355) Unable to set persistenceDelegate for a class via BeanInfo

Posted by "Kevin Zhou (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HARMONY-6355?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Kevin Zhou resolved HARMONY-6355.
---------------------------------

    Resolution: Fixed

This is duplicated to HARMONY-6422.

> Unable to set persistenceDelegate for a class via BeanInfo
> ----------------------------------------------------------
>
>                 Key: HARMONY-6355
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6355
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>    Affects Versions: 5.0M11
>            Reporter: Jingkei Ly
>            Assignee: Kevin Zhou
>         Attachments: HARMONY-6355.diff
>
>
> As mentioned in HARMONY-6354, XMLEncoder is unable to encode an enum. One workaround (described in the comments of this bug report for the RI: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5015403) is to create a custom persistence delegate and set the persistenceDelegate for the enum via the BeanInfo's bean descriptor, i.e.:
> BeanInfo info = Introspector.getBeanInfo(MyEnum.class);
> info.getBeanDescriptor().setValue("persistenceDelegate", new MyCustonPersistenceDelegate());
> When you use XMLEncoder.encode(), it should use the persistenceDelegate specified in the BeanDescriptor - this works in the RI, but not in Harmony.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (HARMONY-6355) Unable to set persistenceDelegate for a class via BeanInfo

Posted by "Li Jing Qin (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-6355?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12767276#action_12767276 ] 

Li Jing Qin commented on HARMONY-6355:
--------------------------------------

The problem seems to be every time we want a bean descriptor,harmony build a new one to return (we can find the problem in the testcase which is in the patch)

> Unable to set persistenceDelegate for a class via BeanInfo
> ----------------------------------------------------------
>
>                 Key: HARMONY-6355
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6355
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>    Affects Versions: 5.0M11
>            Reporter: Jingkei Ly
>         Attachments: HARMONY-6355.diff
>
>
> As mentioned in HARMONY-6354, XMLEncoder is unable to encode an enum. One workaround (described in the comments of this bug report for the RI: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5015403) is to create a custom persistence delegate and set the persistenceDelegate for the enum via the BeanInfo's bean descriptor, i.e.:
> BeanInfo info = Introspector.getBeanInfo(MyEnum.class);
> info.getBeanDescriptor().setValue("persistenceDelegate", new MyCustonPersistenceDelegate());
> When you use XMLEncoder.encode(), it should use the persistenceDelegate specified in the BeanDescriptor - this works in the RI, but not in Harmony.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (HARMONY-6355) Unable to set persistenceDelegate for a class via BeanInfo

Posted by "Li Jing Qin (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HARMONY-6355?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Li Jing Qin updated HARMONY-6355:
---------------------------------

    Attachment: HARMONY-6355.diff

> Unable to set persistenceDelegate for a class via BeanInfo
> ----------------------------------------------------------
>
>                 Key: HARMONY-6355
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6355
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>    Affects Versions: 5.0M11
>            Reporter: Jingkei Ly
>         Attachments: HARMONY-6355.diff
>
>
> As mentioned in HARMONY-6354, XMLEncoder is unable to encode an enum. One workaround (described in the comments of this bug report for the RI: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5015403) is to create a custom persistence delegate and set the persistenceDelegate for the enum via the BeanInfo's bean descriptor, i.e.:
> BeanInfo info = Introspector.getBeanInfo(MyEnum.class);
> info.getBeanDescriptor().setValue("persistenceDelegate", new MyCustonPersistenceDelegate());
> When you use XMLEncoder.encode(), it should use the persistenceDelegate specified in the BeanDescriptor - this works in the RI, but not in Harmony.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.