home *** CD-ROM | disk | FTP | other *** search
- package java.beans.beancontext;
-
- import java.io.IOException;
- import java.io.ObjectInputStream;
- import java.io.ObjectOutputStream;
- import java.io.Serializable;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.Iterator;
- import java.util.Locale;
- import java.util.Map;
- import java.util.TooManyListenersException;
-
- public class BeanContextServicesSupport extends BeanContextSupport implements BeanContextServices {
- protected transient HashMap services;
- protected transient int serializable;
- protected transient BCSSProxyServiceProvider proxy;
- protected transient ArrayList bcsListeners;
-
- public BeanContextServicesSupport(BeanContextServices var1, Locale var2, boolean var3, boolean var4) {
- super(var1, var2, var3, var4);
- this.serializable = 0;
- }
-
- public BeanContextServicesSupport(BeanContextServices var1, Locale var2, boolean var3) {
- this(var1, var2, var3, true);
- }
-
- public BeanContextServicesSupport(BeanContextServices var1, Locale var2) {
- this(var1, var2, false, true);
- }
-
- public BeanContextServicesSupport(BeanContextServices var1) {
- this(var1, (Locale)null, false, true);
- }
-
- public BeanContextServicesSupport() {
- this((BeanContextServices)null, (Locale)null, false, true);
- }
-
- public void initialize() {
- super.initialize();
- this.services = new HashMap(this.serializable + 1);
- this.bcsListeners = new ArrayList(1);
- }
-
- public BeanContextServices getBeanContextServicesPeer() {
- return (BeanContextServices)((BeanContextChildSupport)this).getBeanContextChildPeer();
- }
-
- protected BeanContextSupport.BCSChild createBCSChild(Object var1, Object var2) {
- return new BCSSChild(this, var1, var2);
- }
-
- protected BCSSServiceProvider createBCSSServiceProvider(Class var1, BeanContextServiceProvider var2) {
- return new BCSSServiceProvider(var1, var2);
- }
-
- public void addBeanContextServicesListener(BeanContextServicesListener var1) {
- if (var1 == null) {
- throw new NullPointerException("bcsl");
- } else {
- ArrayList var2 = this.bcsListeners;
- synchronized(var2) {
- if (!this.bcsListeners.contains(var1)) {
- this.bcsListeners.add(var1);
- }
- }
- }
- }
-
- public void removeBeanContextServicesListener(BeanContextServicesListener var1) {
- if (var1 == null) {
- throw new NullPointerException("bcsl");
- } else {
- ArrayList var2 = this.bcsListeners;
- synchronized(var2) {
- if (this.bcsListeners.contains(var1)) {
- this.bcsListeners.remove(var1);
- }
- }
- }
- }
-
- public boolean addService(Class var1, BeanContextServiceProvider var2) {
- return this.addService(var1, var2, true);
- }
-
- protected boolean addService(Class var1, BeanContextServiceProvider var2, boolean var3) {
- if (var1 == null) {
- throw new NullPointerException("serviceClass");
- } else if (var2 == null) {
- throw new NullPointerException("bcsp");
- } else {
- Object var4 = BeanContext.globalHierarchyLock;
- synchronized(var4) {
- if (this.services.containsKey(var1)) {
- boolean var5 = false;
- return var5;
- } else {
- this.services.put(var1, this.createBCSSServiceProvider(var1, var2));
- if (var2 instanceof Serializable) {
- ++this.serializable;
- }
-
- if (!var3) {
- boolean var6 = true;
- return var6;
- } else {
- BeanContextServiceAvailableEvent var7 = new BeanContextServiceAvailableEvent(this.getBeanContextServicesPeer(), var1);
- this.fireServiceAdded(var7);
- HashMap var8 = super.children;
- synchronized(var8) {
- for(Object var10 : super.children.keySet()) {
- if (var10 instanceof BeanContextServices) {
- ((BeanContextServicesListener)var10).serviceAvailable(var7);
- }
- }
- }
-
- boolean var15 = true;
- return var15;
- }
- }
- }
- }
- }
-
- public void revokeService(Class var1, BeanContextServiceProvider var2, boolean var3) {
- if (var1 == null) {
- throw new NullPointerException("serviceClass");
- } else if (var2 == null) {
- throw new NullPointerException("bcsp");
- } else {
- Object var4 = BeanContext.globalHierarchyLock;
- synchronized(var4) {
- if (this.services.containsKey(var1)) {
- BCSSServiceProvider var5 = (BCSSServiceProvider)this.services.get(var1);
- if (!var5.getServiceProvider().equals(var2)) {
- throw new IllegalArgumentException("service provider mismatch");
- } else {
- this.services.remove(var1);
- if (var2 instanceof Serializable) {
- --this.serializable;
- }
-
- Iterator var6 = ((BeanContextSupport)this).bcsChildren();
-
- while(var6.hasNext()) {
- ((BCSSChild)var6.next()).revokeService(var1, false, var3);
- }
-
- this.fireServiceRevoked(var1, var3);
- }
- }
- }
- }
- }
-
- public synchronized boolean hasService(Class var1) {
- if (var1 == null) {
- throw new NullPointerException("serviceClass");
- } else {
- Object var2 = BeanContext.globalHierarchyLock;
- synchronized(var2) {
- if (this.services.containsKey(var1)) {
- boolean var3 = true;
- return var3;
- } else {
- Object var4 = null;
-
- try {
- var10 = (BeanContextServices)((BeanContextChildSupport)this).getBeanContext();
- } catch (ClassCastException var8) {
- boolean var6 = false;
- return var6;
- }
-
- boolean var5 = var10 == null ? false : var10.hasService(var1);
- return var5;
- }
- }
- }
- }
-
- public Object getService(BeanContextChild var1, Object var2, Class var3, Object var4, BeanContextServiceRevokedListener var5) throws TooManyListenersException {
- if (var1 == null) {
- throw new NullPointerException("child");
- } else if (var3 == null) {
- throw new NullPointerException("serviceClass");
- } else if (var2 == null) {
- throw new NullPointerException("requestor");
- } else if (var5 == null) {
- throw new NullPointerException("bcsrl");
- } else {
- Object var6 = null;
- BeanContextServices var8 = this.getBeanContextServicesPeer();
- Object var9 = BeanContext.globalHierarchyLock;
- synchronized(var9) {
- HashMap var10 = super.children;
- BCSSChild var7;
- synchronized(var10) {
- var7 = (BCSSChild)super.children.get(var1);
- }
-
- if (var7 == null) {
- throw new IllegalArgumentException("not a child of this context");
- } else {
- BCSSServiceProvider var11 = (BCSSServiceProvider)this.services.get(var3);
- if (var11 != null) {
- BeanContextServiceProvider var12 = var11.getServiceProvider();
- var6 = var12.getService(var8, var2, var3, var4);
- if (var6 != null) {
- try {
- var7.usingService(var2, var6, var3, var12, false, var5);
- } catch (TooManyListenersException var16) {
- var12.releaseService(var8, var2, var6);
- throw var16;
- } catch (UnsupportedOperationException var17) {
- var12.releaseService(var8, var2, var6);
- throw var17;
- }
-
- return var6;
- }
- }
-
- if (this.proxy != null) {
- var6 = this.proxy.getService(var8, var2, var3, var4);
- if (var6 != null) {
- try {
- var7.usingService(var2, var6, var3, this.proxy, true, var5);
- } catch (TooManyListenersException var18) {
- this.proxy.releaseService(var8, var2, var6);
- throw var18;
- } catch (UnsupportedOperationException var19) {
- this.proxy.releaseService(var8, var2, var6);
- throw var19;
- }
-
- return var6;
- }
- }
-
- return null;
- }
- }
- }
- }
-
- public void releaseService(BeanContextChild var1, Object var2, Object var3) {
- if (var1 == null) {
- throw new NullPointerException("child");
- } else if (var2 == null) {
- throw new NullPointerException("requestor");
- } else if (var3 == null) {
- throw new NullPointerException("service");
- } else {
- Object var5 = BeanContext.globalHierarchyLock;
- synchronized(var5) {
- HashMap var6 = super.children;
- BCSSChild var4;
- synchronized(var6) {
- var4 = (BCSSChild)super.children.get(var1);
- }
-
- if (var4 != null) {
- var4.releaseService(var2, var3);
- } else {
- throw new IllegalArgumentException("child actual is not a child of this BeanContext");
- }
- }
- }
- }
-
- public Iterator getCurrentServiceClasses() {
- return new BeanContextSupport.BCSIterator(this.services.keySet().iterator());
- }
-
- public Iterator getCurrentServiceSelectors(Class var1) {
- BCSSServiceProvider var2 = (BCSSServiceProvider)this.services.get(var1);
- return var2 != null ? new BeanContextSupport.BCSIterator(var2.getServiceProvider().getCurrentServiceSelectors(this.getBeanContextServicesPeer(), var1)) : null;
- }
-
- public void serviceAvailable(BeanContextServiceAvailableEvent var1) {
- Object var2 = BeanContext.globalHierarchyLock;
- synchronized(var2) {
- if (!this.services.containsKey(var1.getServiceClass())) {
- this.fireServiceAdded(var1);
- HashMap var4 = super.children;
- synchronized(var4) {
- ;
- }
-
- for(Object var5 : super.children.keySet()) {
- if (var5 instanceof BeanContextServices) {
- ((BeanContextServicesListener)var5).serviceAvailable(var1);
- }
- }
-
- }
- }
- }
-
- public void serviceRevoked(BeanContextServiceRevokedEvent var1) {
- Object var2 = BeanContext.globalHierarchyLock;
- synchronized(var2) {
- if (!this.services.containsKey(var1.getServiceClass())) {
- this.fireServiceRevoked(var1);
- HashMap var4 = super.children;
- synchronized(var4) {
- ;
- }
-
- for(Object var5 : super.children.keySet()) {
- if (var5 instanceof BeanContextServices) {
- ((BeanContextServicesListener)var5).serviceRevoked(var1);
- }
- }
-
- }
- }
- }
-
- protected static final BeanContextServicesListener getChildBeanContextServicesListener(Object var0) {
- try {
- return (BeanContextServicesListener)var0;
- } catch (ClassCastException var2) {
- return null;
- }
- }
-
- protected void childJustRemovedHook(Object var1, BeanContextSupport.BCSChild var2) {
- BCSSChild var3 = (BCSSChild)var2;
- var3.cleanupReferences();
- }
-
- protected synchronized void releaseBeanContextResources() {
- super.releaseBeanContextResources();
- HashMap var2 = super.children;
- Object[] var1;
- synchronized(var2) {
- if (super.children.isEmpty()) {
- return;
- }
-
- var1 = super.children.values().toArray();
- }
-
- for(int var3 = 0; var3 < var1.length; ++var3) {
- ((BCSSChild)var1[var3]).revokeAllDelegatedServicesNow();
- }
-
- this.proxy = null;
- }
-
- protected synchronized void initializeBeanContextResources() {
- super.initializeBeanContextResources();
- BeanContext var1 = ((BeanContextChildSupport)this).getBeanContext();
- if (var1 != null) {
- try {
- BeanContextServices var2 = (BeanContextServices)var1;
- this.proxy = new BCSSProxyServiceProvider(this, var2);
- } catch (ClassCastException var3) {
- }
-
- }
- }
-
- protected final void fireServiceAdded(Class var1) {
- BeanContextServiceAvailableEvent var2 = new BeanContextServiceAvailableEvent(this.getBeanContextServicesPeer(), var1);
- this.fireServiceAdded(var2);
- }
-
- protected final void fireServiceAdded(BeanContextServiceAvailableEvent var1) {
- ArrayList var3 = this.bcsListeners;
- Object[] var2;
- synchronized(var3) {
- var2 = this.bcsListeners.toArray();
- }
-
- for(int var4 = 0; var4 < var2.length; ++var4) {
- ((BeanContextServicesListener)var2[var4]).serviceAvailable(var1);
- }
-
- }
-
- protected final void fireServiceRevoked(BeanContextServiceRevokedEvent var1) {
- ArrayList var3 = this.bcsListeners;
- Object[] var2;
- synchronized(var3) {
- var2 = this.bcsListeners.toArray();
- }
-
- for(int var4 = 0; var4 < var2.length; ++var4) {
- ((BeanContextServiceRevokedListener)var2[var4]).serviceRevoked(var1);
- }
-
- }
-
- protected final void fireServiceRevoked(Class var1, boolean var2) {
- BeanContextServiceRevokedEvent var4 = new BeanContextServiceRevokedEvent(this.getBeanContextServicesPeer(), var1, var2);
- ArrayList var5 = this.bcsListeners;
- Object[] var3;
- synchronized(var5) {
- var3 = this.bcsListeners.toArray();
- }
-
- for(int var6 = 0; var6 < var3.length; ++var6) {
- ((BeanContextServicesListener)var3[var6]).serviceRevoked(var4);
- }
-
- }
-
- protected synchronized void bcsPreSerializationHook(ObjectOutputStream var1) throws IOException {
- var1.writeInt(this.serializable);
- if (this.serializable > 0) {
- int var2 = 0;
- Iterator var3 = this.services.entrySet().iterator();
-
- while(var3.hasNext() && var2 < this.serializable) {
- Map.Entry var4 = (Map.Entry)var3.next();
- Object var5 = null;
-
- try {
- var8 = (BCSSServiceProvider)var4.getValue();
- } catch (ClassCastException var7) {
- continue;
- }
-
- if (var8.getServiceProvider() instanceof Serializable) {
- var1.writeObject(var4.getKey());
- var1.writeObject(var8);
- ++var2;
- }
- }
-
- if (var2 != this.serializable) {
- throw new IOException("wrote different number of service providers than expected");
- }
- }
- }
-
- protected synchronized void bcsPreDeserializationHook(ObjectInputStream var1) throws IOException, ClassNotFoundException {
- this.serializable = var1.readInt();
-
- for(int var2 = this.serializable; var2 > 0; --var2) {
- this.services.put(var1.readObject(), var1.readObject());
- }
-
- }
-
- private synchronized void writeObject(ObjectOutputStream var1) throws IOException {
- var1.defaultWriteObject();
- ((BeanContextSupport)this).serialize(var1, this.bcsListeners);
- }
-
- private synchronized void readObject(ObjectInputStream var1) throws IOException, ClassNotFoundException {
- var1.defaultReadObject();
- ((BeanContextSupport)this).deserialize(var1, this.bcsListeners);
- }
- }
-