Index: main/java/java/beans/Statement.java =================================================================== --- main/java/java/beans/Statement.java (revision 441438) +++ main/java/java/beans/Statement.java (working copy) @@ -154,18 +154,43 @@ } } else if (target instanceof Class) { Method method = null; + boolean found = false; try { - // try to look for static method at first - method = findMethod((Class) target, methodName, arguments, - true); - result = method.invoke(null, arguments); - } catch (NoSuchMethodException e) { + // try to look for a static method of class + // described by the given Class object at first + + // process only if the class differs from Class itself + if (!((Class) target).getName().equals("java.lang.Class")) { + method = findMethod((Class) target, methodName, + arguments, + true); + result = method.invoke(null, arguments); + found = true; + } + } catch (NoSuchMethodException e) {} + + if (!found) { // static method was not found - // try to invoke non-static method of Class object - method = findMethod(target.getClass(), methodName, - arguments, false); - result = method.invoke(target, arguments); + // try to invoke method of Class object + + if (methodName.equals("forName") //$NON-NLS-1$ + && arguments.length == 1 + && arguments[0] instanceof String) { + // special handling of Class.forName(String) + + try { + result = Class.forName((String) arguments[0]); + } catch (ClassNotFoundException e2) { + result = Class.forName((String) arguments[0], true, + Thread.currentThread(). + getContextClassLoader()); + } + } else { + method = findMethod(target.getClass(), methodName, + arguments, false); + result = method.invoke(target, arguments); + } } } else { Method method = findMethod(target.getClass(), methodName, Index: main/java/org/apache/harmony/beans/DefaultPersistenceDelegatesFactory.java =================================================================== --- main/java/org/apache/harmony/beans/DefaultPersistenceDelegatesFactory.java (revision 441438) +++ main/java/org/apache/harmony/beans/DefaultPersistenceDelegatesFactory.java (working copy) @@ -36,16 +36,20 @@ private static PersistenceDelegate createPersistenceDelegate(Class type) { PersistenceDelegate pd = null; + try { String className = createDefaultNameForPersistenceDelegateClass(type); + pd = (PersistenceDelegate) Class.forName(className, true, type.getClassLoader()).newInstance(); } catch (Exception e) { Class ancestor = type.getSuperclass(); - while (ancestor != null) { + while (pd == null && ancestor != null) { try { - String className = createDefaultNameForPersistenceDelegateClass(ancestor); + String className = + createDefaultNameForPersistenceDelegateClass(ancestor); + pd = (PersistenceDelegate) Class.forName(className, true, type.getClassLoader()).newInstance(); } catch (Exception e2) { Index: main/java/org/apache/harmony/beans/java_lang_reflect_ProxyPersistenceDelegate.java =================================================================== --- main/java/org/apache/harmony/beans/java_lang_reflect_ProxyPersistenceDelegate.java (revision 0) +++ main/java/org/apache/harmony/beans/java_lang_reflect_ProxyPersistenceDelegate.java (revision 0) @@ -0,0 +1,49 @@ +/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.harmony.beans; + +import java.beans.*; +import java.lang.reflect.Proxy; +import java.lang.reflect.InvocationHandler; + +public class java_lang_reflect_ProxyPersistenceDelegate extends + PersistenceDelegate { + + protected Expression instantiate(Object oldInstance, Encoder out) { + assert oldInstance instanceof Proxy : oldInstance; + + Class[] interfaces = oldInstance.getClass().getInterfaces(); + InvocationHandler handler = Proxy.getInvocationHandler(oldInstance); + + return new Expression(oldInstance, Proxy.class, "newProxyInstance", //$NON-NLS-1$ + new Object[] { oldInstance.getClass().getClassLoader(), + interfaces, handler }); + } + + protected void initialize(Class type, Object oldInstance, + Object newInstance, Encoder out) { + // check for consistency + assert oldInstance instanceof Proxy : oldInstance; + assert newInstance instanceof Proxy : newInstance; + assert newInstance == oldInstance; + } + + protected boolean mutatesTo(Object oldInstance, Object newInstance) { + assert oldInstance instanceof Proxy : oldInstance; + + return oldInstance == newInstance; + } + +} \ No newline at end of file Index: test/java/org/apache/harmony/beans/tests/java/beans/CustomizedPersistenceDelegateTest.java =================================================================== --- test/java/org/apache/harmony/beans/tests/java/beans/CustomizedPersistenceDelegateTest.java (revision 441438) +++ test/java/org/apache/harmony/beans/tests/java/beans/CustomizedPersistenceDelegateTest.java (working copy) @@ -157,7 +157,7 @@ public void testFieldPD() throws Exception { Field f = MyHandler.class.getField("i"); - enc.writeObject(f); + enc.writeObject(f); assertEquals(f, enc.get(f)); } @@ -167,7 +167,7 @@ super.writeObject(o); } - public PersistenceDelegate getPersistenceDelegate(Class type) { + public PersistenceDelegate getPersistenceDelegate(Class type) { // System.out.println("getPersistenceDelegate for " + type); return super.getPersistenceDelegate(type); } @@ -224,10 +224,16 @@ return null; } else if (method.getName().equals("getProp")) { return new Integer(i); + } else if (method.getName().equals("hashCode")) { + return this.hashCode() + 113; + } else if (method.getName().equals("equals") && + args.length == 1) { + return proxy.getClass().getName().equals( + args[0].getClass().getName()); } return null; - } - + } + public void setI(int i) { this.i = i; }