From ac1ed908de999523efc36f38e69bca1aadfe0808 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Mon, 14 Aug 2006 23:12:35 +0000 Subject: Imported GNU Classpath 0.92 2006-08-14 Mark Wielaard Imported GNU Classpath 0.92 * HACKING: Add more importing hints. Update automake version requirement. * configure.ac (gconf-peer): New enable AC argument. Add --disable-gconf-peer and --enable-default-preferences-peer to classpath configure when gconf is disabled. * scripts/makemake.tcl: Set gnu/java/util/prefs/gconf and gnu/java/awt/dnd/peer/gtk to bc. Classify gnu/java/security/Configuration.java as generated source file. * gnu/java/lang/management/VMGarbageCollectorMXBeanImpl.java, gnu/java/lang/management/VMMemoryPoolMXBeanImpl.java, gnu/java/lang/management/VMClassLoadingMXBeanImpl.java, gnu/java/lang/management/VMRuntimeMXBeanImpl.java, gnu/java/lang/management/VMMemoryManagerMXBeanImpl.java, gnu/java/lang/management/VMThreadMXBeanImpl.java, gnu/java/lang/management/VMMemoryMXBeanImpl.java, gnu/java/lang/management/VMCompilationMXBeanImpl.java: New VM stub classes. * java/lang/management/VMManagementFactory.java: Likewise. * java/net/VMURLConnection.java: Likewise. * gnu/java/nio/VMChannel.java: Likewise. * java/lang/Thread.java (getState): Add stub implementation. * java/lang/Class.java (isEnum): Likewise. * java/lang/Class.h (isEnum): Likewise. * gnu/awt/xlib/XToolkit.java (getClasspathTextLayoutPeer): Removed. * javax/naming/spi/NamingManager.java: New override for StackWalker functionality. * configure, sources.am, Makefile.in, gcj/Makefile.in, include/Makefile.in, testsuite/Makefile.in: Regenerated. From-SVN: r116139 --- .../java/beans/VetoableChangeSupport.java | 16 +- .../java/beans/beancontext/BeanContextSupport.java | 291 ++++++++++++++++++--- 2 files changed, 260 insertions(+), 47 deletions(-) (limited to 'libjava/classpath/java/beans') diff --git a/libjava/classpath/java/beans/VetoableChangeSupport.java b/libjava/classpath/java/beans/VetoableChangeSupport.java index dce8dff..12051d2 100644 --- a/libjava/classpath/java/beans/VetoableChangeSupport.java +++ b/libjava/classpath/java/beans/VetoableChangeSupport.java @@ -1,5 +1,6 @@ /* VetoableChangeSupport.java -- support to manage vetoable 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,15 @@ public class VetoableChangeSupport implements Serializable * vetoable change events will be sent to this listener. The listener add * is not unique: that is, n adds with the same listener will * result in n events being sent to that listener for every - * vetoable change. Adding a null listener may cause a NullPointerException - * down the road. This method will unwrap a VetoableChangeListenerProxy, + * vetoable change. This method will unwrap a VetoableChangeListenerProxy, * registering the underlying delegate to the named property list. * - * @param l the listener to add + * @param l the listener to add (null ignored). */ public synchronized void addVetoableChangeListener(VetoableChangeListener l) { + if (l == null) + return; if (l instanceof VetoableChangeListenerProxy) { VetoableChangeListenerProxy p = (VetoableChangeListenerProxy) l; @@ -215,19 +217,19 @@ public class VetoableChangeSupport implements Serializable * being sent to that listener when that property is changed. The effect is * cumulative, too; if you are registered to listen to receive events on * all vetoable 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 + * you will receive change events for that property twice. This method * will unwrap a VetoableChangeListenerProxy, registering the underlying * delegate to the named property list if the names match, and discarding * it otherwise. * * @param propertyName the name of the property to listen on * @param l the listener to add - * @throws NullPointerException if propertyName is null */ public synchronized void addVetoableChangeListener(String propertyName, VetoableChangeListener l) { + if (propertyName == null || l == null) + return; while (l instanceof VetoableChangeListenerProxy) { VetoableChangeListenerProxy p = (VetoableChangeListenerProxy) l; diff --git a/libjava/classpath/java/beans/beancontext/BeanContextSupport.java b/libjava/classpath/java/beans/beancontext/BeanContextSupport.java index f3d5ff6..a12c078 100644 --- a/libjava/classpath/java/beans/beancontext/BeanContextSupport.java +++ b/libjava/classpath/java/beans/beancontext/BeanContextSupport.java @@ -1,5 +1,5 @@ /* BeanContextSupport.java -- - Copyright (C) 2003, 2005 Free Software Foundation, Inc. + Copyright (C) 2003, 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -40,6 +40,7 @@ package java.beans.beancontext; import gnu.classpath.NotImplementedException; +import java.beans.Beans; import java.beans.DesignMode; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; @@ -59,7 +60,12 @@ import java.util.Iterator; import java.util.Locale; /** + * This is a helper class for implementing a bean context. It is + * intended to be used either by subclassing or by calling methods + * of this implementation from another. + * * @author Michael Koch + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) * @since 1.2 */ public class BeanContextSupport extends BeanContextChildSupport @@ -180,27 +186,102 @@ public class BeanContextSupport extends BeanContextChildSupport initialize (); } - public boolean add (Object targetChild) + /** + *

+ * Add a child to the bean context. A child can be a simple + * Object, a BeanContextChild + * or another BeanContext. + *

+ *

+ * The children of a BeanContext form a set. As + * a result, this method returns false if the given + * object is already a child of this context. + *

+ *

+ * If the child is a BeanContextChild, or a proxy + * for such a child, the setBeanContext() method + * is invoked on the child. If this operation is vetoed by the + * child, via throwing a PropertyVetoException, + * then the current completion state of the add() + * operation is rolled back and a IllegalStateException + * is thrown. If the BeanContextChild is successfully + * added, then the context registers with its + * PropertyChangeListener and + * VetoableChangeListener for "beanContext" events. + *

+ *

+ * If the child implements java.beans.Visibility, + * then its ability to use a GUI is set based on that of + * this context. + *

+ *

+ * A BeanContextMembershipEvent is fired when the + * child is successfully added to the bean context. + *

+ *

+ * This method is synchronized over the global hierarchy lock. + *

+ * + * @param targetChild the child to add. + * @return false if the child has already been added. + * @throws IllegalArgumentException if the child is null. + * @throws IllegalStateException if the child vetos the setting + * of its context. + */ + public boolean add(Object targetChild) { - if (targetChild == null) - throw new IllegalArgumentException(); - - BCSChild child; - synchronized (children) - { - if (children.containsKey(targetChild) - || ! validatePendingAdd(targetChild)) - return false; - child = createBCSChild(targetChild, beanContextChildPeer); - children.put(targetChild, child); - } - synchronized (targetChild) + synchronized (globalHierarchyLock) { - childJustAddedHook(targetChild, child); + if (targetChild == null) + throw new IllegalArgumentException(); + + BCSChild child; + synchronized (children) + { + if (children.containsKey(targetChild) + || ! validatePendingAdd(targetChild)) + return false; + child = createBCSChild(targetChild, beanContextChildPeer); + children.put(targetChild, child); + } + synchronized (targetChild) + { + BeanContextChild bcChild = null; + if (targetChild instanceof BeanContextChild) + bcChild = (BeanContextChild) targetChild; + if (targetChild instanceof BeanContextProxy) + bcChild = ((BeanContextProxy) targetChild).getBeanContextProxy(); + if (bcChild != null) + try + { + bcChild.setBeanContext(this); + bcChild.addVetoableChangeListener("beanContext", this); + bcChild.addPropertyChangeListener("beanContext", this); + } + catch (PropertyVetoException e) + { + synchronized (children) + { + children.remove(targetChild); + } + throw new IllegalStateException("The child refused to " + + "associate itself with " + + "this context.", e); + } + if (targetChild instanceof Visibility) + { + Visibility visibleChild = (Visibility) targetChild; + if (okToUseGui) + visibleChild.okToUseGui(); + else + visibleChild.dontUseGui(); + } + childJustAddedHook(targetChild, child); + } + fireChildrenAdded(new BeanContextMembershipEvent(this, + new Object[]{ targetChild })); + return true; } - fireChildrenAdded(new BeanContextMembershipEvent(this, - new Object[] { targetChild })); - return true; } public boolean addAll (Collection c) @@ -219,10 +300,18 @@ public class BeanContextSupport extends BeanContextChildSupport } } - public boolean avoidingGui () + /** + * Returns true if this bean needs a GUI + * but is being prevented from using one. + * + * @return true if needsGui() + * is true but the bean has been + * told not to use it. + */ + public boolean avoidingGui() throws NotImplementedException { - throw new Error ("Not implemented"); + return needsGui() && (!okToUseGui); } protected Iterator bcsChildren () @@ -321,10 +410,13 @@ public class BeanContextSupport extends BeanContextChildSupport throw new Error ("Not implemented"); } - public void dontUseGui () - throws NotImplementedException + /** + * Informs this bean that is should not make + * use of the GUI. + */ + public void dontUseGui() { - throw new Error ("Not implemented"); + okToUseGui = false; } protected final void fireChildrenAdded (BeanContextMembershipEvent bcme) @@ -426,10 +518,20 @@ public class BeanContextSupport extends BeanContextChildSupport children = new HashMap(); } + /** + * This is a convenience method for instantiating a bean inside this + * context. It delegates to the appropriate method in + * java.beans.Beans using the context's classloader. + * + * @param beanName the name of the class of bean to instantiate. + * @throws IOException if an I/O error occurs in loading the class. + * @throws ClassNotFoundException if the class, beanName, + * can not be found. + */ public Object instantiateChild (String beanName) - throws IOException, ClassNotFoundException, NotImplementedException + throws IOException, ClassNotFoundException { - throw new Error ("Not implemented"); + return Beans.instantiate(getClass().getClassLoader(), beanName, this); } public boolean isDesignTime () @@ -437,6 +539,11 @@ public class BeanContextSupport extends BeanContextChildSupport return designTime; } + /** + * Returns true if this bean context has no children. + * + * @return true if there are no children. + */ public boolean isEmpty () { synchronized (children) @@ -459,22 +566,38 @@ public class BeanContextSupport extends BeanContextChildSupport } } - public boolean needsGui () - throws NotImplementedException + /** + * Returns false as this bean does not a + * GUI for its operation. + * + * @return false + */ + public boolean needsGui() { - throw new Error ("Not implemented"); + return false; } + /** + * Informs this bean that it is okay to make use of + * the GUI. + */ public void okToUseGui () - throws NotImplementedException { - throw new Error ("Not implemented"); + okToUseGui = true; } + /** + * Subclasses may use this method to catch property changes + * arising from the children of this context. At present, + * we just listen for the beans being assigned to a different + * context and remove them from here if such an event occurs. + * + * @param pce the property change event. + */ public void propertyChange (PropertyChangeEvent pce) - throws NotImplementedException { - throw new Error ("Not implemented"); + if (pce.getNewValue() != this) + remove(pce.getSource(), false); } public final void readChildren (ObjectInputStream ois) @@ -483,18 +606,100 @@ public class BeanContextSupport extends BeanContextChildSupport throw new Error ("Not implemented"); } + /** + * Remove the specified child from the context. This is + * the same as calling remove(Object,boolean) + * with a request for the setBeanContext() method + * of the child to be called (i.e. the second argument is true). + * + * @param targetChild the child to remove. + */ public boolean remove (Object targetChild) { return remove(targetChild, true); } + /** + *

+ * Removes a child from the bean context. A child can be a simple + * Object, a BeanContextChild + * or another BeanContext. If the given child is not + * a child of this context, this method returns false. + *

+ *

+ * If the child is a BeanContextChild, or a proxy + * for such a child, the setBeanContext() method + * is invoked on the child (if specified). If this operation is vetoed + * by the child, via throwing a PropertyVetoException, + * then the current completion state of the remove() + * operation is rolled back and a IllegalStateException + * is thrown. If the BeanContextChild is successfully + * removed, then the context deregisters with its + * PropertyChangeListener and + * VetoableChangeListener for "beanContext" events. + *

+ *

+ * A BeanContextMembershipEvent is fired when the + * child is successfully removed from the bean context. + *

+ *

+ * This method is synchronized over the global hierarchy lock. + *

+ * + * @param targetChild the child to add. + * @param callChildSetBC true if the setBeanContext() + * method of the child should be called. + * @return false if the child doesn't exist. + * @throws IllegalArgumentException if the child is null. + * @throws IllegalStateException if the child vetos the setting + * of its context. + */ protected boolean remove (Object targetChild, boolean callChildSetBC) - throws NotImplementedException { - if (targetChild == null) - throw new IllegalArgumentException(); - - throw new Error ("Not implemented"); + synchronized (globalHierarchyLock) + { + if (targetChild == null) + throw new IllegalArgumentException(); + + BCSChild child; + synchronized (children) + { + if (!children.containsKey(targetChild) + || !validatePendingRemove(targetChild)) + return false; + child = (BCSChild) children.remove(targetChild); + } + synchronized (targetChild) + { + BeanContextChild bcChild = null; + if (targetChild instanceof BeanContextChild) + bcChild = (BeanContextChild) targetChild; + if (targetChild instanceof BeanContextProxy) + bcChild = ((BeanContextProxy) targetChild).getBeanContextProxy(); + if (bcChild != null) + try + { + if (callChildSetBC) + bcChild.setBeanContext(null); + bcChild.removeVetoableChangeListener("beanContext", this); + bcChild.removePropertyChangeListener("beanContext", this); + } + catch (PropertyVetoException e) + { + synchronized (children) + { + children.put(targetChild, child); + } + throw new IllegalStateException("The child refused to " + + "disassociate itself with " + + "this context.", e); + } + childJustRemovedHook(targetChild, child); + } + fireChildrenRemoved(new BeanContextMembershipEvent(this, + new Object[]{ targetChild })); + return true; + } } public boolean removeAll (Collection c) @@ -578,10 +783,16 @@ public class BeanContextSupport extends BeanContextChildSupport return true; } + /** + * Subclasses may use this method to veto changes arising + * from the children of this context. + * + * @param pce the vetoable property change event fired. + */ public void vetoableChange (PropertyChangeEvent pce) - throws PropertyVetoException, NotImplementedException + throws PropertyVetoException { - throw new Error ("Not implemented"); + /* Purposefully left empty */ } public final void writeChildren (ObjectOutputStream oos) -- cgit v1.1