aboutsummaryrefslogtreecommitdiff
path: root/libjava/classpath/java/beans
diff options
context:
space:
mode:
authorMark Wielaard <mark@gcc.gnu.org>2006-03-10 21:46:48 +0000
committerMark Wielaard <mark@gcc.gnu.org>2006-03-10 21:46:48 +0000
commit8aa540d2f783474d1d2e06f16744bf67b9c1facc (patch)
treeea38c56431c5d4528fb54254c3f8e50f517bede3 /libjava/classpath/java/beans
parent27079765d00123f8e53d0e1ef7f9d46559266e6d (diff)
downloadgcc-8aa540d2f783474d1d2e06f16744bf67b9c1facc.zip
gcc-8aa540d2f783474d1d2e06f16744bf67b9c1facc.tar.gz
gcc-8aa540d2f783474d1d2e06f16744bf67b9c1facc.tar.bz2
Imported GNU Classpath 0.90
Imported GNU Classpath 0.90 * scripts/makemake.tcl: Set gnu/java/awt/peer/swing to ignore. * gnu/classpath/jdwp/VMFrame.java (SIZE): New constant. * java/lang/VMCompiler.java: Use gnu.java.security.hash.MD5. * java/lang/Math.java: New override file. * java/lang/Character.java: Merged from Classpath. (start, end): Now 'int's. (canonicalName): New field. (CANONICAL_NAME, NO_SPACES_NAME, CONSTANT_NAME): New constants. (UnicodeBlock): Added argument. (of): New overload. (forName): New method. Updated unicode blocks. (sets): Updated. * sources.am: Regenerated. * Makefile.in: Likewise. From-SVN: r111942
Diffstat (limited to 'libjava/classpath/java/beans')
-rw-r--r--libjava/classpath/java/beans/DefaultPersistenceDelegate.java17
-rw-r--r--libjava/classpath/java/beans/Encoder.java45
-rw-r--r--libjava/classpath/java/beans/PersistenceDelegate.java5
-rw-r--r--libjava/classpath/java/beans/PropertyChangeSupport.java25
-rw-r--r--libjava/classpath/java/beans/PropertyDescriptor.java67
-rw-r--r--libjava/classpath/java/beans/XMLDecoder.java6
-rw-r--r--libjava/classpath/java/beans/XMLEncoder.java2
7 files changed, 113 insertions, 54 deletions
diff --git a/libjava/classpath/java/beans/DefaultPersistenceDelegate.java b/libjava/classpath/java/beans/DefaultPersistenceDelegate.java
index 9dd1ae5..ca1041f 100644
--- a/libjava/classpath/java/beans/DefaultPersistenceDelegate.java
+++ b/libjava/classpath/java/beans/DefaultPersistenceDelegate.java
@@ -157,6 +157,23 @@ public class DefaultPersistenceDelegate extends PersistenceDelegate
protected void initialize(Class type, Object oldInstance, Object newInstance,
Encoder out)
{
+ // Calling the supertype's implementation of initialize makes it
+ // possible that descendants of classes like AbstractHashMap
+ // or Hashtable are serialized correctly. This mechanism grounds on
+ // two other facts:
+ // * Each class which has not registered a special purpose
+ // PersistenceDelegate is handled by a DefaultPersistenceDelegate
+ // instance.
+ // * PersistenceDelegate.initialize() is implemented in a way that it
+ // calls the initialize method of the superclass' persistence delegate.
+ super.initialize(type, oldInstance, newInstance, out);
+
+ // Suppresses the writing of property setting statements when this delegate
+ // is not used for the exact instance type. By doing so the following code
+ // is called only once per object.
+ if (type != oldInstance.getClass())
+ return;
+
try
{
PropertyDescriptor[] propertyDescs = Introspector.getBeanInfo(
diff --git a/libjava/classpath/java/beans/Encoder.java b/libjava/classpath/java/beans/Encoder.java
index 9b96aaa..b9d1358 100644
--- a/libjava/classpath/java/beans/Encoder.java
+++ b/libjava/classpath/java/beans/Encoder.java
@@ -1,5 +1,5 @@
/* Encoder.java
- Copyright (C) 2005 Free Software Foundation, Inc.
+ Copyright (C) 2005, 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -38,21 +38,16 @@
package java.beans;
+import gnu.java.beans.DefaultExceptionListener;
import gnu.java.beans.encoder.ArrayPersistenceDelegate;
import gnu.java.beans.encoder.ClassPersistenceDelegate;
import gnu.java.beans.encoder.CollectionPersistenceDelegate;
import gnu.java.beans.encoder.MapPersistenceDelegate;
import gnu.java.beans.encoder.PrimitivePersistenceDelegate;
-import java.util.ArrayList;
+import java.util.AbstractCollection;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.IdentityHashMap;
-import java.util.LinkedHashSet;
-import java.util.LinkedList;
-import java.util.TreeMap;
-import java.util.TreeSet;
-import java.util.Vector;
/**
* @author Robert Schuster (robertschuster@fsfe.org)
@@ -123,31 +118,11 @@ public class Encoder
delegates.put(Object[].class, new ArrayPersistenceDelegate());
pd = new CollectionPersistenceDelegate();
- delegates.put(ArrayList.class, pd);
- delegates.put(LinkedList.class, pd);
- delegates.put(Vector.class, pd);
- delegates.put(HashSet.class, pd);
- delegates.put(LinkedHashSet.class, pd);
- delegates.put(TreeSet.class, pd);
+ delegates.put(AbstractCollection.class, pd);
pd = new MapPersistenceDelegate();
- delegates.put(HashMap.class, pd);
- delegates.put(TreeMap.class, pd);
+ delegates.put(java.util.AbstractMap.class, pd);
delegates.put(java.util.Hashtable.class, pd);
- delegates.put(java.util.IdentityHashMap.class, pd);
-
- delegates.put(java.util.LinkedHashMap.class, pd);
- delegates.put(java.util.Properties.class, pd);
-
- delegates.put(java.awt.RenderingHints.class, pd);
- delegates.put(java.util.WeakHashMap.class, pd);
- delegates.put(javax.swing.UIDefaults.class, pd);
-
- // TODO: These classes need to be implemented first
- //delegates.put(java.security.AuthProvider.class, pd);
- //delegates.put(java.util.concurrent.ConcurrentHashMap.class, pd);
- //delegates.put(java.util.EnumMap.class, pd);
- //delegates.put(javax.management.openmbean.TabularDataSupport.class, pd);
defaultPersistenceDelegate = new DefaultPersistenceDelegate();
delegates.put(Object.class, defaultPersistenceDelegate);
@@ -194,14 +169,8 @@ public class Encoder
*/
public void setExceptionListener(ExceptionListener listener)
{
- exceptionListener = (listener != null) ? listener : new ExceptionListener()
- {
- public void exceptionThrown(Exception e)
- {
- System.err.println("exception thrown: " + e);
- e.printStackTrace();
- }
- };
+ exceptionListener = (listener != null)
+ ? listener : DefaultExceptionListener.INSTANCE;
}
/**
diff --git a/libjava/classpath/java/beans/PersistenceDelegate.java b/libjava/classpath/java/beans/PersistenceDelegate.java
index b33cbcb..77953b6 100644
--- a/libjava/classpath/java/beans/PersistenceDelegate.java
+++ b/libjava/classpath/java/beans/PersistenceDelegate.java
@@ -59,9 +59,8 @@ public abstract class PersistenceDelegate
{
type = type.getSuperclass();
- PersistenceDelegate pd = out.getPersistenceDelegate(
- oldInstance.getClass().getSuperclass());
-
+ PersistenceDelegate pd = out.getPersistenceDelegate(type);
+
pd.initialize(type, oldInstance, newInstance, out);
}
}
diff --git a/libjava/classpath/java/beans/PropertyChangeSupport.java b/libjava/classpath/java/beans/PropertyChangeSupport.java
index 991390b..e944e15 100644
--- a/libjava/classpath/java/beans/PropertyChangeSupport.java
+++ b/libjava/classpath/java/beans/PropertyChangeSupport.java
@@ -1,5 +1,6 @@
/* PropertyChangeSupport.java -- support to manage property change listeners
- Copyright (C) 1998, 1999, 2000, 2002, 2005 Free Software Foundation, Inc.
+ Copyright (C) 1998, 1999, 2000, 2002, 2005, 2006
+ Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -120,14 +121,17 @@ public class PropertyChangeSupport implements Serializable
* property change events will be sent to this listener. The listener add
* is not unique: that is, <em>n</em> adds with the same listener will
* result in <em>n</em> events being sent to that listener for every
- * property change. Adding a null listener may cause a NullPointerException
- * down the road. This method will unwrap a PropertyChangeListenerProxy,
+ * property change. Adding a null listener is silently ignored.
+ * This method will unwrap a PropertyChangeListenerProxy,
* registering the underlying delegate to the named property list.
*
* @param l the listener to add
*/
public synchronized void addPropertyChangeListener(PropertyChangeListener l)
{
+ if (l == null)
+ return;
+
if (l instanceof PropertyChangeListenerProxy)
{
PropertyChangeListenerProxy p = (PropertyChangeListenerProxy) l;
@@ -216,8 +220,8 @@ public class PropertyChangeSupport implements Serializable
* cumulative, too; if you are registered to listen to receive events on
* all property changes, and then you register on a particular property,
* you will receive change events for that property twice. Adding a null
- * listener may cause a NullPointerException down the road. This method
- * will unwrap a PropertyChangeListenerProxy, registering the underlying
+ * listener is silently ignored. This method will unwrap a
+ * PropertyChangeListenerProxy, registering the underlying
* delegate to the named property list if the names match, and discarding
* it otherwise.
*
@@ -228,6 +232,9 @@ public class PropertyChangeSupport implements Serializable
public synchronized void addPropertyChangeListener(String propertyName,
PropertyChangeListener l)
{
+ if (l == null)
+ return;
+
while (l instanceof PropertyChangeListenerProxy)
{
PropertyChangeListenerProxy p = (PropertyChangeListenerProxy) l;
@@ -290,17 +297,16 @@ public class PropertyChangeSupport implements Serializable
/**
* Returns an array of all property change listeners registered under the
- * given property name. If there are no registered listeners, this returns
- * an empty array.
+ * given property name. If there are no registered listeners, or
+ * propertyName is null, this returns an empty array.
*
* @return the array of registered listeners
- * @throws NullPointerException if propertyName is null
* @since 1.4
*/
public synchronized PropertyChangeListener[]
getPropertyChangeListeners(String propertyName)
{
- if (children == null)
+ if (children == null || propertyName == null)
return new PropertyChangeListener[0];
PropertyChangeSupport s
= (PropertyChangeSupport) children.get(propertyName);
@@ -455,7 +461,6 @@ public class PropertyChangeSupport implements Serializable
*
* @param propertyName the property that may be listened on
* @return whether the property is being listened on
- * @throws NullPointerException if propertyName is null
*/
public synchronized boolean hasListeners(String propertyName)
{
diff --git a/libjava/classpath/java/beans/PropertyDescriptor.java b/libjava/classpath/java/beans/PropertyDescriptor.java
index a22d625..da2ca78 100644
--- a/libjava/classpath/java/beans/PropertyDescriptor.java
+++ b/libjava/classpath/java/beans/PropertyDescriptor.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package java.beans;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
/**
@@ -344,6 +346,71 @@ public class PropertyDescriptor extends FeatureDescriptor
this.propertyEditorClass = propertyEditorClass;
}
+ /**
+ * Instantiate a property editor using the property editor class.
+ * If no property editor class has been set, this will return null.
+ * If the editor class has a public constructor which takes a single
+ * argument, that will be used and the bean parameter will be passed
+ * to it. Otherwise, a public no-argument constructor will be used,
+ * if available. This method will return null if no constructor is
+ * found or if construction fails for any reason.
+ * @param bean the argument to the constructor
+ * @return a new PropertyEditor, or null on error
+ * @since 1.5
+ */
+ public PropertyEditor createPropertyEditor(Object bean)
+ {
+ if (propertyEditorClass == null)
+ return null;
+ Constructor c = findConstructor(propertyEditorClass,
+ new Class[] { Object.class });
+ if (c != null)
+ return instantiateClass(c, new Object[] { bean });
+ c = findConstructor(propertyEditorClass, null);
+ if (c != null)
+ return instantiateClass(c, null);
+ return null;
+ }
+
+ // Helper method to look up a constructor and return null if it is not
+ // found.
+ private Constructor findConstructor(Class k, Class[] argTypes)
+ {
+ try
+ {
+ return k.getConstructor(argTypes);
+ }
+ catch (NoSuchMethodException _)
+ {
+ return null;
+ }
+ }
+
+ // Helper method to instantiate an object but return null on error.
+ private PropertyEditor instantiateClass(Constructor c, Object[] args)
+ {
+ try
+ {
+ return (PropertyEditor) c.newInstance(args);
+ }
+ catch (InstantiationException _)
+ {
+ return null;
+ }
+ catch (InvocationTargetException _)
+ {
+ return null;
+ }
+ catch (IllegalAccessException _)
+ {
+ return null;
+ }
+ catch (ClassCastException _)
+ {
+ return null;
+ }
+ }
+
private void findMethods(
Class beanClass,
String getMethodName1,
diff --git a/libjava/classpath/java/beans/XMLDecoder.java b/libjava/classpath/java/beans/XMLDecoder.java
index 238fd6b..7618bb8 100644
--- a/libjava/classpath/java/beans/XMLDecoder.java
+++ b/libjava/classpath/java/beans/XMLDecoder.java
@@ -1,5 +1,5 @@
/* java.beans.XMLDecoder --
- Copyright (C) 2004, 2005 Free Software Foundation, Inc.
+ Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -38,7 +38,7 @@ exception statement from your version. */
package java.beans;
-import gnu.java.beans.decoder.DefaultExceptionListener;
+import gnu.java.beans.DefaultExceptionListener;
import gnu.java.beans.decoder.PersistenceParser;
import java.io.IOException;
@@ -289,7 +289,7 @@ public class XMLDecoder
// uses a default implementation when null
if (listener == null)
{
- listener = new DefaultExceptionListener();
+ listener = DefaultExceptionListener.INSTANCE;
}
exceptionListener = listener;
}
diff --git a/libjava/classpath/java/beans/XMLEncoder.java b/libjava/classpath/java/beans/XMLEncoder.java
index f9cbe63..feff68b 100644
--- a/libjava/classpath/java/beans/XMLEncoder.java
+++ b/libjava/classpath/java/beans/XMLEncoder.java
@@ -168,6 +168,8 @@ public class XMLEncoder extends Encoder
// an erroneous state to the ScanEngine without behaving different
// to the JDK.
scanEngine.revoke();
+
+ return;
}
writeObject(value);