diff options
Diffstat (limited to 'libjava/classpath/java/beans')
6 files changed, 322 insertions, 86 deletions
diff --git a/libjava/classpath/java/beans/beancontext/BeanContext.java b/libjava/classpath/java/beans/beancontext/BeanContext.java index 3d1be7f..02f4a1a 100644 --- a/libjava/classpath/java/beans/beancontext/BeanContext.java +++ b/libjava/classpath/java/beans/beancontext/BeanContext.java @@ -198,7 +198,7 @@ public interface BeanContext * @return the created Bean * * @see java.beans.Beans#instantiate(java.lang.ClassLoader,java.lang.String) - * @see java.beans.Beans#instantiate(java.lang.ClassLoader,java.lang.String,java.lang.BeanContext) + * @see java.beans.Beans#instantiate(java.lang.ClassLoader,java.lang.String,java.beans.beancontext.BeanContext) * @exception IOException if there is an I/O problem during * instantiation. * @exception ClassNotFoundException if a serialized Bean's class diff --git a/libjava/classpath/java/beans/beancontext/BeanContextMembershipEvent.java b/libjava/classpath/java/beans/beancontext/BeanContextMembershipEvent.java index 3176542..9560889 100644 --- a/libjava/classpath/java/beans/beancontext/BeanContextMembershipEvent.java +++ b/libjava/classpath/java/beans/beancontext/BeanContextMembershipEvent.java @@ -52,7 +52,9 @@ import java.util.Iterator; * @see java.beans.beancontext.BeanContextMembershipListener */ public class BeanContextMembershipEvent extends BeanContextEvent { - /** + private static final long serialVersionUID = 3499346510334590959L; + + /** * The children that were added or removed. */ protected Collection children; diff --git a/libjava/classpath/java/beans/beancontext/BeanContextServiceAvailableEvent.java b/libjava/classpath/java/beans/beancontext/BeanContextServiceAvailableEvent.java index eea10f2..6dc2c38 100644 --- a/libjava/classpath/java/beans/beancontext/BeanContextServiceAvailableEvent.java +++ b/libjava/classpath/java/beans/beancontext/BeanContextServiceAvailableEvent.java @@ -49,7 +49,9 @@ import java.util.Iterator; */ public class BeanContextServiceAvailableEvent extends BeanContextEvent { - /** + private static final long serialVersionUID = -5333985775656400778L; + + /** * The <code>Class</code> representing the service which is now * available. */ diff --git a/libjava/classpath/java/beans/beancontext/BeanContextServiceRevokedEvent.java b/libjava/classpath/java/beans/beancontext/BeanContextServiceRevokedEvent.java index dfa2b89b..1f5ebd3 100644 --- a/libjava/classpath/java/beans/beancontext/BeanContextServiceRevokedEvent.java +++ b/libjava/classpath/java/beans/beancontext/BeanContextServiceRevokedEvent.java @@ -47,7 +47,9 @@ package java.beans.beancontext; */ public class BeanContextServiceRevokedEvent extends BeanContextEvent { - /** + private static final long serialVersionUID = -1295543154724961754L; + + /** * The <code>Class</code> representing the service which is now * available. */ diff --git a/libjava/classpath/java/beans/beancontext/BeanContextServicesSupport.java b/libjava/classpath/java/beans/beancontext/BeanContextServicesSupport.java index 5455adb..4da523e 100644 --- a/libjava/classpath/java/beans/beancontext/BeanContextServicesSupport.java +++ b/libjava/classpath/java/beans/beancontext/BeanContextServicesSupport.java @@ -38,6 +38,8 @@ exception statement from your version. */ package java.beans.beancontext; +import gnu.classpath.NotImplementedException; + import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; @@ -62,6 +64,11 @@ public class BeanContextServicesSupport extends BeanContextSupport.BCSChild { private static final long serialVersionUID = -3263851306889194873L; + + BCSSChild(Object targetChild, Object peer) + { + super(targetChild, peer); + } } protected class BCSSProxyServiceProvider @@ -69,9 +76,14 @@ public class BeanContextServicesSupport BeanContextServiceRevokedListener { private static final long serialVersionUID = 7078212910685744490L; - + + private BCSSProxyServiceProvider() + { + } + public Iterator getCurrentServiceSelectors (BeanContextServices bcs, Class serviceClass) + throws NotImplementedException { throw new Error ("Not implemented"); } @@ -80,6 +92,7 @@ public class BeanContextServicesSupport Object requestor, Class serviceClass, Object serviceSelector) + throws NotImplementedException { throw new Error ("Not implemented"); } @@ -87,11 +100,13 @@ public class BeanContextServicesSupport public void releaseService (BeanContextServices bcs, Object requestor, Object service) + throws NotImplementedException { throw new Error ("Not implemented"); } public void serviceRevoked (BeanContextServiceRevokedEvent bcsre) + throws NotImplementedException { throw new Error ("Not implemented"); } @@ -104,6 +119,10 @@ public class BeanContextServicesSupport protected BeanContextServiceProvider serviceProvider; + private BCSSServiceProvider() + { + } + protected BeanContextServiceProvider getServiceProvider() { return serviceProvider; @@ -148,105 +167,154 @@ public class BeanContextServicesSupport public void addBeanContextServicesListener (BeanContextServicesListener listener) { - if (! bcsListeners.contains(listener)) - bcsListeners.add(listener); + synchronized (bcsListeners) + { + if (! bcsListeners.contains(listener)) + bcsListeners.add(listener); + } } - public boolean addService (Class serviceClass, BeanContextServiceProvider bcsp) + public boolean addService (Class serviceClass, + BeanContextServiceProvider bcsp) { - throw new Error ("Not implemented"); + return addService(serviceClass, bcsp, true); } protected boolean addService (Class serviceClass, BeanContextServiceProvider bcsp, boolean fireEvent) { - throw new Error ("Not implemented"); + synchronized (services) + { + if (services.containsKey(serviceClass)) + return false; + services.put(serviceClass, bcsp); + if (bcsp instanceof Serializable) + ++serializable; + fireServiceAdded(serviceClass); + return true; + } } protected void bcsPreDeserializationHook (ObjectInputStream ois) - throws ClassNotFoundException, IOException + throws ClassNotFoundException, IOException, NotImplementedException { throw new Error ("Not implemented"); } protected void bcsPreSerializationHook (ObjectOutputStream oos) - throws IOException + throws IOException, NotImplementedException { throw new Error ("Not implemented"); } protected void childJustRemovedHook (Object child, BeanContextSupport.BCSChild bcsc) + throws NotImplementedException { throw new Error ("Not implemented"); } protected BeanContextSupport.BCSChild createBCSChild (Object targetChild, - Object peer) + Object peer) { - throw new Error ("Not implemented"); + return new BCSSChild(targetChild, peer); } protected BeanContextServicesSupport.BCSSServiceProvider createBCSSServiceProvider (Class sc, BeanContextServiceProvider bcsp) + throws NotImplementedException { throw new Error ("Not implemented"); } protected final void fireServiceAdded (BeanContextServiceAvailableEvent bcssae) { - throw new Error ("Not implemented"); + synchronized (bcsListeners) + { + int size = bcsListeners.size(); + for (int i = 0; i < size; ++i) + { + BeanContextServicesListener bcsl + = (BeanContextServicesListener) bcsListeners.get(i); + bcsl.serviceAvailable(bcssae); + } + } } - protected final void fireServiceAdded (Class serviceClass) + protected final void fireServiceAdded (Class serviceClass) { - throw new Error ("Not implemented"); + fireServiceAdded(new BeanContextServiceAvailableEvent(this, + serviceClass)); } protected final void fireServiceRevoked(BeanContextServiceRevokedEvent event) { - throw new Error ("Not implemented"); + synchronized (bcsListeners) + { + int size = bcsListeners.size(); + for (int i = 0; i < size; ++i) + { + BeanContextServicesListener bcsl + = (BeanContextServicesListener) bcsListeners.get(i); + bcsl.serviceRevoked(event); + } + } } protected final void fireServiceRevoked (Class serviceClass, boolean revokeNow) { - throw new Error ("Not implemented"); + fireServiceRevoked(new BeanContextServiceRevokedEvent(this, serviceClass, + revokeNow)); } public BeanContextServices getBeanContextServicesPeer () + throws NotImplementedException { throw new Error ("Not implemented"); } protected static final BeanContextServicesListener - getChildBeanContextServicesListener (Object child) + getChildBeanContextServicesListener (Object child) + throws NotImplementedException { throw new Error ("Not implemented"); } - public Iterator getCurrentServiceClasses () + public Iterator getCurrentServiceClasses () { - throw new Error ("Not implemented"); + synchronized (services) + { + return services.keySet().iterator(); + } } - public Iterator getCurrentServiceSelectors (Class serviceClass) + public Iterator getCurrentServiceSelectors (Class serviceClass) { - throw new Error ("Not implemented"); + synchronized (services) + { + // FIXME: what if service does not exist? Must write a test. + BeanContextServiceProvider bcsp + = (BeanContextServiceProvider) services.get(serviceClass); + return bcsp.getCurrentServiceSelectors(this, serviceClass); + } } public Object getService (BeanContextChild child, Object requestor, Class serviceClass, Object serviceSelector, BeanContextServiceRevokedListener bcsrl) - throws TooManyListenersException + throws TooManyListenersException, NotImplementedException { throw new Error ("Not implemented"); } public boolean hasService (Class serviceClass) { - throw new Error ("Not implemented"); + synchronized (services) + { + return services.containsKey(serviceClass); + } } public void initialize () @@ -257,18 +325,21 @@ public class BeanContextServicesSupport services = new HashMap(); } - protected void initializeBeanContextResources () + protected void initializeBeanContextResources () + throws NotImplementedException { throw new Error ("Not implemented"); } - protected void releaseBeanContextResources () + protected void releaseBeanContextResources () + throws NotImplementedException { throw new Error ("Not implemented"); } public void releaseService (BeanContextChild child, Object requestor, Object service) + throws NotImplementedException { throw new Error ("Not implemented"); } @@ -276,25 +347,52 @@ public class BeanContextServicesSupport public void removeBeanContextServicesListener (BeanContextServicesListener listener) { - int index = bcsListeners.indexOf(listener); - - if (index > -1) - bcsListeners.remove(index); + synchronized (bcsListeners) + { + int index = bcsListeners.indexOf(listener); + if (index > -1) + bcsListeners.remove(index); + } } public void revokeService (Class serviceClass, BeanContextServiceProvider bcsp, - boolean revokeCurrentServicesNow) + boolean revokeCurrentServicesNow) + throws NotImplementedException { throw new Error ("Not implemented"); } - public void serviceAvailable (BeanContextServiceAvailableEvent bcssae) - { - throw new Error ("Not implemented"); - } - - public void serviceRevoked (BeanContextServiceRevokedEvent bcssre) - { - throw new Error ("Not implemented"); + public void serviceAvailable (BeanContextServiceAvailableEvent bcssae) + { + synchronized (services) + { + Class klass = bcssae.getServiceClass(); + if (services.containsKey(klass)) + return; + Iterator it = bcsChildren(); + while (it.hasNext()) + { + Object obj = it.next(); + if (obj instanceof BeanContextServices) + ((BeanContextServices) obj).serviceAvailable(bcssae); + } + } + } + + public void serviceRevoked (BeanContextServiceRevokedEvent bcssre) + { + synchronized (services) + { + Class klass = bcssre.getServiceClass(); + if (services.containsKey(klass)) + return; + Iterator it = bcsChildren(); + while (it.hasNext()) + { + Object obj = it.next(); + if (obj instanceof BeanContextServices) + ((BeanContextServices) obj).serviceRevoked(bcssre); + } + } } } diff --git a/libjava/classpath/java/beans/beancontext/BeanContextSupport.java b/libjava/classpath/java/beans/beancontext/BeanContextSupport.java index 60ccc3a..f3d5ff6 100644 --- a/libjava/classpath/java/beans/beancontext/BeanContextSupport.java +++ b/libjava/classpath/java/beans/beancontext/BeanContextSupport.java @@ -38,6 +38,9 @@ exception statement from your version. */ package java.beans.beancontext; +import gnu.classpath.NotImplementedException; + +import java.beans.DesignMode; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.beans.PropertyVetoException; @@ -64,15 +67,19 @@ public class BeanContextSupport extends BeanContextChildSupport VetoableChangeListener { private static final long serialVersionUID = -4879613978649577204L; - + + // This won't show up in japi, but we mark it as a stub anyway, + // so that searches for NotImplementedException will find it. private void readObject (ObjectInputStream s) - throws ClassNotFoundException, IOException + throws ClassNotFoundException, IOException, NotImplementedException { throw new Error ("Not implemented"); } + // This won't show up in japi, but we mark it as a stub anyway, + // so that searches for NotImplementedException will find it. private void writeObject (ObjectOutputStream s) - throws ClassNotFoundException, IOException + throws ClassNotFoundException, IOException, NotImplementedException { throw new Error ("Not implemented"); } @@ -80,18 +87,34 @@ public class BeanContextSupport extends BeanContextChildSupport protected class BCSChild implements Serializable { private static final long serialVersionUID = -5815286101609939109L; + + private Object targetChild; + private Object peer; + + BCSChild(Object targetChild, Object peer) + { + this.targetChild = targetChild; + this.peer = peer; + } } protected static final class BCSIterator implements Iterator { + private Iterator child; + + BCSIterator(Iterator child) + { + this.child = child; + } + public boolean hasNext () { - throw new Error ("Not implemented"); + return child.hasNext(); } public Object next () { - throw new Error ("Not implemented"); + return child.next(); } public void remove () @@ -148,7 +171,9 @@ public class BeanContextSupport extends BeanContextChildSupport public BeanContextSupport (BeanContext peer, Locale lcle, boolean dtime, boolean visible) { - locale = lcle; + super(peer); + + locale = lcle == null ? Locale.getDefault() : lcle; designTime = dtime; okToUseGui = visible; @@ -160,150 +185,214 @@ public class BeanContextSupport extends BeanContextChildSupport if (targetChild == null) throw new IllegalArgumentException(); - if (children.containsKey(targetChild)) - return false; - - // FIXME: The second argument is surely wrong. - children.put(targetChild, targetChild); + BCSChild child; + synchronized (children) + { + if (children.containsKey(targetChild) + || ! validatePendingAdd(targetChild)) + return false; + child = createBCSChild(targetChild, beanContextChildPeer); + children.put(targetChild, child); + } + synchronized (targetChild) + { + childJustAddedHook(targetChild, child); + } + fireChildrenAdded(new BeanContextMembershipEvent(this, + new Object[] { targetChild })); return true; } public boolean addAll (Collection c) { + // Intentionally throws an exception. throw new UnsupportedOperationException(); } public void addBeanContextMembershipListener (BeanContextMembershipListener listener) { - if (! bcmListeners.contains(listener)) - bcmListeners.add(listener); + synchronized (bcmListeners) + { + if (! bcmListeners.contains(listener)) + bcmListeners.add(listener); + } } public boolean avoidingGui () + throws NotImplementedException { throw new Error ("Not implemented"); } protected Iterator bcsChildren () { - throw new Error ("Not implemented"); + synchronized (children) + { + return new BCSIterator(children.values().iterator()); + } } protected void bcsPreDeserializationHook (ObjectInputStream ois) - throws ClassNotFoundException, IOException + throws ClassNotFoundException, IOException, NotImplementedException { throw new Error ("Not implemented"); } protected void bcsPreSerializationHook (ObjectOutputStream oos) - throws IOException + throws IOException, NotImplementedException { throw new Error ("Not implemented"); } protected void childDeserializedHook (Object child, BeanContextSupport.BCSChild bcsc) + throws NotImplementedException { throw new Error ("Not implemented"); } protected void childJustAddedHook (Object child, BeanContextSupport.BCSChild bcsc) { - throw new Error ("Not implemented"); + // Do nothing in the base class. } protected void childJustRemovedHook (Object child, BeanContextSupport.BCSChild bcsc) { - throw new Error ("Not implemented"); + // Do nothing in the base class. } protected static final boolean classEquals (Class first, Class second) { - throw new Error ("Not implemented"); + // Lame function! + return (first == second || first.getName().equals(second.getName())); } public void clear () { + // This is the right thing to do. + // The JDK docs are really bad here. throw new UnsupportedOperationException(); } public boolean contains (Object o) { - throw new Error ("Not implemented"); + synchronized (children) + { + return children.containsKey(o); + } } public boolean containsAll (Collection c) { - throw new Error ("Not implemented"); + synchronized (children) + { + Iterator it = c.iterator(); + while (it.hasNext()) + if (! children.containsKey(it.next())) + return false; + } + return true; } public boolean containsKey (Object o) { - throw new Error ("Not implemented"); + synchronized (children) + { + return children.containsKey(o); + } } protected final Object[] copyChildren () { - throw new Error ("Not implemented"); + synchronized (children) + { + return children.keySet().toArray(); + } } protected BeanContextSupport.BCSChild createBCSChild (Object targetChild, Object peer) { - throw new Error ("Not implemented"); + return new BCSChild(targetChild, peer); } protected final void deserialize (ObjectInputStream ois, Collection coll) - throws ClassNotFoundException, IOException + throws ClassNotFoundException, IOException, NotImplementedException { throw new Error ("Not implemented"); } public void dontUseGui () + throws NotImplementedException { throw new Error ("Not implemented"); } protected final void fireChildrenAdded (BeanContextMembershipEvent bcme) { - throw new Error ("Not implemented"); + synchronized (bcmListeners) + { + Iterator it = bcmListeners.iterator(); + while (it.hasNext()) + { + BeanContextMembershipListener l + = (BeanContextMembershipListener) it.next(); + l.childrenAdded(bcme); + } + } } protected final void fireChildrenRemoved (BeanContextMembershipEvent bcme) { - throw new Error ("Not implemented"); + synchronized (bcmListeners) + { + Iterator it = bcmListeners.iterator(); + while (it.hasNext()) + { + BeanContextMembershipListener l + = (BeanContextMembershipListener) it.next(); + l.childrenRemoved(bcme); + } + } } public BeanContext getBeanContextPeer () + throws NotImplementedException { throw new Error ("Not implemented"); } protected static final BeanContextChild getChildBeanContextChild (Object child) + throws NotImplementedException { throw new Error ("Not implemented"); } protected static final BeanContextMembershipListener getChildBeanContextMembershipListener (Object child) + throws NotImplementedException { throw new Error ("Not implemented"); } protected static final PropertyChangeListener getChildPropertyChangeListener (Object child) + throws NotImplementedException { throw new Error ("Not implemented"); } protected static final Serializable getChildSerializable (Object child) + throws NotImplementedException { throw new Error ("Not implemented"); } protected static final VetoableChangeListener getChildVetoableChangeListener (Object child) + throws NotImplementedException { throw new Error ("Not implemented"); } protected static final Visibility getChildVisibility (Object child) + throws NotImplementedException { throw new Error ("Not implemented"); } @@ -315,12 +404,20 @@ public class BeanContextSupport extends BeanContextChildSupport public URL getResource (String name, BeanContextChild bcc) { - throw new Error ("Not implemented"); + if (! contains(bcc)) + throw new IllegalArgumentException("argument not a child"); + ClassLoader loader = bcc.getClass().getClassLoader(); + return (loader == null ? ClassLoader.getSystemResource(name) + : loader.getResource(name)); } public InputStream getResourceAsStream (String name, BeanContextChild bcc) { - throw new Error ("Not implemented"); + if (! contains(bcc)) + throw new IllegalArgumentException("argument not a child"); + ClassLoader loader = bcc.getClass().getClassLoader(); + return (loader == null ? ClassLoader.getSystemResourceAsStream(name) + : loader.getResourceAsStream(name)); } protected void initialize () @@ -330,48 +427,58 @@ public class BeanContextSupport extends BeanContextChildSupport } public Object instantiateChild (String beanName) - throws IOException, ClassNotFoundException + throws IOException, ClassNotFoundException, NotImplementedException { throw new Error ("Not implemented"); } public boolean isDesignTime () { - throw new Error ("Not implemented"); + return designTime; } public boolean isEmpty () { - throw new Error ("Not implemented"); + synchronized (children) + { + return children.isEmpty(); + } } public boolean isSerializing () + throws NotImplementedException { throw new Error ("Not implemented"); } public Iterator iterator () { - return children.keySet().iterator(); + synchronized (children) + { + return children.keySet().iterator(); + } } public boolean needsGui () + throws NotImplementedException { throw new Error ("Not implemented"); } public void okToUseGui () + throws NotImplementedException { throw new Error ("Not implemented"); } public void propertyChange (PropertyChangeEvent pce) + throws NotImplementedException { throw new Error ("Not implemented"); } public final void readChildren (ObjectInputStream ois) - throws IOException, ClassNotFoundException + throws IOException, ClassNotFoundException, NotImplementedException { throw new Error ("Not implemented"); } @@ -382,6 +489,7 @@ public class BeanContextSupport extends BeanContextChildSupport } protected boolean remove (Object targetChild, boolean callChildSetBC) + throws NotImplementedException { if (targetChild == null) throw new IllegalArgumentException(); @@ -391,69 +499,93 @@ public class BeanContextSupport extends BeanContextChildSupport public boolean removeAll (Collection c) { + // Intentionally throws an exception. throw new UnsupportedOperationException(); } public void removeBeanContextMembershipListener (BeanContextMembershipListener bcml) { - throw new Error ("Not implemented"); + synchronized (bcmListeners) + { + bcmListeners.remove(bcml); + } } public boolean retainAll (Collection c) { + // Intentionally throws an exception. throw new UnsupportedOperationException(); } protected final void serialize (ObjectOutputStream oos, Collection coll) - throws IOException + throws IOException, NotImplementedException { throw new Error ("Not implemented"); } public void setDesignTime (boolean dtime) { - throw new Error ("Not implemented"); + boolean save = designTime; + designTime = dtime; + firePropertyChange(DesignMode.PROPERTYNAME, Boolean.valueOf(save), + Boolean.valueOf(dtime)); } public void setLocale (Locale newLocale) throws PropertyVetoException { - throw new Error ("Not implemented"); + if (newLocale == null || locale == newLocale) + return; + fireVetoableChange("locale", locale, newLocale); + Locale oldLocale = locale; + locale = newLocale; + firePropertyChange("locale", oldLocale, newLocale); } public int size () { - throw new Error ("Not implemented"); + synchronized (children) + { + return children.size(); + } } public Object[] toArray () { - return children.keySet().toArray(); + synchronized (children) + { + return children.keySet().toArray(); + } } public Object[] toArray(Object[] array) + throws NotImplementedException { - return children.keySet().toArray(array); + // This implementation is incorrect, I think. + synchronized (children) + { + return children.keySet().toArray(array); + } } protected boolean validatePendingAdd (Object targetChild) { - throw new Error ("Not implemented"); + return true; } protected boolean validatePendingRemove (Object targetChild) { - throw new Error ("Not implemented"); + return true; } public void vetoableChange (PropertyChangeEvent pce) - throws PropertyVetoException + throws PropertyVetoException, NotImplementedException { throw new Error ("Not implemented"); } public final void writeChildren (ObjectOutputStream oos) - throws IOException + throws IOException, NotImplementedException { throw new Error ("Not implemented"); } |