diff options
| author | Tom Tromey <tromey@redhat.com> | 2006-04-07 16:25:56 +0000 |
|---|---|---|
| committer | Tom Tromey <tromey@redhat.com> | 2006-04-07 16:25:56 +0000 |
| commit | bafaa5739338ef0ad48d205a93c4d3ca107a48be (patch) | |
| tree | 73258c0723a4e47b9925dfbb664b5994e198a129 /java | |
| parent | 381a2189e271efd31922aa6c51c0f050f0d4dc64 (diff) | |
| download | classpath-bafaa5739338ef0ad48d205a93c4d3ca107a48be.tar.gz | |
* java/beans/beancontext/BeanContextMembershipEvent.java
(serialVersionUID): New field.
* java/beans/beancontext/BeanContextServicesSupport.java
(addBeanContextServicesListener): Synchronize.
(addService): Implemented.
(createBCSChild): Implemented.
(BCSSChild): Added arguments.
(fireServiceAdded): Implemented.
(fireServiceRevoked): Implemented.
(getCurrentServiceSelectors): Implemented.
(hasService): Implemented.
(removeBeanContextServicesListener): Implemented.
(serviceAvailable): Implemented.
(serviceRevoked): Implemented.
* java/beans/beancontext/BeanContextSupport.java (BCSChild): Added
arguments.
(createBCSChild): Implemented.
(BeanContextSupport):
(addBeanContextMembershipListener): Synchronize.
(fireChildrenAdded): Implemented.
(fireChildrenRemoved): Implemented.
(BeanContextSupport): Use default locale.
(isEmpty): Implemented.
(isDesignTime): Implemented.
(size): Implemented.
(toArray): Synchronized.
(toArray): Likewise.
(iterator): Likewise.
(BCSIterator): Implemented.
(bcsChildren): Implemented.
(validatePendingAdd): Implemented.
(validatePendingRemove): Likewise.
(childJustAddedHook): Implemented.
(childJustRemovedHook): Likewise.
(classEquals): Likewise.
(toArray): Mark as stub.
(setDesignTime): Implemented.
(copyChildren): Implemented.
(containsKey): Implemented.
(contains): Likewise.
(containsAll): Likewise.
(getResource): Implemented.
(getResourceAsStream): Likewise.
(removeBeanContextMembershipListener): Likewise.
* java/beans/beancontext/BeanContextServiceRevokedEvent.java
(serialVersionUID): New field.
* java/beans/beancontext/BeanContextServiceAvailableEvent.java
(serialVersionUID): New field.
* java/beans/beancontext/BeanContext.java (instantiateChild): Javadoc
fix.
Diffstat (limited to 'java')
6 files changed, 241 insertions, 94 deletions
diff --git a/java/beans/beancontext/BeanContext.java b/java/beans/beancontext/BeanContext.java index 3d1be7fc8..02f4a1a40 100644 --- a/java/beans/beancontext/BeanContext.java +++ b/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/java/beans/beancontext/BeanContextMembershipEvent.java b/java/beans/beancontext/BeanContextMembershipEvent.java index 317654266..9560889f8 100644 --- a/java/beans/beancontext/BeanContextMembershipEvent.java +++ b/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/java/beans/beancontext/BeanContextServiceAvailableEvent.java b/java/beans/beancontext/BeanContextServiceAvailableEvent.java index eea10f261..6dc2c38ab 100644 --- a/java/beans/beancontext/BeanContextServiceAvailableEvent.java +++ b/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/java/beans/beancontext/BeanContextServiceRevokedEvent.java b/java/beans/beancontext/BeanContextServiceRevokedEvent.java index dfa2b89b3..1f5ebd3cd 100644 --- a/java/beans/beancontext/BeanContextServiceRevokedEvent.java +++ b/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/java/beans/beancontext/BeanContextServicesSupport.java b/java/beans/beancontext/BeanContextServicesSupport.java index 679464478..4da523eeb 100644 --- a/java/beans/beancontext/BeanContextServicesSupport.java +++ b/java/beans/beancontext/BeanContextServicesSupport.java @@ -65,8 +65,9 @@ public class BeanContextServicesSupport { private static final long serialVersionUID = -3263851306889194873L; - private BCSSChild() + BCSSChild(Object targetChild, Object peer) { + super(targetChild, peer); } } @@ -166,22 +167,33 @@ 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) - throws NotImplementedException + 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) - throws NotImplementedException { - 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) @@ -205,9 +217,8 @@ public class BeanContextServicesSupport protected BeanContextSupport.BCSChild createBCSChild (Object targetChild, Object peer) - throws NotImplementedException { - throw new Error ("Not implemented"); + return new BCSSChild(targetChild, peer); } protected BeanContextServicesSupport.BCSSServiceProvider @@ -218,28 +229,44 @@ public class BeanContextServicesSupport } protected final void fireServiceAdded (BeanContextServiceAvailableEvent bcssae) - throws NotImplementedException { - 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) - throws NotImplementedException { - throw new Error ("Not implemented"); + fireServiceAdded(new BeanContextServiceAvailableEvent(this, + serviceClass)); } protected final void fireServiceRevoked(BeanContextServiceRevokedEvent event) - throws NotImplementedException { - 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) - throws NotImplementedException { - throw new Error ("Not implemented"); + fireServiceRevoked(new BeanContextServiceRevokedEvent(this, serviceClass, + revokeNow)); } public BeanContextServices getBeanContextServicesPeer () @@ -256,15 +283,22 @@ public class BeanContextServicesSupport } public Iterator getCurrentServiceClasses () - throws NotImplementedException { - throw new Error ("Not implemented"); + synchronized (services) + { + return services.keySet().iterator(); + } } public Iterator getCurrentServiceSelectors (Class serviceClass) - throws NotImplementedException { - 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, @@ -276,9 +310,11 @@ public class BeanContextServicesSupport } public boolean hasService (Class serviceClass) - throws NotImplementedException { - throw new Error ("Not implemented"); + synchronized (services) + { + return services.containsKey(serviceClass); + } } public void initialize () @@ -311,10 +347,12 @@ 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, @@ -325,14 +363,36 @@ public class BeanContextServicesSupport } public void serviceAvailable (BeanContextServiceAvailableEvent bcssae) - throws NotImplementedException { - throw new Error ("Not implemented"); + 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) - throws NotImplementedException { - throw new Error ("Not implemented"); + 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/java/beans/beancontext/BeanContextSupport.java b/java/beans/beancontext/BeanContextSupport.java index 5770c4fb0..f964e2e75 100644 --- a/java/beans/beancontext/BeanContextSupport.java +++ b/java/beans/beancontext/BeanContextSupport.java @@ -40,6 +40,7 @@ package java.beans.beancontext; import gnu.classpath.NotImplementedException; +import java.beans.DesignMode; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.beans.PropertyVetoException; @@ -87,27 +88,35 @@ public class BeanContextSupport extends BeanContextChildSupport { private static final long serialVersionUID = -5815286101609939109L; - BCSChild() + private Object targetChild; + private Object peer; + + BCSChild(Object targetChild, Object peer) { + this.targetChild = targetChild; + this.peer = peer; } } protected static final class BCSIterator implements Iterator { - BCSIterator() + private Iterator child; + + BCSIterator(Iterator child) { + this.child = child; } public boolean hasNext () throws NotImplementedException { - throw new Error ("Not implemented"); + return child.hasNext(); } public Object next () throws NotImplementedException { - throw new Error ("Not implemented"); + return child.next(); } public void remove () @@ -164,7 +173,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; @@ -176,24 +187,38 @@ 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 () @@ -203,9 +228,11 @@ public class BeanContextSupport extends BeanContextChildSupport } protected Iterator bcsChildren () - throws NotImplementedException { - throw new Error ("Not implemented"); + synchronized (children) + { + return new BCSIterator(children.values().iterator()); + } } protected void bcsPreDeserializationHook (ObjectInputStream ois) @@ -227,58 +254,67 @@ public class BeanContextSupport extends BeanContextChildSupport } protected void childJustAddedHook (Object child, BeanContextSupport.BCSChild bcsc) - throws NotImplementedException { - throw new Error ("Not implemented"); + // Do nothing in the base class. } protected void childJustRemovedHook (Object child, BeanContextSupport.BCSChild bcsc) - throws NotImplementedException { - throw new Error ("Not implemented"); + // Do nothing in the base class. } protected static final boolean classEquals (Class first, Class second) - throws NotImplementedException { - throw new Error ("Not implemented"); + // Lame function! + return (first == second || first.getName().equals(second.getName())); } public void clear () { - // This is probably the right thing to do. + // This is the right thing to do. // The JDK docs are really bad here. throw new UnsupportedOperationException(); } public boolean contains (Object o) - throws NotImplementedException { - throw new Error ("Not implemented"); + synchronized (children) + { + return children.containsKey(o); + } } public boolean containsAll (Collection c) - throws NotImplementedException { - 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) - throws NotImplementedException { - throw new Error ("Not implemented"); + synchronized (children) + { + return children.containsKey(o); + } } protected final Object[] copyChildren () - throws NotImplementedException { - throw new Error ("Not implemented"); + synchronized (children) + { + return children.keySet().toArray(); + } } protected BeanContextSupport.BCSChild createBCSChild (Object targetChild, Object peer) - throws NotImplementedException { - throw new Error ("Not implemented"); + return new BCSChild(targetChild, peer); } protected final void deserialize (ObjectInputStream ois, Collection coll) @@ -294,15 +330,31 @@ public class BeanContextSupport extends BeanContextChildSupport } protected final void fireChildrenAdded (BeanContextMembershipEvent bcme) - throws NotImplementedException { - 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) - throws NotImplementedException { - 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 () @@ -353,15 +405,21 @@ public class BeanContextSupport extends BeanContextChildSupport } public URL getResource (String name, BeanContextChild bcc) - throws NotImplementedException { - 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) - throws NotImplementedException { - 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 () @@ -377,15 +435,16 @@ public class BeanContextSupport extends BeanContextChildSupport } public boolean isDesignTime () - throws NotImplementedException { - throw new Error ("Not implemented"); + return designTime; } public boolean isEmpty () - throws NotImplementedException { - throw new Error ("Not implemented"); + synchronized (children) + { + return children.isEmpty(); + } } public boolean isSerializing () @@ -396,7 +455,10 @@ public class BeanContextSupport extends BeanContextChildSupport public Iterator iterator () { - return children.keySet().iterator(); + synchronized (children) + { + return children.keySet().iterator(); + } } public boolean needsGui () @@ -439,17 +501,21 @@ public class BeanContextSupport extends BeanContextChildSupport public boolean removeAll (Collection c) { + // Intentionally throws an exception. throw new UnsupportedOperationException(); } public void removeBeanContextMembershipListener (BeanContextMembershipListener bcml) - throws NotImplementedException { - throw new Error ("Not implemented"); + synchronized (bcmListeners) + { + bcmListeners.remove(bcml); + } } public boolean retainAll (Collection c) { + // Intentionally throws an exception. throw new UnsupportedOperationException(); } @@ -460,43 +526,58 @@ public class BeanContextSupport extends BeanContextChildSupport } public void setDesignTime (boolean dtime) - throws NotImplementedException { - 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, NotImplementedException + 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 () - throws NotImplementedException { - 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) - throws NotImplementedException { - throw new Error ("Not implemented"); + return true; } protected boolean validatePendingRemove (Object targetChild) - throws NotImplementedException { - throw new Error ("Not implemented"); + return true; } public void vetoableChange (PropertyChangeEvent pce) |
