You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by py...@apache.org on 2007/07/19 10:09:59 UTC
svn commit: r557518 [1/2] - in
/harmony/enhanced/classlib/branches/java6/modules:
awt/src/main/java/common/org/apache/harmony/awt/gl/font/
awt/src/main/java/common/org/apache/harmony/awt/gl/font/fontlib/
awt/src/main/native/fontlib/shared/ beans/META-I...
Author: pyang
Date: Thu Jul 19 01:09:53 2007
New Revision: 557518
URL: http://svn.apache.org/viewvc?view=rev&rev=557518
Log:
Merge updates from classlib trunk@557505 since r557124
Added:
harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/AwtChoicePersistenceDelegate.java
- copied unchanged from r557505, harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/AwtChoicePersistenceDelegate.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/AwtColorPersistenceDelegate.java
- copied unchanged from r557505, harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/AwtColorPersistenceDelegate.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/AwtComponentPersistenceDelegate.java
- copied unchanged from r557505, harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/AwtComponentPersistenceDelegate.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/AwtContainerPersistenceDelegate.java
- copied unchanged from r557505, harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/AwtContainerPersistenceDelegate.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/AwtCursorPersistenceDelegate.java
- copied unchanged from r557505, harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/AwtCursorPersistenceDelegate.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/AwtDimensionPersistenceDelegate.java
- copied unchanged from r557505, harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/AwtDimensionPersistenceDelegate.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/AwtFontPersistenceDelegate.java
- copied unchanged from r557505, harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/AwtFontPersistenceDelegate.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/AwtFontTextAttributePersistenceDelegate.java
- copied unchanged from r557505, harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/AwtFontTextAttributePersistenceDelegate.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/AwtInsetsPersistenceDelegate.java
- copied unchanged from r557505, harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/AwtInsetsPersistenceDelegate.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/AwtListPersistenceDelegate.java
- copied unchanged from r557505, harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/AwtListPersistenceDelegate.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/AwtMenuBarPersistenceDelegate.java
- copied unchanged from r557505, harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/AwtMenuBarPersistenceDelegate.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/AwtMenuPersistenceDelegate.java
- copied unchanged from r557505, harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/AwtMenuPersistenceDelegate.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/AwtMenuShortcutPersistenceDelegate.java
- copied unchanged from r557505, harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/AwtMenuShortcutPersistenceDelegate.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/AwtPointPersistenceDelegate.java
- copied unchanged from r557505, harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/AwtPointPersistenceDelegate.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/AwtRectanglePersistenceDelegate.java
- copied unchanged from r557505, harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/AwtRectanglePersistenceDelegate.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/AwtScrollPanePersistenceDelegate.java
- copied unchanged from r557505, harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/AwtScrollPanePersistenceDelegate.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/AwtSystemColorPersistenceDelegate.java
- copied unchanged from r557505, harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/AwtSystemColorPersistenceDelegate.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/ReferenceMap.java
- copied unchanged from r557505, harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/ReferenceMap.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/StandardBeanInfo.java
- copied unchanged from r557505, harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/StandardBeanInfo.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/StaticFieldPersistenceDelegate.java
- copied unchanged from r557505, harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/StaticFieldPersistenceDelegate.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/UtilMapPersistenceDelegate.java
- copied unchanged from r557505, harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/UtilMapPersistenceDelegate.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/test/resources/xml/Choice.xml
- copied unchanged from r557505, harmony/enhanced/classlib/trunk/modules/beans/src/test/resources/xml/Choice.xml
harmony/enhanced/classlib/branches/java6/modules/beans/src/test/support/java/org/apache/harmony/beans/tests/support/mock/FakeFox03.java
- copied unchanged from r557505, harmony/enhanced/classlib/trunk/modules/beans/src/test/support/java/org/apache/harmony/beans/tests/support/mock/FakeFox03.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/test/support/java/org/apache/harmony/beans/tests/support/mock/FakeFox031.java
- copied unchanged from r557505, harmony/enhanced/classlib/trunk/modules/beans/src/test/support/java/org/apache/harmony/beans/tests/support/mock/FakeFox031.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/test/support/java/org/apache/harmony/beans/tests/support/mock/FakeFox031BeanInfo.java
- copied unchanged from r557505, harmony/enhanced/classlib/trunk/modules/beans/src/test/support/java/org/apache/harmony/beans/tests/support/mock/FakeFox031BeanInfo.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/test/support/java/org/apache/harmony/beans/tests/support/mock/FakeFox03BeanInfo.java
- copied unchanged from r557505, harmony/enhanced/classlib/trunk/modules/beans/src/test/support/java/org/apache/harmony/beans/tests/support/mock/FakeFox03BeanInfo.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/test/support/java/org/apache/harmony/beans/tests/support/mock/MockInterface.java
- copied unchanged from r557505, harmony/enhanced/classlib/trunk/modules/beans/src/test/support/java/org/apache/harmony/beans/tests/support/mock/MockInterface.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/test/support/java/org/apache/harmony/beans/tests/support/mock/MockInterfaceBeanInfo.java
- copied unchanged from r557505, harmony/enhanced/classlib/trunk/modules/beans/src/test/support/java/org/apache/harmony/beans/tests/support/mock/MockInterfaceBeanInfo.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/test/support/java/org/apache/harmony/beans/tests/support/mock/MockSubClass.java
- copied unchanged from r557505, harmony/enhanced/classlib/trunk/modules/beans/src/test/support/java/org/apache/harmony/beans/tests/support/mock/MockSubClass.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/test/support/java/org/apache/harmony/beans/tests/support/mock/MockSubClassBeanInfo.java
- copied unchanged from r557505, harmony/enhanced/classlib/trunk/modules/beans/src/test/support/java/org/apache/harmony/beans/tests/support/mock/MockSubClassBeanInfo.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/test/support/java/org/apache/harmony/beans/tests/support/mock/MockSuperClass.java
- copied unchanged from r557505, harmony/enhanced/classlib/trunk/modules/beans/src/test/support/java/org/apache/harmony/beans/tests/support/mock/MockSuperClass.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/test/support/java/org/apache/harmony/beans/tests/support/mock/MockSuperClassBeanInfo.java
- copied unchanged from r557505, harmony/enhanced/classlib/trunk/modules/beans/src/test/support/java/org/apache/harmony/beans/tests/support/mock/MockSuperClassBeanInfo.java
Modified:
harmony/enhanced/classlib/branches/java6/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/font/FontManager.java
harmony/enhanced/classlib/branches/java6/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/font/fontlib/FLFontManager.java
harmony/enhanced/classlib/branches/java6/modules/awt/src/main/native/fontlib/shared/ParsingTables.cpp
harmony/enhanced/classlib/branches/java6/modules/beans/META-INF/MANIFEST.MF
harmony/enhanced/classlib/branches/java6/modules/beans/make/exclude.common
harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/DefaultPersistenceDelegate.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/Encoder.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/EventSetDescriptor.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/FeatureDescriptor.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/Introspector.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/MethodDescriptor.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/PropertyDescriptor.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/PropertyEditorManager.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/VetoableChangeSupport.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/XMLEncoder.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/org/apache/harmony/beans/editors/ColorEditor.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/org/apache/harmony/beans/editors/FontEditor.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/DefaultPersistenceDelegateTest.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/IntrospectorTest.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PersistenceDelegateTest.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyEditorManagerTest.java
Modified: harmony/enhanced/classlib/branches/java6/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/font/FontManager.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/font/FontManager.java?view=diff&rev=557518&r1=557517&r2=557518
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/font/FontManager.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/font/FontManager.java Thu Jul 19 01:09:53 2007
@@ -52,7 +52,7 @@
*/
public String[] allFamilies;
- public static final String DEFAULT_NAME = IS_FONTLIB ? "Luxi Sans" : "Default"; /* Default font name */ //$NON-NLS-1$
+ public static final String DEFAULT_NAME = IS_FONTLIB ? "DejaVu Sans" : "Default"; /* Default font name */ //$NON-NLS-1$
public static final String DIALOG_NAME = "Dialog"; /* Dialog font name */ //$NON-NLS-1$
/**
Modified: harmony/enhanced/classlib/branches/java6/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/font/fontlib/FLFontManager.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/font/fontlib/FLFontManager.java?view=diff&rev=557518&r1=557517&r2=557518
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/font/fontlib/FLFontManager.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/font/fontlib/FLFontManager.java Thu Jul 19 01:09:53 2007
@@ -89,8 +89,6 @@
allFonts.add(newFont);
}
}
-
- allFamilies = getAllFamilies();
}
@Override
Modified: harmony/enhanced/classlib/branches/java6/modules/awt/src/main/native/fontlib/shared/ParsingTables.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/awt/src/main/native/fontlib/shared/ParsingTables.cpp?view=diff&rev=557518&r1=557517&r2=557518
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/awt/src/main/native/fontlib/shared/ParsingTables.cpp (original)
+++ harmony/enhanced/classlib/branches/java6/modules/awt/src/main/native/fontlib/shared/ParsingTables.cpp Thu Jul 19 01:09:53 2007
@@ -377,21 +377,10 @@
}
subFamilyName[j] = 0;
-//#ifdef WIN32
-
-#define COMPARE_IT (!fwcscmp((ufshort *)subFamilyName,"Italic"))
+#define COMPARE_IT (!fwcscmp((ufshort *)subFamilyName,"Italic") || !fwcscmp((ufshort *)subFamilyName,"Oblique"))
#define COMPARE_BD (!fwcscmp((ufshort *)subFamilyName,"Bold"))
-#define COMPARE_BDIT (!fwcscmp((ufshort *)subFamilyName,"Bold Italic"))
-#define COMPARE_REG (!fwcscmp((ufshort *)subFamilyName,"Regular") || !fwcscmp((fwchar_t *)subFamilyName,"Normal"))
-
-/*#else
-
-#define COMPARE_IT (compare((fwchar_t *)subFamilyName, "Italic"))
-#define COMPARE_BD (compare((fwchar_t *)subFamilyName, "Bold"))
-#define COMPARE_BDIT (compare((fwchar_t *)subFamilyName, "Bold Italic"))
-#define COMPARE_REG (compare((fwchar_t *)subFamilyName, "Regular") || compare((fwchar_t *)subFamilyName, "Normal"))
-
-#endif*/
+#define COMPARE_BDIT (!fwcscmp((ufshort *)subFamilyName,"Bold Italic") || !fwcscmp((ufshort *)subFamilyName,"Bold Oblique"))
+#define COMPARE_REG (!fwcscmp((ufshort *)subFamilyName,"Regular") || !fwcscmp((fwchar_t *)subFamilyName,"Normal") || !fwcscmp((fwchar_t *)subFamilyName,"Book"))
if COMPARE_IT
{
Modified: harmony/enhanced/classlib/branches/java6/modules/beans/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/beans/META-INF/MANIFEST.MF?view=diff&rev=557518&r1=557517&r2=557518
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/beans/META-INF/MANIFEST.MF (original)
+++ harmony/enhanced/classlib/branches/java6/modules/beans/META-INF/MANIFEST.MF Thu Jul 19 01:09:53 2007
@@ -13,8 +13,10 @@
Eclipse-JREBundle: true
Import-Package: java.applet,
java.awt,
+ java.awt.dnd,
java.awt.event;resolution:=optional,
java.awt.font,
+ java.awt.image,
java.io,
java.lang,
java.lang.annotation,
@@ -22,9 +24,11 @@
java.net,
java.nio.charset;resolution:=optional,
java.security,
+ java.text,
java.util,
java.util.regex;resolution:=optional,
javax.accessibility;resolution:=optional,
+ javax.swing,
javax.xml.parsers,
org.apache.harmony.kernel.vm,
org.apache.harmony.testframework.serialization;hy_usage=test;resolution:=optional,
Modified: harmony/enhanced/classlib/branches/java6/modules/beans/make/exclude.common
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/beans/make/exclude.common?view=diff&rev=557518&r1=557517&r2=557518
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/beans/make/exclude.common (original)
+++ harmony/enhanced/classlib/branches/java6/modules/beans/make/exclude.common Thu Jul 19 01:09:53 2007
@@ -1,4 +1,3 @@
-org/apache/harmony/beans/tests/java/beans/EncoderTest.java
org/apache/harmony/beans/tests/java/beans/VetoableChangeSupportTest.java
org/apache/harmony/beans/tests/java/beans/XMLDecoderTest.java
org/apache/harmony/beans/tests/java/beans/XMLEncoderTest.java
Modified: harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/DefaultPersistenceDelegate.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/DefaultPersistenceDelegate.java?view=diff&rev=557518&r1=557517&r2=557518
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/DefaultPersistenceDelegate.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/DefaultPersistenceDelegate.java Thu Jul 19 01:09:53 2007
@@ -17,220 +17,300 @@
package java.beans;
+import java.lang.reflect.Field;
import java.lang.reflect.Method;
-
-import org.apache.harmony.beans.internal.nls.Messages;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.HashMap;
+
+/**
+ * Default PersistenceDelegate for normal classes. The instances of this class
+ * are used when other customized PersistenceDelegate is not set in the encoders
+ * for a particular type.
+ * <p>
+ * This PersistenceDelegate assumes that the bean to be made persistent has a
+ * default constructor that takes no parameters or a constructor that takes some
+ * properties as its parameters. Only the properties that can be got or set
+ * based on the knowledge gained through an introspection will be made
+ * persistent. In the case that a bean is constructed with some properties, the
+ * value of these properties should be available via the conventional getter
+ * method.
+ * </p>
+ *
+ * @see Encoder
+ */
public class DefaultPersistenceDelegate extends PersistenceDelegate {
- private String[] constructorPropertyNames;
-
- public DefaultPersistenceDelegate(String[] constructorPropertyNames) {
- String[] arr = null;
-
- // convert first letters of property names to lower case
- if (constructorPropertyNames != null) {
- arr = new String[constructorPropertyNames.length];
- for (int i = 0; i < constructorPropertyNames.length; i++) {
- if (constructorPropertyNames[i] != null
- && constructorPropertyNames[i].length() > 0) {
- arr[i] = constructorPropertyNames[i].substring(0, 1)
- .toLowerCase()
- + constructorPropertyNames[i].substring(1);
- } else {
- arr[i] = constructorPropertyNames[i];
- }
- }
- }
+ // shared empty property name array
+ private static String[] EMPTY_PROPERTIES = new String[0];
- this.constructorPropertyNames = arr;
- }
+ // names of the properties accepted by the bean's constructor
+ private String[] propertyNames = EMPTY_PROPERTIES;
+ /**
+ * Constructs a <code>DefaultPersistenceDelegate</code> instance that
+ * supports the persistence of a bean which has a default constructor.
+ *
+ */
public DefaultPersistenceDelegate() {
- this.constructorPropertyNames = null;
+ // empty
}
- @Override
- protected void initialize(Class<?> type, Object oldInstance,
- Object newInstance, Encoder out) {
-
- // added for compatibility with RI
- if (out == null) {
- throw new NullPointerException(Messages.getString("beans.4C")); //$NON-NLS-1$
+ /**
+ * Constructs a <code>DefaultPersistenceDelegate</code> instance that
+ * supports the persistence of a bean which is constructed with some
+ * properties.
+ *
+ * @param propertyNames
+ * the name of the properties that are taken as parameters by the
+ * bean's constructor
+ */
+ public DefaultPersistenceDelegate(String[] propertyNames) {
+ if (null != propertyNames) {
+ this.propertyNames = propertyNames;
}
+ }
- // added for compatibility with RI
- if (newInstance == null) {
- out.getExceptionListener().exceptionThrown(
- new NullPointerException(Messages.getString("beans.4A"))); //$NON-NLS-1$
+ /**
+ * Initializes the new instance in the new environment so that it becomes
+ * equivalent with the old one, meanwhile recording this process in the
+ * encoder.
+ * <p>
+ * This is done by inspecting each property of the bean. The property value
+ * from the old bean instance and the value from the new bean instance are
+ * both retrieved and examined to see whether the latter mutates to the
+ * former, and if not, issue a call to the write method to set the
+ * equivalent value for the new instance. Exceptions occured during this
+ * process are reported to the exception listener of the encoder.
+ * </p>
+ *
+ * @param type
+ * the type of the bean
+ * @param oldInstance
+ * the original bean object to be recorded
+ * @param newInstance
+ * the simmulating new bean object to be initialized
+ * @param enc
+ * the encoder to write the outputs to
+ */
+ protected void initialize(Class<?> type, Object oldInstance,
+ Object newInstance, Encoder enc) {
+ // Call the initialization of the super type
+ super.initialize(type, oldInstance, newInstance, enc);
+ // Continue only if initializing the "current" type
+ if (type != oldInstance.getClass()) {
return;
}
- // added for compatibility with RI
- if (oldInstance == null) {
- throw new NullPointerException(Messages.getString("beans.4C")); //$NON-NLS-1$
- }
-
+ // Get all bean properties
BeanInfo info = null;
try {
info = Introspector.getBeanInfo(type);
- } catch (IntrospectionException e) {
- out.getExceptionListener().exceptionThrown(e);
+ } catch (IntrospectionException ex) {
+ enc.getExceptionListener().exceptionThrown(ex);
return;
}
PropertyDescriptor[] pds = info.getPropertyDescriptors();
- for (PropertyDescriptor pd : pds) {
- if (!isTransient(pd)) {
- Method getter = pd.getReadMethod();
-
- if (getter != null) {
- Method setter = pd.getWriteMethod();
-
- if (setter != null) {
- Expression getterExp = new Expression(oldInstance, pd
- .getReadMethod().getName(), null);
- try {
- // Calculate the old value of the property
- Object oldValue = getterExp.getValue();
-
- // Write the getter expression to the encoder
- out.writeExpression(getterExp);
-
- // Get the target value that exists in the new
- // environment
- Object targetVal = out.get(oldValue);
-
- Object newValue = new Expression(newInstance, pd
- .getReadMethod().getName(), null)
- .getValue();
-
- /*
- * Make the target value and current property value
- * equivalent in the new environment
- */
- if (null == targetVal) {
- if (null != newValue) {
- // Set to null
- Statement setterStm = new Statement(
- oldInstance, pd.getWriteMethod()
- .getName(),
- new Object[] { null });
- out.writeStatement(setterStm);
- }
- } else {
- PersistenceDelegate delegate = out
- .getPersistenceDelegate(targetVal
- .getClass());
- if (!delegate.mutatesTo(targetVal, newValue)) {
- Statement setterStm = new Statement(
- oldInstance, pd.getWriteMethod()
- .getName(),
- new Object[] { oldValue });
- out.writeStatement(setterStm);
- }
- }
- } catch (Exception ex) {
- out.getExceptionListener().exceptionThrown(ex);
- }
- } else {
- // commented since the process should be
- // continued even if no setter is found
- // throw new Exception("no setter for " +
- // pd.getName() + " property.");
- continue;
+ // Initialize each found non-transient property
+ for (int i = 0; i < pds.length; i++) {
+ // Skip a property whose transient attribute is true
+ if (Boolean.TRUE.equals(pds[i].getValue("transient"))) { //$NON-NLS-1$
+ continue;
+ }
+ // Skip a property having no setter or getter
+ if (null == pds[i].getWriteMethod()
+ || null == pds[i].getReadMethod()) {
+ continue;
+ }
+
+ // Get the value of the property in the old instance
+ Expression getterExp = new Expression(oldInstance, pds[i]
+ .getReadMethod().getName(), null);
+ try {
+ // Calculate the old value of the property
+ Object oldVal = getterExp.getValue();
+ // Write the getter expression to the encoder
+ enc.writeExpression(getterExp);
+ // Get the target value that exists in the new environment
+ Object targetVal = enc.get(oldVal);
+ // Get the current property value in the new environment
+ Object newVal = new Expression(newInstance, pds[i]
+ .getReadMethod().getName(), null).getValue();
+ /*
+ * Make the target value and current property value equivalent
+ * in the new environment
+ */
+ if (null == targetVal) {
+ if (null != newVal) {
+ // Set to null
+ Statement setterStm = new Statement(oldInstance, pds[i]
+ .getWriteMethod().getName(),
+ new Object[] { null });
+ enc.writeStatement(setterStm);
+ }
+ } else {
+ PersistenceDelegate pd = enc
+ .getPersistenceDelegate(targetVal.getClass());
+ if (!pd.mutatesTo(targetVal, newVal)) {
+ Statement setterStm = new Statement(oldInstance, pds[i]
+ .getWriteMethod().getName(),
+ new Object[] { oldVal });
+ enc.writeStatement(setterStm);
}
}
+ } catch (Exception ex) {
+ enc.getExceptionListener().exceptionThrown(ex);
}
}
}
- @Override
- protected Expression instantiate(Object oldInstance, Encoder out) {
- Object[] args = null;
-
- if (constructorPropertyNames == null
- || constructorPropertyNames.length == 0) {
- args = new Object[] {};
- } else {
- args = new Object[constructorPropertyNames.length];
-
- try {
- PropertyDescriptor[] pds = Introspector.getBeanInfo(
- oldInstance.getClass()).getPropertyDescriptors();
-
- for (int i = 0; i < constructorPropertyNames.length; ++i) {
+ /*
+ * Get the field value of an object using privileged code.
+ */
+ @SuppressWarnings("unchecked")
+ private Object getFieldValue(Object oldInstance, String fieldName)
+ throws NoSuchFieldException, IllegalAccessException {
+ Class c = oldInstance.getClass();
+ final Field f = c.getDeclaredField(fieldName);
+ AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ f.setAccessible(true);
+ return null;
+ }
+ });
+ return f.get(oldInstance);
+ }
- boolean found = false;
+ /*
+ * Get the value for the specified property of the given bean instance.
+ */
+ private Object getPropertyValue(HashMap proDscMap, Object oldInstance,
+ String propName) throws Exception {
+ // Try to get the read method for the property
+ Method getter = null;
+ if (null != proDscMap) {
+ PropertyDescriptor pd = (PropertyDescriptor) proDscMap
+ .get(Introspector.decapitalize(propName));
+ if (null != pd) {
+ getter = pd.getReadMethod();
+ }
+ }
- for (PropertyDescriptor element : pds) {
+ // Invoke read method to get the value if found
+ if (null != getter) {
+ return getter.invoke(oldInstance, (Object[]) null);
+ }
- if (constructorPropertyNames[i].equals(element
- .getName())) {
- Method getter = element.getReadMethod();
+ // Otherwise, try to access the field directly
+ try {
+ return getFieldValue(oldInstance, propName);
+ } catch (Exception ex) {
+ // Fail, throw an exception
+ throw new NoSuchMethodException(
+ "The getter method for the property " //$NON-NLS-1$
+ + propName + " can't be found."); //$NON-NLS-1$
+ }
- if (getter != null) {
- args[i] = getter.invoke(oldInstance,
- (Object[]) null);
- found = true;
- break;
- }
+ }
- throw new NoSuchMethodException(Messages.getString(
- "beans.00", element.getName())); //$NON-NLS-1$
+ /**
+ * Returns an expression that represents a call to the bean's constructor.
+ * The constructor may take zero or more parameters, as specified when this
+ * <code>DefaultPersistenceDelegate</code> is constructed.
+ *
+ * @param oldInstance
+ * the old instance
+ * @param enc
+ * the encoder that wants to record the old instance
+ * @return an expression for instantiating an object of the same type as the
+ * old instance
+ */
+ protected Expression instantiate(Object oldInstance, Encoder enc) {
+ Object[] args = null;
- }
- }
+ // Set the constructor arguments if any property names exist
+ if (this.propertyNames.length > 0) {
+ // Prepare the property descriptors for finding getter method later
+ BeanInfo info = null;
+ HashMap proDscMap = null;
+ try {
+ info = Introspector.getBeanInfo(oldInstance.getClass(),
+ Introspector.IGNORE_ALL_BEANINFO);
+ proDscMap = internalAsMap(info.getPropertyDescriptors());
+ } catch (IntrospectionException ex) {
+ enc.getExceptionListener().exceptionThrown(ex);
+ throw new Error(ex);
+ }
- if (found == false) {
- throw new NoSuchMethodException(Messages.getString(
- "beans.01", constructorPropertyNames[i])); //$NON-NLS-1$
- }
+ // Get the arguments values
+ args = new Object[this.propertyNames.length];
+ for (int i = 0; i < this.propertyNames.length; i++) {
+ String propertyName = propertyNames[i];
+ if (null == propertyName || 0 == propertyName.length()) {
+ continue;
+ }
+ // Get the value for each property of the given instance
+ try {
+ args[i] = getPropertyValue(proDscMap, oldInstance,
+ this.propertyNames[i]);
+ } catch (Exception ex) {
+ enc.getExceptionListener().exceptionThrown(ex);
}
- } catch (RuntimeException e) {
- throw e;
- } catch (Exception e) {
- out.getExceptionListener().exceptionThrown(e);
}
-
}
- return new Expression(oldInstance, oldInstance.getClass(), "new", args); //$NON-NLS-1$
+ return new Expression(oldInstance, oldInstance.getClass(),
+ Statement.CONSTRUCTOR_NAME, args);
}
- @Override
- protected boolean mutatesTo(Object oldInstance, Object newInstance) {
- if (oldInstance != null && constructorPropertyNames != null
- && constructorPropertyNames.length > 0) {
+ private static HashMap<String, PropertyDescriptor> internalAsMap(
+ PropertyDescriptor[] propertyDescs) {
+ HashMap<String, PropertyDescriptor> map = new HashMap<String, PropertyDescriptor>();
+ for (int i = 0; i < propertyDescs.length; i++) {
+ map.put(propertyDescs[i].getName(), propertyDescs[i]);
+ }
+ return map;
+ }
- // Get explicitly declared equals method.
- Method equalsMethod = null;
+ /**
+ * Determines whether one object mutates to the other object. If this
+ * <code>DefaultPersistenceDelegate</code> is constructed with one or more
+ * property names, and the class of <code>o1</code> overrides the
+ * "equals(Object)" method, then <code>o2</code> is considered to mutate
+ * to <code>o1</code> if <code>o1</code> equals to <code>o2</code>.
+ * Otherwise, the result is the same as the definition in
+ * <code>PersistenceDelegate</code>.
+ *
+ * @param o1
+ * one object
+ * @param o2
+ * the other object
+ * @return true if second object mutates to the first object, otherwise
+ * false
+ */
+ protected boolean mutatesTo(Object o1, Object o2) {
+ if (null == o1 || null == o2) {
+ return false;
+ }
+ Class c = o1.getClass();
+ if (this.propertyNames.length > 0) {
+ // Check the "equals" method has been declared
+ Method equalMethod = null;
try {
- equalsMethod = oldInstance.getClass().getDeclaredMethod(
- "equals", new Class[] { Object.class }); //$NON-NLS-1$
-
- } catch (NoSuchMethodException e) {
- // does not declare explicitly an equals method.
+ equalMethod = c.getDeclaredMethod("equals", //$NON-NLS-1$
+ new Class[] { Object.class });
+ } catch (NoSuchMethodException ex) {
+ // ignore
}
- if (equalsMethod != null) {
- Object result;
- try {
- result = equalsMethod.invoke(oldInstance,
- new Object[] { newInstance });
- } catch (Exception e) {
- // should not happen here.
- throw new Error(e);
- }
- return ((Boolean) result).booleanValue();
+ if (null != equalMethod) {
+ return o1.equals(o2);
}
}
- return super.mutatesTo(oldInstance, newInstance);
- }
- private static boolean isTransient(PropertyDescriptor pd) {
- Boolean isTransient = (Boolean) pd.getValue("transient"); //$NON-NLS-1$
- return (isTransient != null) && isTransient.equals(Boolean.TRUE);
+ return super.mutatesTo(o1, o2);
}
-}
+}
\ No newline at end of file
Modified: harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/Encoder.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/Encoder.java?view=diff&rev=557518&r1=557517&r2=557518
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/Encoder.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/Encoder.java Thu Jul 19 01:09:53 2007
@@ -17,12 +17,14 @@
package java.beans;
+import java.awt.*;
+import java.awt.font.*;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Collection;
+import java.util.Map;
import java.util.Hashtable;
-import java.util.IdentityHashMap;
import org.apache.harmony.beans.*;
@@ -82,11 +84,29 @@
delegates.put(Method.class, new java_lang_reflect_MethodPersistenceDelegate());
delegates.put(String.class, new java_lang_StringPersistenceDelegate());
delegates.put(Proxy.class, new java_lang_reflect_ProxyPersistenceDelegate());
+
+ delegates.put(Choice.class, new AwtChoicePersistenceDelegate());
+ delegates.put(Color.class, new AwtColorPersistenceDelegate());
+ delegates.put(Container.class, new AwtContainerPersistenceDelegate());
+ delegates.put(Component.class, new AwtComponentPersistenceDelegate());
+ delegates.put(Cursor.class, new AwtCursorPersistenceDelegate());
+ delegates.put(Dimension.class, new AwtDimensionPersistenceDelegate());
+ delegates.put(Font.class, new AwtFontPersistenceDelegate());
+ delegates.put(Insets.class, new AwtInsetsPersistenceDelegate());
+ delegates.put(List.class, new AwtListPersistenceDelegate());
+ delegates.put(Menu.class, new AwtMenuPersistenceDelegate());
+ delegates.put(MenuBar.class, new AwtMenuBarPersistenceDelegate());
+ delegates.put(MenuShortcut.class, new AwtMenuShortcutPersistenceDelegate());
+ delegates.put(Point.class, new AwtPointPersistenceDelegate());
+ delegates.put(Rectangle.class, new AwtRectanglePersistenceDelegate());
+ delegates.put(SystemColor.class, new AwtSystemColorPersistenceDelegate());
+ delegates.put(TextAttribute.class, new AwtFontTextAttributePersistenceDelegate());
+
}
private ExceptionListener listener = defaultExListener;
- private IdentityHashMap oldNewMap = new IdentityHashMap();
+ private ReferenceMap oldNewMap = new ReferenceMap();
/**
* Construct a new encoder.
@@ -171,6 +191,10 @@
if (Collection.class.isAssignableFrom(type)) {
return new UtilCollectionPersistenceDelegate();
+ }
+
+ if (Map.class.isAssignableFrom(type)) {
+ return new UtilMapPersistenceDelegate();
}
if (type.isArray()) {
Modified: harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/EventSetDescriptor.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/EventSetDescriptor.java?view=diff&rev=557518&r1=557517&r2=557518
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/EventSetDescriptor.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/EventSetDescriptor.java Thu Jul 19 01:09:53 2007
@@ -38,10 +38,6 @@
private boolean unicast;
private boolean inDefaultEventSet = true;
-
- private Class awtEventListener;
-
- private Class awtEventAction;
public EventSetDescriptor(Class<?> sourceClass, String eventSetName,
Class<?> listenerType, String listenerMethodName)
@@ -52,24 +48,19 @@
listenerMethodName);
setName(eventSetName);
- setDisplayName(eventSetName);
this.listenerType = listenerType;
m = findListenerMethodByName(listenerMethodName);
checkEventType(eventSetName, m);
listenerMethodDescriptors = new ArrayList<MethodDescriptor>();
listenerMethodDescriptors.add(new MethodDescriptor(m));
- addListenerMethod = findMethodByPrefix(
- sourceClass, "add", ""); //$NON-NLS-1$ //$NON-NLS-2$
- removeListenerMethod = findMethodByPrefix(
- sourceClass, "remove", ""); //$NON-NLS-1$ //$NON-NLS-2$
+ addListenerMethod = findMethodByPrefix(sourceClass, "add", ""); //$NON-NLS-1$ //$NON-NLS-2$
+ removeListenerMethod = findMethodByPrefix(sourceClass, "remove", ""); //$NON-NLS-1$ //$NON-NLS-2$
if (addListenerMethod == null || removeListenerMethod == null) {
- throw new IntrospectionException(
- Messages.getString("beans.38")); //$NON-NLS-1$
+ throw new IntrospectionException(Messages.getString("beans.38")); //$NON-NLS-1$
}
- getListenerMethod = findMethodByPrefix(
- sourceClass, "get", "s"); //$NON-NLS-1$ //$NON-NLS-2$
+ getListenerMethod = findMethodByPrefix(sourceClass, "get", "s"); //$NON-NLS-1$ //$NON-NLS-2$
unicast = isUnicastByDefault(addListenerMethod);
}
@@ -77,10 +68,9 @@
Class<?> listenerType, String[] listenerMethodNames,
String addListenerMethodName, String removeListenerMethodName)
throws IntrospectionException {
- this(sourceClass, eventSetName, listenerType,
- listenerMethodNames, addListenerMethodName,
- removeListenerMethodName, null);
-
+ this(sourceClass, eventSetName, listenerType, listenerMethodNames,
+ addListenerMethodName, removeListenerMethodName, null);
+
}
public EventSetDescriptor(Class<?> sourceClass, String eventSetName,
@@ -92,34 +82,33 @@
listenerMethodNames);
setName(eventSetName);
- setDisplayName(eventSetName);
this.listenerType = listenerType;
listenerMethodDescriptors = new ArrayList<MethodDescriptor>();
for (String element : listenerMethodNames) {
Method m = findListenerMethodByName(element);
- //checkEventType(eventSetName, m);
+ // checkEventType(eventSetName, m);
listenerMethodDescriptors.add(new MethodDescriptor(m));
}
if (addListenerMethodName != null) {
- this.addListenerMethod = findAddRemoveListenerMethod(
- sourceClass, addListenerMethodName);
+ this.addListenerMethod = findAddRemoveListenerMethod(sourceClass,
+ addListenerMethodName);
}
if (removeListenerMethodName != null) {
this.removeListenerMethod = findAddRemoveListenerMethod(
sourceClass, removeListenerMethodName);
}
if (getListenerMethodName != null) {
- this.getListenerMethod = findGetListenerMethod(
- sourceClass, getListenerMethodName);
+ this.getListenerMethod = findGetListenerMethod(sourceClass,
+ getListenerMethodName);
}
this.unicast = isUnicastByDefault(addListenerMethod);
}
- private Method findListenerMethodByName(
- String listenerMethodName) throws IntrospectionException {
+ private Method findListenerMethodByName(String listenerMethodName)
+ throws IntrospectionException {
Method method = null;
Method[] methods = listenerType.getMethods();
for (Method m : methods) {
@@ -130,7 +119,7 @@
method = m;
break;
}
-
+
}
}
if (null == method) {
@@ -153,7 +142,6 @@
throws IntrospectionException {
setName(eventSetName);
- setDisplayName(eventSetName);
this.listenerType = listenerType;
this.listenerMethods = listenerMethods;
@@ -187,13 +175,8 @@
this.listenerMethodDescriptors = new ArrayList<MethodDescriptor>();
for (MethodDescriptor element : listenerMethodDescriptors) {
- Method listenerMethod = element.getMethod();
-
- // XXX
- // checkEventType(eventSetName, listenerMethod);
- // if (checkMethod(listenerType, listenerMethod)) {
+ element.getMethod();
this.listenerMethodDescriptors.add(element);
- // }
}
}
}
@@ -216,36 +199,39 @@
}
/**
- * Checks that given listener method has an argument of the valid type.
- * @param eventSetName event set name
- * @param listenerMethod listener method
- * @throws IntrospectionException if check fails
+ * Checks that given listener method has an argument of the valid type.
+ *
+ * @param eventSetName
+ * event set name
+ * @param listenerMethod
+ * listener method
+ * @throws IntrospectionException
+ * if check fails
*/
private static void checkEventType(String eventSetName,
Method listenerMethod) throws IntrospectionException {
Class<?>[] params = listenerMethod.getParameterTypes();
String firstParamTypeName = null;
String eventTypeName = prepareEventTypeName(eventSetName);
-
+
if (params.length > 0) {
- firstParamTypeName = BeanInfoImpl.extractShortClassName(
- params[0].getName());
+ firstParamTypeName = BeanInfoImpl.extractShortClassName(params[0]
+ .getName());
+ }
+
+ if (firstParamTypeName == null
+ || !firstParamTypeName.equals(eventTypeName)) {
+ throw new IntrospectionException(Messages.getString("beans.51", //$NON-NLS-1$
+ listenerMethod.getName(), eventTypeName));
}
-
- if (firstParamTypeName == null ||
- !firstParamTypeName.equals(eventTypeName)) {
- throw new IntrospectionException(
- Messages.getString("beans.51", //$NON-NLS-1$
- listenerMethod.getName(), eventTypeName));
- }
}
-
+
private static String prepareEventTypeName(String eventSetName) {
StringBuilder sb = new StringBuilder();
if (eventSetName != null && eventSetName.length() > 0) {
sb.append(Character.toUpperCase(eventSetName.charAt(0)));
-
+
if (eventSetName.length() > 1) {
sb.append(eventSetName.substring(1));
}
@@ -254,7 +240,7 @@
sb.append("Event"); //$NON-NLS-1$
return sb.toString();
}
-
+
public Method[] getListenerMethods() {
int i = 0;
@@ -274,9 +260,10 @@
}
public MethodDescriptor[] getListenerMethodDescriptors() {
- return listenerMethodDescriptors == null ? null :
- listenerMethodDescriptors.toArray(
- new MethodDescriptor[listenerMethodDescriptors.size()]);
+ return listenerMethodDescriptors == null ? null
+ : listenerMethodDescriptors
+ .toArray(new MethodDescriptor[listenerMethodDescriptors
+ .size()]);
}
public Method getRemoveListenerMethod() {
@@ -311,27 +298,17 @@
return inDefaultEventSet;
}
-
- private static final String AWT_EVENT_PREFIX="java.awt.event.";
-
- private boolean checkMethod(Class<?> listenerType, Method listenerMethod)
- throws IntrospectionException {
- if (listenerMethod != null && listenerType != null &&
- !listenerMethod.getDeclaringClass().isAssignableFrom(listenerType)) {
- throw new IntrospectionException(Messages.getString("beans.31", //$NON-NLS-1$
- listenerMethod.getName(), listenerType.getName()));
- }
- return true;
- }
-
-
/**
- * Searches for {add|remove}Listener methods in the event source.
- * Parameter check is also performed.
- * @param sourceClass event source class
- * @param methodName method name to search
+ * Searches for {add|remove}Listener methods in the event source. Parameter
+ * check is also performed.
+ *
+ * @param sourceClass
+ * event source class
+ * @param methodName
+ * method name to search
* @return found method
- * @throws IntrospectionException if no valid method found
+ * @throws IntrospectionException
+ * if no valid method found
*/
private Method findAddRemoveListenerMethod(Class<?> sourceClass,
String methodName) throws IntrospectionException {
@@ -345,7 +322,7 @@
methodName, listenerType.getName()));
}
}
-
+
private Method findAddRemoveListnerMethodWithLessCheck(
Class<?> sourceClass, String methodName, Class listenerTYpe)
throws IntrospectionException {
@@ -358,17 +335,17 @@
if (m.getName().equals(methodName)) {
Class[] paramTypes = m.getParameterTypes();
if (paramTypes.length == 1) {
-// String paramTypeName = paramTypes[0].getName();
-// paramTypeName = paramTypeName.substring(paramTypeName
-// .lastIndexOf(".") + 1);
-// if (paramTypeName.endsWith("Listener")) {
-// paramTypeName = paramTypeName.substring(0,
-// paramTypeName.length() - "Listener".length());
-// if (expectedListenerTypeName.startsWith(paramTypeName)) {
- method = m;
- break;
-// }
-// }
+ // String paramTypeName = paramTypes[0].getName();
+ // paramTypeName = paramTypeName.substring(paramTypeName
+ // .lastIndexOf(".") + 1);
+ // if (paramTypeName.endsWith("Listener")) {
+ // paramTypeName = paramTypeName.substring(0,
+ // paramTypeName.length() - "Listener".length());
+ // if (expectedListenerTypeName.startsWith(paramTypeName)) {
+ method = m;
+ break;
+ // }
+ // }
}
}
}
@@ -387,8 +364,7 @@
* @return found Method object for custom getListener or null if nothing is
* found
*/
- private Method findGetListenerMethod(Class<?> sourceClass,
- String methodName) {
+ private Method findGetListenerMethod(Class<?> sourceClass, String methodName) {
try {
return sourceClass.getMethod(methodName);
} catch (Exception e) {
@@ -397,12 +373,12 @@
}
}
- private Method findMethodByPrefix(Class<?> sourceClass,
- String prefix, String postfix) {
+ private Method findMethodByPrefix(Class<?> sourceClass, String prefix,
+ String postfix) {
String shortName = listenerType.getName();
- if(listenerType.getPackage()!= null){
- shortName = shortName.substring(
- listenerType.getPackage().getName().length() + 1);
+ if (listenerType.getPackage() != null) {
+ shortName = shortName.substring(listenerType.getPackage().getName()
+ .length() + 1);
}
String methodName = prefix + shortName + postfix;
try {
@@ -413,8 +389,8 @@
return null;
}
Method[] m = sourceClass.getMethods();
- for(int i = 0; i < m.length; i++){
- if(m[i].getName().equals(methodName)){
+ for (int i = 0; i < m.length; i++) {
+ if (m[i].getName().equals(methodName)) {
Class[] paramTypes = m[i].getParameterTypes();
if (paramTypes.length == 1) {
return m[i];
@@ -436,46 +412,27 @@
return false;
}
+ void merge(EventSetDescriptor event) {
+ super.merge(event);
+ if (addListenerMethod == null) {
+ addListenerMethod = event.addListenerMethod;
+ }
+ if (getListenerMethod == null) {
+ getListenerMethod = event.getListenerMethod;
+ }
+ if (listenerMethodDescriptors == null) {
+ listenerMethodDescriptors = event.listenerMethodDescriptors;
+ }
+ if (listenerMethods == null) {
+ listenerMethods = event.listenerMethods;
+ }
+ if (listenerType == null) {
+ listenerType = event.listenerType;
+ }
-//TODO investigate, do we need the following code?
-
-// private static Method checkRegistrationMethod(Class<?> listenerType,
-// Method registrationMethod) throws IntrospectionException {
-// if (registrationMethod == null) {
-// return null;
-// }
-// Class<?> returnType = registrationMethod.getReturnType();
-// Class<?>[] parameterTypes;
-// if (returnType != void.class) {
-// throw new IntrospectionException(Messages.getString(
-// "beans.33", registrationMethod.getName())); //$NON-NLS-1$
-// }
-// parameterTypes = registrationMethod.getParameterTypes();
-// if (parameterTypes == null || parameterTypes.length != 1) {
-// throw new IntrospectionException(Messages.getString(
-// "beans.34", registrationMethod.getName())); //$NON-NLS-1$
-// } else if (parameterTypes[0] != listenerType) {
-// throw new IntrospectionException(Messages.getString(
-// "beans.35", listenerType.getName())); //$NON-NLS-1$
-// } else {
-// return registrationMethod;
-// }
-// }
-
-// private static Method checkGetListenerMethod(Class<?> listenerType, Method getListenerMethod)
-// throws IntrospectionException {
-// if (getListenerMethod == null) {
-// return null;
-// }
-// Class<?>[] parameterTypes = getListenerMethod.getParameterTypes();
-// Class<?> returnType;
-// if (parameterTypes.length != 0) {
-// throw new IntrospectionException(Messages.getString("beans.36")); //$NON-NLS-1$
-// }
-// returnType = getListenerMethod.getReturnType();
-// if (returnType.isArray() && returnType.getComponentType() == listenerType) {
-// return getListenerMethod;
-// }
-// throw new IntrospectionException(Messages.getString("beans.37")); //$NON-NLS-1$
-// }
+ if (removeListenerMethod == null) {
+ removeListenerMethod = event.removeListenerMethod;
+ }
+ inDefaultEventSet &= event.inDefaultEventSet;
+ }
}
Modified: harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/FeatureDescriptor.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/FeatureDescriptor.java?view=diff&rev=557518&r1=557517&r2=557518
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/FeatureDescriptor.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/FeatureDescriptor.java Thu Jul 19 01:09:53 2007
@@ -231,4 +231,20 @@
public boolean isExpert() {
return expert;
}
+
+ void merge(FeatureDescriptor feature){
+ assert(name.equals(feature.name));
+ expert |= feature.expert;
+ hidden |= feature.hidden;
+ preferred |= feature.preferred;
+ if(shortDescription == null){
+ shortDescription = feature.shortDescription;
+ }
+ if(name == null){
+ name = feature.name;
+ }
+ if(displayName == null){
+ displayName = feature.displayName;
+ }
+ }
}
Modified: harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/Introspector.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/Introspector.java?view=diff&rev=557518&r1=557517&r2=557518
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/Introspector.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/Introspector.java Thu Jul 19 01:09:53 2007
@@ -17,246 +17,339 @@
package java.beans;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
+import java.util.Collections;
import java.util.Map;
+import java.util.WeakHashMap;
-import org.apache.harmony.beans.internal.nls.Messages;
-
+/**
+ * The <code>Introspector</code> is a utility for developers to figure out
+ * which properties, events, and methods a JavaBean supports.
+ * <p>
+ * The <code>Introspector</code> class walks over the class/superclass chain
+ * of the target bean class. At each level it checks if there is a matching
+ * <code>BeanInfo</code> class which provides explicit information about the
+ * bean, and if so uses that explicit information. Otherwise it uses the low
+ * level reflection APIs to study the target class and uses design patterns to
+ * analyze its behaviour and then proceeds to continue the introspection with
+ * its baseclass.
+ * </p>
+ * <p>
+ * To look for the explicit information of a bean:
+ * </p>
+ * <ol>
+ * <li>The <code>Introspector</code> appends "BeanInfo" to the qualified name
+ * of the bean class, try to use the new class as the "BeanInfo" class. If the
+ * "BeanInfo" class exsits and returns non-null value when queried for explicit
+ * information, use the explicit information</li>
+ * <li>If the first step fails, the <code>Introspector</code> will extract a
+ * simple class name of the bean class by removing the package name from the
+ * qualified name of the bean class, append "BeanInfo" to it. And look for the
+ * simple class name in the packages defined in the "BeanInfo" search path (The
+ * default "BeanInfo" search path is <code>sun.beans.infos</code>). If it
+ * finds a "BeanInfo" class and the "BeanInfo" class returns non-null value when
+ * queried for explicit information, use the explicit information</li>
+ * </ol>
+ *
+ */
+//ScrollPane cannot be introspected correctly
+public class Introspector extends java.lang.Object {
+
+ // Public fields
+ /**
+ * Constant values to indicate that the <code>Introspector</code> will
+ * ignore all <code>BeanInfo</code> class.
+ */
+ public static final int IGNORE_ALL_BEANINFO = 3;
-public class Introspector {
+ /**
+ * Constant values to indicate that the <code>Introspector</code> will
+ * ignore the <code>BeanInfo</code> class of the current bean class.
+ */
+ public static final int IGNORE_IMMEDIATE_BEANINFO = 2;
+ /**
+ * Constant values to indicate that the <code>Introspector</code> will use
+ * all <code>BeanInfo</code> class which have been found. This is the default one.
+ */
public static final int USE_ALL_BEANINFO = 1;
- public static final int IGNORE_IMMEDIATE_BEANINFO = 2;
+ // Default search path for BeanInfo classes
+ private static final String DEFAULT_BEANINFO_SEARCHPATH = "sun.beans.infos"; //$NON-NLS-1$
- public static final int IGNORE_ALL_BEANINFO = 3;
+ // The search path to use to find BeanInfo classes
+ // - an array of package names that are used in turn
+ private static String[] searchPath = { DEFAULT_BEANINFO_SEARCHPATH };
+
+ // The cache to store Bean Info objects that have been found or created
+ private static final int DEFAULT_CAPACITY = 128;
+
+ private static Map<Class, StandardBeanInfo> theCache = Collections.synchronizedMap(new WeakHashMap<Class, StandardBeanInfo>(DEFAULT_CAPACITY));
private Introspector() {
+ super();
}
+ /**
+ * Decapitalizes a given string according to the rule:
+ * <ul>
+ * <li>If the first or only character is Upper Case, it is made Lower Case
+ * <li>UNLESS the second character is also Upper Case, when the String is
+ * returned unchanged <eul>
+ *
+ * @param name -
+ * the String to decapitalize
+ * @return the decapitalized version of the String
+ */
public static String decapitalize(String name) {
- if ((name != null) && (name.length() > 0)) {
- String result;
-
- // first two letters are capital
- if ((name.length() > 1)
- && Character.isUpperCase(name.charAt(0))
- && Character.isUpperCase(name.charAt(1))) {
- return name;
- }
-
- result = name.substring(0, 1).toLowerCase();
- if (name.length() > 1) {
- result += name.substring(1);
- }
-
- return result;
- }
- return name;
- }
- public static BeanInfo getBeanInfo(Class<?> beanClass, int flags)
- throws IntrospectionException {
- switch (flags) {
- case USE_ALL_BEANINFO:
- return getBeanInfo(beanClass, null, false, false);
- case IGNORE_IMMEDIATE_BEANINFO:
- return getBeanInfo(beanClass, null, true, false);
- case IGNORE_ALL_BEANINFO:
- return getBeanInfo(beanClass, null, true, true);
- default:
- // TODO: verify that default behavior complies with RI
- return getBeanInfo(beanClass, null, false, false);
+ if (name == null)
+ return null;
+ // The rule for decapitalize is that:
+ // If the first letter of the string is Upper Case, make it lower case
+ // UNLESS the second letter of the string is also Upper Case, in which case no
+ // changes are made.
+ if (name.length() == 0 || (name.length() > 1 && Character.isUpperCase(name.charAt(1)))) {
+ return name;
}
+
+ char[] chars = name.toCharArray();
+ chars[0] = Character.toLowerCase(chars[0]);
+ return new String(chars);
}
+ /**
+ * Flushes all <code>BeanInfo</code> caches.
+ *
+ */
+ public static void flushCaches() {
+ // Flush the cache by throwing away the cache HashMap and creating a
+ // new empty one
+ theCache.clear();
+ }
+
+ /**
+ * Flushes the <code>BeanInfo</code> caches of the specified bean class
+ *
+ * @param clazz
+ * the specified bean class
+ */
+ public static void flushFromCaches(Class<?> clazz) {
+ if(clazz == null){
+ throw new NullPointerException();
+ }
+ theCache.remove(clazz);
+ }
+
+ /**
+ * Gets the <code>BeanInfo</code> object which contains the information of
+ * the properties, events and methods of the specified bean class.
+ *
+ * <p>
+ * The <code>Introspector</code> will cache the <code>BeanInfo</code>
+ * object. Subsequent calls to this method will be answered with the cached
+ * data.
+ * </p>
+ *
+ * @param beanClass
+ * the specified bean class.
+ * @return the <code>BeanInfo</code> of the bean class.
+ * @throws IntrospectionException
+ */
public static BeanInfo getBeanInfo(Class<?> beanClass)
throws IntrospectionException {
- return getBeanInfo(beanClass, null, false, false);
- }
-
+ StandardBeanInfo beanInfo = theCache.get(beanClass);
+ if (beanInfo == null) {
+ beanInfo = getBeanInfoImplAndInit(beanClass, null, USE_ALL_BEANINFO);
+ theCache.put(beanClass, beanInfo);
+ }
+ return beanInfo;
+ }
+
+ /**
+ * Gets the <code>BeanInfo</code> object which contains the information of
+ * the properties, events and methods of the specified bean class. It will
+ * not introspect the "stopclass" and its super class.
+ *
+ * <p>
+ * The <code>Introspector</code> will cache the <code>BeanInfo</code>
+ * object. Subsequent calls to this method will be answered with the cached
+ * data.
+ * </p>
+ *
+ * @param beanClass
+ * the specified beanClass.
+ * @param stopClass
+ * the sopt class which should be super class of the bean class.
+ * May be null.
+ * @return the <code>BeanInfo</code> of the bean class.
+ * @throws IntrospectionException
+ */
public static BeanInfo getBeanInfo(Class<?> beanClass, Class<?> stopClass)
throws IntrospectionException {
- return getBeanInfo(beanClass, stopClass, false, false);
- }
-
- public static void setBeanInfoSearchPath(String[] searchPath) {
- SecurityManager sm = System.getSecurityManager();
-
- if (sm != null) {
- sm.checkPropertiesAccess();
- }
- synchronized(Introspector.class) {
- path = searchPath;
- }
- }
-
- public static synchronized String[] getBeanInfoSearchPath() {
- // compatible with RI
- if (path == null) {
- throw new NullPointerException(
- Messages.getString("beans.4F")); //$NON-NLS-1$
- }
-
- return path.clone();
- }
-
- public static void flushFromCaches(Class<?> clz) {
- removeBeanInfoClassFromCache(clz);
- }
-
- public static void flushCaches() {
- removeAllBeanInfoClassesFromCache();
- }
-
- // private methods
-
- private static BeanInfoWrapper getBeanInfo(Class<?> beanClass,
- Class<?> stopClass, boolean ignoreBeanClassBeanInfo,
- boolean ignoreSuperClassBeanInfo) throws IntrospectionException {
- BeanInfoWrapper beanInfoWrapper;
- BeanInfo beanInfo;
- BeanInfoImpl beanInfoImpl;
- BeanInfoWrapper wrapper;
- Class<?> parent;
-
- if (beanClass == null) {
- throw new java.lang.NullPointerException();
- }
-
- if (stopClass != null && !stopClass.isAssignableFrom(beanClass)) {
- throw new IntrospectionException(
- Messages.getString("beans.4E")); //$NON-NLS-1$
- }
-
- beanInfoWrapper = findBeanInfoClassInCache(beanClass,
- stopClass, ignoreBeanClassBeanInfo, ignoreSuperClassBeanInfo);
-
- if (beanInfoWrapper != null) {
- return beanInfoWrapper;
- }
-
- // find bean info as a separate class
-
- beanInfo = null;
-
- if (!ignoreBeanClassBeanInfo) {
- try {
- Class<?> beanInfoClass = findBeanInfoClass(beanClass);
-
- if (beanInfoClass != null) {
- beanInfo = (BeanInfo) beanInfoClass.newInstance();
- }
- } catch (Exception e) {
+ if(stopClass == null){
+ //try to use cache
+ return getBeanInfo(beanClass);
+ }
+ return getBeanInfoImplAndInit(beanClass, stopClass, USE_ALL_BEANINFO);
+ }
+
+ /**
+ * Gets the <code>BeanInfo</code> object which contains the information of
+ * the properties, events and methods of the specified bean class.
+ * <ol>
+ * <li>If <code>flag==IGNORE_ALL_BEANINFO</code>, the
+ * <code>Introspector</code> will ignore all <code>BeanInfo</code>
+ * class.</li>
+ * <li>If <code>flag==IGNORE_IMMEDIATE_BEANINFO</code>, the
+ * <code>Introspector</code> will ignore the <code>BeanInfo</code> class
+ * of the current bean class.</li>
+ * <li>If <code>flag==USE_ALL_BEANINFO</code>, the
+ * <code>Introspector</code> will use all <code>BeanInfo</code> class
+ * which have been found.</li>
+ * </ol>
+ * <p>
+ * The <code>Introspector</code> will cache the <code>BeanInfo</code>
+ * object. Subsequent calls to this method will be answered with the cached
+ * data.
+ * </p>
+ *
+ * @param beanClass
+ * the specified bean class.
+ * @param flags
+ * the flag to control the usage of the explicit
+ * <code>BeanInfo</code> class.
+ * @return the <code>BeanInfo</code> of the bean class.
+ * @throws IntrospectionException
+ */
+ public static BeanInfo getBeanInfo(Class<?> beanClass, int flags)
+ throws IntrospectionException {
+ if(flags == USE_ALL_BEANINFO){
+ //try to use cache
+ return getBeanInfo(beanClass);
+ }
+ return getBeanInfoImplAndInit(beanClass, null, flags);
+ }
+
+ /**
+ * Gets an array of search packages.
+ *
+ * @return an array of search packages.
+ */
+ public static String[] getBeanInfoSearchPath() {
+ String[] path = new String[searchPath.length];
+ System.arraycopy(searchPath, 0, path, 0, searchPath.length);
+ return path;
+ }
+
+ /**
+ * Sets the search packages.
+ *
+ * @param path the new search packages to be set.
+ */
+ public static void setBeanInfoSearchPath(String[] path) {
+ if (System.getSecurityManager() != null) {
+ System.getSecurityManager().checkPropertiesAccess();
+ }
+ searchPath = path;
+ }
+
+ private static StandardBeanInfo getBeanInfoImpl(Class beanClass, Class stopClass,
+ int flags) throws IntrospectionException {
+ BeanInfo explicitInfo = null;
+ if (flags == USE_ALL_BEANINFO) {
+ explicitInfo = getExplicitBeanInfo(beanClass);
+ }
+ StandardBeanInfo beanInfo = new StandardBeanInfo(beanClass, explicitInfo, stopClass);
+
+ if (beanInfo.additionalBeanInfo != null) {
+ for (int i = beanInfo.additionalBeanInfo.length-1; i >=0; i--) {
+ BeanInfo info = beanInfo.additionalBeanInfo[i];
+ beanInfo.mergeBeanInfo(info, true);
}
}
-
- // ...
-
- // generate bean info automatically
-
- beanInfoImpl = new BeanInfoImpl(beanClass);
-
- // ...
-
- wrapper = new BeanInfoWrapper(beanInfo, beanInfoImpl);
- parent = beanClass.getSuperclass();
-
- if (parent != null && parent != stopClass) {
- BeanInfoWrapper parentBeanInfo = getBeanInfo(parent, stopClass,
- ignoreSuperClassBeanInfo, ignoreSuperClassBeanInfo);
-
- wrapper.setParentToMerge(parentBeanInfo);
- }
-
- // ...
-
- storeBeanInfoClassInCache(wrapper, beanClass, stopClass,
- ignoreBeanClassBeanInfo, ignoreSuperClassBeanInfo);
- return wrapper;
- }
-
- private static Class<?> findBeanInfoClass(Class<?> beanClass) {
- String beanClassName = beanClass.getName();
- int idx = beanClassName.lastIndexOf("."); //$NON-NLS-1$
- String shortBeanInfoClassName = beanClassName.substring(idx + 1,
- beanClassName.length())
- + "BeanInfo"; //$NON-NLS-1$
- String fullBeanInfoClassName = beanClassName + "BeanInfo"; //$NON-NLS-1$
-
- Class<?> beanInfoClass = null;
- try {
- beanInfoClass = Class.forName(fullBeanInfoClassName, true,
- beanClass.getClassLoader());
-
- } catch (ClassNotFoundException cnfe) {
- for (String element : path) {
- try {
- fullBeanInfoClassName = element + "." //$NON-NLS-1$
- + shortBeanInfoClassName;
- beanInfoClass = Class.forName(fullBeanInfoClassName, true,
- beanClass.getClassLoader());
- break;
- } catch (ClassNotFoundException cnfe2) {
- }
+ // recursive get beaninfo for super classes
+ Class beanSuperClass = beanClass.getSuperclass();
+ if (beanSuperClass != stopClass) {
+ if (beanSuperClass == null)
+ throw new IntrospectionException(
+ "Stop class is not super class of bean class");
+ int superflags = flags == IGNORE_IMMEDIATE_BEANINFO ? USE_ALL_BEANINFO
+ : flags;
+ BeanInfo superBeanInfo = getBeanInfoImpl(beanSuperClass, stopClass,
+ superflags);
+ if (superBeanInfo != null) {
+ beanInfo.mergeBeanInfo(superBeanInfo, false);
}
}
-
- return beanInfoClass;
+ return beanInfo;
}
- private static BeanInfoWrapper findBeanInfoClassInCache(Class<?> beanClass,
- Class<?> stopClass, boolean ignoreBeanClassBeanInfo,
- boolean ignoreSuperClassBeanInfo) {
- BeanInfoWrapper result = null;
- List<BeanInfoData> beanInfoDatas = beanInfos.get(beanClass.getName());
- if (beanInfoDatas != null) {
- Iterator<BeanInfoData> iterator = beanInfoDatas.iterator();
- while (iterator.hasNext()) {
- BeanInfoData beanInfoData = iterator.next();
- if ((beanInfoData.getStopClass() == stopClass)
- && (beanInfoData.getIgnoreBeanClassBeanInfo() == ignoreBeanClassBeanInfo)
- && (beanInfoData.getIgnoreSuperClassBeanInfo() == ignoreSuperClassBeanInfo)) {
- result = beanInfoData.getBeanInfoWrapper();
- }
- if (result != null) {
- break;
- }
+ private static BeanInfo getExplicitBeanInfo(Class beanClass) {
+ BeanInfo theBeanInfo = null;
+ String beanInfoClassName = beanClass.getName() + "BeanInfo"; //$NON-NLS-1$
+ try{
+ theBeanInfo = loadBeanInfo(beanInfoClassName, beanClass);
+ return theBeanInfo;
+ }catch(Exception e){
+ //fall through
+ }
+ int index = beanInfoClassName.lastIndexOf('.');
+ String beanInfoName = index>=0? beanInfoClassName.substring(index+1):beanInfoClassName;
+ for (int i = 0; i < searchPath.length; i++) {
+ beanInfoClassName = searchPath[i] + "." + beanInfoName;
+ try{
+ theBeanInfo = loadBeanInfo(beanInfoClassName, beanClass);
+ break;
+ }catch(Exception e){
+ //ignore, try next one
}
}
- return result;
- }
-
- private static void storeBeanInfoClassInCache(
- BeanInfoWrapper beanInfoWrapper, Class<?> beanClass,
- Class<?> stopClass, boolean ignoreBeanClassBeanInfo,
- boolean ignoreSuperClassBeanInfo) {
- List<BeanInfoData> beanInfoDatas = beanInfos.get(beanClass.getName());
- if (beanInfoDatas == null) {
- beanInfoDatas = new ArrayList<BeanInfoData>();
- beanInfos.put(beanClass.getName(), beanInfoDatas);
- }
- beanInfoDatas.add(new BeanInfoData(stopClass, ignoreBeanClassBeanInfo,
- ignoreSuperClassBeanInfo, beanInfoWrapper));
+ return theBeanInfo;
}
- private static void removeBeanInfoClassFromCache(Class<?> beanClass) {
- beanInfos.remove(beanClass.getName());
- }
-
- private static void removeAllBeanInfoClassesFromCache() {
- beanInfos.clear();
- }
- // private fields
+ /*
+ * Method which attempts to instantiate a BeanInfo object of the supplied
+ * classname
+ *
+ * @param theBeanInfoClassName -
+ * the Class Name of the class of which the BeanInfo is an
+ * instance
+ * @param classLoader
+ * @return A BeanInfo object which is an instance of the Class named
+ * theBeanInfoClassName null if the Class does not exist or if there
+ * are problems instantiating the instance
+ */
+ private static BeanInfo loadBeanInfo(String beanInfoClassName,
+ Class beanClass) throws Exception{
+ try {
+ ClassLoader cl = beanClass.getClassLoader();
+ if(cl != null){
+ return (BeanInfo) Class.forName(beanInfoClassName, true,
+ beanClass.getClassLoader()).newInstance();
+ }
+ } catch (Exception e) {
+ // fall through
+ }
+ try {
+ return (BeanInfo) Class.forName(beanInfoClassName, true,
+ ClassLoader.getSystemClassLoader()).newInstance();
+ } catch (Exception e) {
+ // fall through
+ }
+ return (BeanInfo) Class.forName(beanInfoClassName, true,
+ Thread.currentThread().getContextClassLoader()).newInstance();
+ }
+
+ private static StandardBeanInfo getBeanInfoImplAndInit(Class beanClass,
+ Class stopClass, int flag) throws IntrospectionException {
+ StandardBeanInfo standardBeanInfo = getBeanInfoImpl(beanClass,
+ stopClass, flag);
+ standardBeanInfo.init();
+ return standardBeanInfo;
+ }
+}
- private static String[] path = { "org.apache.harmony.beans.infos" }; //$NON-NLS-1$
- private static final Map<String, List<BeanInfoData>> beanInfos =
- new HashMap<String, List<BeanInfoData>>();
-}
Modified: harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/MethodDescriptor.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/MethodDescriptor.java?view=diff&rev=557518&r1=557517&r2=557518
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/MethodDescriptor.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/MethodDescriptor.java Thu Jul 19 01:09:53 2007
@@ -96,4 +96,14 @@
public ParameterDescriptor[] getParameterDescriptors() {
return parameterDescriptors;
}
+
+ void merge(MethodDescriptor anotherMethod){
+ super.merge(anotherMethod);
+ if(method == null){
+ method = anotherMethod.method;
+ }
+ if(parameterDescriptors == null){
+ parameterDescriptors = anotherMethod.parameterDescriptors;
+ }
+ }
}
Modified: harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/PropertyDescriptor.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/PropertyDescriptor.java?view=diff&rev=557518&r1=557517&r2=557518
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/PropertyDescriptor.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/PropertyDescriptor.java Thu Jul 19 01:09:53 2007
@@ -31,12 +31,12 @@
private Class<?> propertyEditorClass;
- private boolean constrained;
+ boolean constrained;
- private boolean bound;
+ boolean bound;
- public PropertyDescriptor(String propertyName, Class<?> beanClass, String getterName,
- String setterName) throws IntrospectionException {
+ public PropertyDescriptor(String propertyName, Class<?> beanClass,
+ String getterName, String setterName) throws IntrospectionException {
super();
if (beanClass == null) {
throw new IntrospectionException(Messages.getString("beans.03")); //$NON-NLS-1$
@@ -45,20 +45,22 @@
throw new IntrospectionException(Messages.getString("beans.04")); //$NON-NLS-1$
}
this.setName(propertyName);
- this.setDisplayName(propertyName);
if (getterName != null) {
- if(getterName.length() == 0){
- throw new IntrospectionException("read or write method cannot be empty."); //$NON-NLS-1$
+ if (getterName.length() == 0) {
+ throw new IntrospectionException(
+ "read or write method cannot be empty."); //$NON-NLS-1$
}
- try{
+ try {
setReadMethod(beanClass, getterName);
- }catch(IntrospectionException e){
- setReadMethod(beanClass, createDefaultMethodName(propertyName, "get")); //$NON-NLS-1$
+ } catch (IntrospectionException e) {
+ setReadMethod(beanClass, createDefaultMethodName(propertyName,
+ "get")); //$NON-NLS-1$
}
}
if (setterName != null) {
- if(setterName.length() == 0){
- throw new IntrospectionException("read or write method cannot be empty."); //$NON-NLS-1$
+ if (setterName.length() == 0) {
+ throw new IntrospectionException(
+ "read or write method cannot be empty."); //$NON-NLS-1$
}
setWriteMethod(beanClass, setterName);
}
@@ -71,7 +73,6 @@
throw new IntrospectionException(Messages.getString("beans.04")); //$NON-NLS-1$
}
this.setName(propertyName);
- this.setDisplayName(propertyName);
setReadMethod(getter);
setWriteMethod(setter);
}
@@ -85,13 +86,14 @@
throw new IntrospectionException(Messages.getString("beans.04")); //$NON-NLS-1$
}
this.setName(propertyName);
- this.setDisplayName(propertyName);
try {
- setReadMethod(beanClass, createDefaultMethodName(propertyName, "is")); //$NON-NLS-1$
+ setReadMethod(beanClass,
+ createDefaultMethodName(propertyName, "is")); //$NON-NLS-1$
} catch (Exception e) {
- setReadMethod(beanClass, createDefaultMethodName(propertyName, "get")); //$NON-NLS-1$
+ setReadMethod(beanClass, createDefaultMethodName(propertyName,
+ "get")); //$NON-NLS-1$
}
-
+
setWriteMethod(beanClass, createDefaultMethodName(propertyName, "set")); //$NON-NLS-1$
}
@@ -149,22 +151,26 @@
boolean result = object instanceof PropertyDescriptor;
if (result) {
PropertyDescriptor pd = (PropertyDescriptor) object;
- boolean gettersAreEqual = (this.getter == null) && (pd.getReadMethod() == null)
- || (this.getter != null) && (this.getter.equals(pd.getReadMethod()));
- boolean settersAreEqual = (this.setter == null) && (pd.getWriteMethod() == null)
- || (this.setter != null) && (this.setter.equals(pd.getWriteMethod()));
- boolean propertyTypesAreEqual = this.getPropertyType() == pd.getPropertyType();
- boolean propertyEditorClassesAreEqual = this.getPropertyEditorClass() == pd
- .getPropertyEditorClass();
+ boolean gettersAreEqual = (this.getter == null)
+ && (pd.getReadMethod() == null) || (this.getter != null)
+ && (this.getter.equals(pd.getReadMethod()));
+ boolean settersAreEqual = (this.setter == null)
+ && (pd.getWriteMethod() == null) || (this.setter != null)
+ && (this.setter.equals(pd.getWriteMethod()));
+ boolean propertyTypesAreEqual = this.getPropertyType() == pd
+ .getPropertyType();
+ boolean propertyEditorClassesAreEqual = this
+ .getPropertyEditorClass() == pd.getPropertyEditorClass();
boolean boundPropertyAreEqual = this.isBound() == pd.isBound();
- boolean constrainedPropertyAreEqual = this.isConstrained() == pd.isConstrained();
- result = gettersAreEqual && settersAreEqual && propertyTypesAreEqual
- && propertyEditorClassesAreEqual && boundPropertyAreEqual
- && constrainedPropertyAreEqual;
+ boolean constrainedPropertyAreEqual = this.isConstrained() == pd
+ .isConstrained();
+ result = gettersAreEqual && settersAreEqual
+ && propertyTypesAreEqual && propertyEditorClassesAreEqual
+ && boundPropertyAreEqual && constrainedPropertyAreEqual;
}
return result;
}
-
+
@Override
public int hashCode() {
return BeansUtils.getHashCode(getter) + BeansUtils.getHashCode(setter)
@@ -219,24 +225,27 @@
return result;
}
- void setReadMethod(Class<?> beanClass, String getterName) throws IntrospectionException {
+ void setReadMethod(Class<?> beanClass, String getterName)
+ throws IntrospectionException {
try {
- Method readMethod = beanClass.getMethod(getterName, new Class[]{});
+ Method readMethod = beanClass.getMethod(getterName, new Class[] {});
setReadMethod(readMethod);
} catch (Exception e) {
throw new IntrospectionException(e.getLocalizedMessage());
}
}
- void setWriteMethod(Class<?> beanClass, String setterName) throws IntrospectionException {
+ void setWriteMethod(Class<?> beanClass, String setterName)
+ throws IntrospectionException {
Method writeMethod = null;
try {
- if(getter != null){
- writeMethod = beanClass.getMethod(setterName, new Class[]{getter.getReturnType()});
- }else{
+ if (getter != null) {
+ writeMethod = beanClass.getMethod(setterName,
+ new Class[] { getter.getReturnType() });
+ } else {
Method[] methods = beanClass.getMethods();
for (Method method : methods) {
- if(method.getName().equals(setterName)){
+ if (method.getName().equals(setterName)) {
writeMethod = method;
break;
}
@@ -271,7 +280,8 @@
}
} catch (Exception e) {
// beans.47=Unable to instantiate property editor
- RuntimeException re = new RuntimeException(Messages.getString("beans.47"), e); //$NON-NLS-1$
+ RuntimeException re = new RuntimeException(Messages
+ .getString("beans.47"), e); //$NON-NLS-1$
throw re;
}
return editor;