home *** CD-ROM | disk | FTP | other *** search
- package java.beans.beancontext;
-
- import java.awt.Component;
- import java.awt.Container;
- import java.beans.Beans;
- import java.beans.PropertyChangeEvent;
- import java.beans.PropertyChangeListener;
- import java.beans.PropertyVetoException;
- import java.beans.VetoableChangeListener;
- import java.beans.Visibility;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.ObjectInputStream;
- import java.io.ObjectOutputStream;
- import java.io.Serializable;
- import java.net.URL;
- import java.util.ArrayList;
- import java.util.Collection;
- import java.util.EventObject;
- import java.util.HashMap;
- import java.util.Iterator;
- import java.util.Locale;
- import java.util.Map;
-
- public class BeanContextSupport extends BeanContextChildSupport implements BeanContext, Serializable, PropertyChangeListener, VetoableChangeListener {
- static final long serialVersionUID = -4879613978649577204L;
- protected transient HashMap children;
- private int serializable;
- protected transient ArrayList bcmListeners;
- protected Locale locale;
- protected boolean okToUseGui;
- protected boolean designTime;
- private transient PropertyChangeListener childPCL;
- private transient VetoableChangeListener childVCL;
- private transient boolean serializing;
-
- public BeanContextSupport(BeanContext var1, Locale var2, boolean var3, boolean var4) {
- super(var1);
- this.serializable = 0;
- this.locale = var2 != null ? var2 : Locale.getDefault();
- this.designTime = var3;
- this.okToUseGui = var4;
- this.initialize();
- }
-
- public BeanContextSupport(BeanContext var1, Locale var2, boolean var3) {
- this(var1, var2, var3, true);
- }
-
- public BeanContextSupport(BeanContext var1, Locale var2) {
- this(var1, var2, false, true);
- }
-
- public BeanContextSupport(BeanContext var1) {
- this(var1, (Locale)null, false, true);
- }
-
- public BeanContextSupport() {
- this((BeanContext)null, (Locale)null, false, true);
- }
-
- public BeanContext getBeanContextPeer() {
- return (BeanContext)((BeanContextChildSupport)this).getBeanContextChildPeer();
- }
-
- public Object instantiateChild(String var1) throws IOException, ClassNotFoundException {
- BeanContext var2 = this.getBeanContextPeer();
- return Beans.instantiate(var2.getClass().getClassLoader(), var1, var2);
- }
-
- public int size() {
- HashMap var1 = this.children;
- synchronized(var1) {
- int var2 = this.children.size();
- return var2;
- }
- }
-
- public boolean isEmpty() {
- HashMap var1 = this.children;
- synchronized(var1) {
- boolean var2 = this.children.isEmpty();
- return var2;
- }
- }
-
- public boolean contains(Object var1) {
- HashMap var2 = this.children;
- synchronized(var2) {
- boolean var3 = this.children.containsKey(var1);
- return var3;
- }
- }
-
- public boolean containsKey(Object var1) {
- HashMap var2 = this.children;
- synchronized(var2) {
- boolean var3 = this.children.containsKey(var1);
- return var3;
- }
- }
-
- public Iterator iterator() {
- HashMap var1 = this.children;
- synchronized(var1) {
- BCSIterator var2 = new BCSIterator(this.children.keySet().iterator());
- return var2;
- }
- }
-
- public Object[] toArray() {
- HashMap var1 = this.children;
- synchronized(var1) {
- Object[] var2 = this.children.keySet().toArray();
- return var2;
- }
- }
-
- public Object[] toArray(Object[] var1) {
- HashMap var2 = this.children;
- synchronized(var2) {
- Object[] var3 = this.children.keySet().toArray(var1);
- return var3;
- }
- }
-
- protected BCSChild createBCSChild(Object var1, Object var2) {
- return new BCSChild(this, var1, var2);
- }
-
- public boolean add(Object var1) {
- if (var1 == null) {
- throw new IllegalArgumentException();
- } else if (this.children.containsKey(var1)) {
- return false;
- } else {
- Object var2 = BeanContext.globalHierarchyLock;
- synchronized(var2) {
- if (this.children.containsKey(var1)) {
- boolean var3 = false;
- return var3;
- } else if (!this.validatePendingAdd(var1)) {
- throw new IllegalStateException();
- } else {
- BeanContextChild var4 = getChildBeanContextChild(var1);
- BeanContextChild var5 = null;
- synchronized(var1) {
- if (var1 instanceof BeanContextProxy) {
- var5 = ((BeanContextProxy)var1).getBeanContextProxy();
- if (var5 == null) {
- throw new NullPointerException("BeanContextPeer.getBeanContextProxy()");
- }
- }
-
- BCSChild var7 = this.createBCSChild(var1, var5);
- BCSChild var8 = null;
- HashMap var9 = this.children;
- synchronized(var9) {
- this.children.put(var1, var7);
- if (var5 != null) {
- this.children.put(var5, var8 = this.createBCSChild(var5, var1));
- }
- }
-
- if (var4 != null) {
- synchronized(var4) {
- try {
- var4.setBeanContext(this.getBeanContextPeer());
- } catch (PropertyVetoException var18) {
- HashMap var12 = this.children;
- synchronized(var12) {
- this.children.remove(var1);
- if (var5 != null) {
- this.children.remove(var5);
- }
- }
-
- throw new IllegalStateException();
- }
-
- var4.addPropertyChangeListener("beanContext", this.childPCL);
- var4.addVetoableChangeListener("beanContext", this.childVCL);
- }
- }
-
- Visibility var11 = getChildVisibility(var1);
- if (var11 != null) {
- if (this.okToUseGui) {
- var11.okToUseGui();
- } else {
- var11.dontUseGui();
- }
- }
-
- if (getChildSerializable(var1) != null) {
- ++this.serializable;
- }
-
- this.childJustAddedHook(var1, var7);
- if (var5 != null) {
- var11 = getChildVisibility(var5);
- if (var11 != null) {
- if (this.okToUseGui) {
- var11.okToUseGui();
- } else {
- var11.dontUseGui();
- }
- }
-
- if (getChildSerializable(var5) != null) {
- ++this.serializable;
- }
-
- this.childJustAddedHook(var5, var8);
- }
- }
-
- this.fireChildrenAdded(new BeanContextMembershipEvent(this.getBeanContextPeer(), var5 == null ? new Object[]{var1} : new Object[]{var1, var5}));
- return true;
- }
- }
- }
- }
-
- public boolean remove(Object var1) {
- return this.remove(var1, true);
- }
-
- protected boolean remove(Object var1, boolean var2) {
- if (var1 == null) {
- throw new IllegalArgumentException();
- } else {
- Object var3 = BeanContext.globalHierarchyLock;
- synchronized(var3) {
- if (!this.containsKey(var1)) {
- boolean var4 = false;
- return var4;
- } else if (!this.validatePendingRemove(var1)) {
- throw new IllegalStateException();
- } else {
- BCSChild var5 = (BCSChild)this.children.get(var1);
- BCSChild var6 = null;
- Object var7 = null;
- synchronized(var1) {
- if (var2) {
- BeanContextChild var9 = getChildBeanContextChild(var1);
- if (var9 != null) {
- synchronized(var9) {
- var9.removePropertyChangeListener("beanContext", this.childPCL);
- var9.removeVetoableChangeListener("beanContext", this.childVCL);
-
- try {
- var9.setBeanContext((BeanContext)null);
- } catch (PropertyVetoException var16) {
- var9.addPropertyChangeListener("beanContext", this.childPCL);
- var9.addVetoableChangeListener("beanContext", this.childVCL);
- throw new IllegalStateException();
- }
- }
- }
- }
-
- HashMap var21 = this.children;
- synchronized(var21) {
- this.children.remove(var1);
- if (var5.isProxyPeer()) {
- var6 = (BCSChild)this.children.get(var7 = var5.getProxyPeer());
- this.children.remove(var7);
- }
- }
-
- if (getChildSerializable(var1) != null) {
- --this.serializable;
- }
-
- this.childJustRemovedHook(var1, var5);
- if (var7 != null) {
- if (getChildSerializable(var7) != null) {
- --this.serializable;
- }
-
- this.childJustRemovedHook(var7, var6);
- }
- }
-
- this.fireChildrenRemoved(new BeanContextMembershipEvent(this.getBeanContextPeer(), var7 == null ? new Object[]{var1} : new Object[]{var1, var7}));
- return true;
- }
- }
- }
- }
-
- public boolean containsAll(Collection var1) {
- HashMap var2 = this.children;
- synchronized(var2) {
- Iterator var3 = var1.iterator();
-
- while(var3.hasNext()) {
- if (!this.contains(var3.next())) {
- boolean var4 = false;
- return var4;
- }
- }
-
- boolean var5 = true;
- return var5;
- }
- }
-
- public boolean addAll(Collection var1) {
- throw new UnsupportedOperationException();
- }
-
- public boolean removeAll(Collection var1) {
- throw new UnsupportedOperationException();
- }
-
- public boolean retainAll(Collection var1) {
- throw new UnsupportedOperationException();
- }
-
- public void clear() {
- throw new UnsupportedOperationException();
- }
-
- public void addBeanContextMembershipListener(BeanContextMembershipListener var1) {
- if (var1 == null) {
- throw new NullPointerException("listener");
- } else {
- ArrayList var2 = this.bcmListeners;
- synchronized(var2) {
- if (!this.bcmListeners.contains(var1)) {
- this.bcmListeners.add(var1);
- }
- }
- }
- }
-
- public void removeBeanContextMembershipListener(BeanContextMembershipListener var1) {
- if (var1 == null) {
- throw new NullPointerException("listener");
- } else {
- ArrayList var2 = this.bcmListeners;
- synchronized(var2) {
- if (this.bcmListeners.contains(var1)) {
- this.bcmListeners.remove(var1);
- }
- }
- }
- }
-
- public InputStream getResourceAsStream(String var1, BeanContextChild var2) {
- if (var1 == null) {
- throw new NullPointerException("name");
- } else if (var2 == null) {
- throw new NullPointerException("bcc");
- } else {
- HashMap var4 = this.children;
- boolean var3;
- synchronized(var4) {
- var3 = this.children.containsValue(var2);
- }
-
- if (var3) {
- ClassLoader var5 = var2.getClass().getClassLoader();
- return var5 != null ? var5.getResourceAsStream(var1) : ClassLoader.getSystemResourceAsStream(var1);
- } else {
- throw new IllegalArgumentException("Not a valid child");
- }
- }
- }
-
- public URL getResource(String var1, BeanContextChild var2) {
- if (var1 == null) {
- throw new NullPointerException("name");
- } else if (var2 == null) {
- throw new NullPointerException("bcc");
- } else {
- HashMap var4 = this.children;
- boolean var3;
- synchronized(var4) {
- var3 = this.children.containsValue(var2);
- }
-
- if (var3) {
- ClassLoader var5 = var2.getClass().getClassLoader();
- return var5 != null ? var5.getResource(var1) : ClassLoader.getSystemResource(var1);
- } else {
- throw new IllegalArgumentException("Not a valid child");
- }
- }
- }
-
- public synchronized void setDesignTime(boolean var1) {
- if (this.designTime != var1) {
- this.designTime = var1;
- ((BeanContextChildSupport)this).firePropertyChange("designMode", new Boolean(!var1), new Boolean(var1));
- }
-
- }
-
- public synchronized boolean isDesignTime() {
- return this.designTime;
- }
-
- public synchronized void setLocale(Locale var1) throws PropertyVetoException {
- if (this.locale != null && !this.locale.equals(var1) || var1 != null) {
- Locale var2 = this.locale;
- ((BeanContextChildSupport)this).fireVetoableChange("locale", var2, var1);
- this.locale = var1;
- ((BeanContextChildSupport)this).firePropertyChange("locale", var2, var1);
- }
-
- }
-
- public synchronized Locale getLocale() {
- return this.locale;
- }
-
- public synchronized boolean needsGui() {
- BeanContext var1 = this.getBeanContextPeer();
- if (var1 != this) {
- if (var1 instanceof Visibility) {
- return var1.needsGui();
- }
-
- if (var1 instanceof Container || var1 instanceof Component) {
- return true;
- }
- }
-
- HashMap var2 = this.children;
- synchronized(var2) {
- for(Object var4 : this.children.keySet()) {
- try {
- boolean var9 = ((Visibility)var4).needsGui();
- return var9;
- } catch (ClassCastException var7) {
- if (var4 instanceof Container || var4 instanceof Component) {
- boolean var5 = true;
- return var5;
- }
- }
- }
-
- return false;
- }
- }
-
- public synchronized void dontUseGui() {
- if (this.okToUseGui) {
- this.okToUseGui = false;
- HashMap var1 = this.children;
- synchronized(var1) {
- Iterator var2 = this.children.keySet().iterator();
-
- while(var2.hasNext()) {
- Visibility var3 = getChildVisibility(var2.next());
- if (var3 != null) {
- var3.dontUseGui();
- }
- }
- }
- }
-
- }
-
- public synchronized void okToUseGui() {
- if (!this.okToUseGui) {
- this.okToUseGui = true;
- HashMap var1 = this.children;
- synchronized(var1) {
- Iterator var2 = this.children.keySet().iterator();
-
- while(var2.hasNext()) {
- Visibility var3 = getChildVisibility(var2.next());
- if (var3 != null) {
- var3.okToUseGui();
- }
- }
- }
- }
-
- }
-
- public boolean avoidingGui() {
- return !this.okToUseGui && this.needsGui();
- }
-
- public boolean isSerializing() {
- return this.serializing;
- }
-
- protected Iterator bcsChildren() {
- HashMap var1 = this.children;
- synchronized(var1) {
- Iterator var2 = this.children.values().iterator();
- return var2;
- }
- }
-
- protected void bcsPreSerializationHook(ObjectOutputStream var1) throws IOException {
- }
-
- protected void bcsPreDeserializationHook(ObjectInputStream var1) throws IOException, ClassNotFoundException {
- }
-
- protected void childDeserializedHook(Object var1, BCSChild var2) {
- HashMap var3 = this.children;
- synchronized(var3) {
- this.children.put(var1, var2);
- }
- }
-
- protected final void serialize(ObjectOutputStream var1, Collection var2) throws IOException {
- int var3 = 0;
- Object[] var4 = var2.toArray();
-
- for(int var5 = 0; var5 < var4.length; ++var5) {
- if (var4[var5] instanceof Serializable) {
- ++var3;
- } else {
- var4[var5] = null;
- }
- }
-
- var1.writeInt(var3);
-
- for(int var6 = 0; var3 > 0; ++var6) {
- Object var7 = var4[var6];
- if (var7 != null) {
- var1.writeObject(var7);
- --var3;
- }
- }
-
- }
-
- protected final void deserialize(ObjectInputStream var1, Collection var2) throws IOException, ClassNotFoundException {
- int var3 = 0;
- var3 = var1.readInt();
-
- while(var3-- > 0) {
- var2.add(var1.readObject());
- }
-
- }
-
- public final void writeChildren(ObjectOutputStream var1) throws IOException {
- if (this.serializable > 0) {
- boolean var2 = this.serializing;
- this.serializing = true;
- int var3 = 0;
- HashMap var4 = this.children;
- synchronized(var4) {
- Iterator var5 = this.children.entrySet().iterator();
-
- while(var5.hasNext() && var3 < this.serializable) {
- Map.Entry var6 = (Map.Entry)var5.next();
- if (var6.getKey() instanceof Serializable) {
- try {
- var1.writeObject(var6.getKey());
- var1.writeObject(var6.getValue());
- } catch (IOException var9) {
- this.serializing = var2;
- throw var9;
- }
-
- ++var3;
- }
- }
- }
-
- this.serializing = var2;
- if (var3 != this.serializable) {
- throw new IOException("wrote different number of children than expected");
- }
- }
- }
-
- private synchronized void writeObject(ObjectOutputStream var1) throws IOException, ClassNotFoundException {
- this.serializing = true;
- Object var2 = BeanContext.globalHierarchyLock;
- synchronized(var2) {
- try {
- var1.defaultWriteObject();
- this.bcsPreSerializationHook(var1);
- if (this.serializable > 0 && this.equals(this.getBeanContextPeer())) {
- this.writeChildren(var1);
- }
-
- this.serialize(var1, this.bcmListeners);
- } finally {
- this.serializing = false;
- }
-
- }
- }
-
- public final void readChildren(ObjectInputStream var1) throws IOException, ClassNotFoundException {
- int var2 = this.serializable;
-
- while(var2-- > 0) {
- Object var3 = null;
- Object var4 = null;
-
- try {
- var3 = var1.readObject();
- var15 = (BCSChild)var1.readObject();
- } catch (IOException var12) {
- continue;
- } catch (ClassNotFoundException var13) {
- continue;
- }
-
- synchronized(var3) {
- BeanContextChild var6 = null;
-
- try {
- var6 = (BeanContextChild)var3;
- } catch (ClassCastException var9) {
- }
-
- if (var6 != null) {
- try {
- var6.setBeanContext(this.getBeanContextPeer());
- var6.addPropertyChangeListener("beanContext", this.childPCL);
- var6.addVetoableChangeListener("beanContext", this.childVCL);
- } catch (PropertyVetoException var10) {
- continue;
- }
- }
-
- this.childDeserializedHook(var3, var15);
- }
- }
-
- }
-
- private synchronized void readObject(ObjectInputStream var1) throws IOException, ClassNotFoundException {
- Object var2 = BeanContext.globalHierarchyLock;
- synchronized(var2) {
- var1.defaultReadObject();
- this.initialize();
- this.bcsPreDeserializationHook(var1);
- if (this.serializable > 0 && this.equals(this.getBeanContextPeer())) {
- this.readChildren(var1);
- }
-
- this.deserialize(var1, this.bcmListeners = new ArrayList(1));
- }
- }
-
- public void vetoableChange(PropertyChangeEvent var1) throws PropertyVetoException {
- String var2 = var1.getPropertyName();
- Object var3 = ((EventObject)var1).getSource();
- HashMap var4 = this.children;
- synchronized(var4) {
- if ("beanContext".equals(var2) && this.containsKey(var3) && !this.getBeanContextPeer().equals(var1.getNewValue())) {
- if (!this.validatePendingRemove(var3)) {
- throw new PropertyVetoException("current BeanContext vetoes setBeanContext()", var1);
- }
-
- ((BCSChild)this.children.get(var3)).setRemovePending(true);
- }
-
- }
- }
-
- public void propertyChange(PropertyChangeEvent var1) {
- String var2 = var1.getPropertyName();
- Object var3 = ((EventObject)var1).getSource();
- HashMap var4 = this.children;
- synchronized(var4) {
- if ("beanContext".equals(var2) && this.containsKey(var3) && ((BCSChild)this.children.get(var3)).isRemovePending()) {
- BeanContext var5 = this.getBeanContextPeer();
- if (var5.equals(var1.getOldValue()) && !var5.equals(var1.getNewValue())) {
- this.remove(var3, false);
- } else {
- ((BCSChild)this.children.get(var3)).setRemovePending(false);
- }
- }
-
- }
- }
-
- protected boolean validatePendingAdd(Object var1) {
- return true;
- }
-
- protected boolean validatePendingRemove(Object var1) {
- return true;
- }
-
- protected void childJustAddedHook(Object var1, BCSChild var2) {
- }
-
- protected void childJustRemovedHook(Object var1, BCSChild var2) {
- }
-
- protected static final Visibility getChildVisibility(Object var0) {
- try {
- return (Visibility)var0;
- } catch (ClassCastException var2) {
- return null;
- }
- }
-
- protected static final Serializable getChildSerializable(Object var0) {
- try {
- return (Serializable)var0;
- } catch (ClassCastException var2) {
- return null;
- }
- }
-
- protected static final PropertyChangeListener getChildPropertyChangeListener(Object var0) {
- try {
- return (PropertyChangeListener)var0;
- } catch (ClassCastException var2) {
- return null;
- }
- }
-
- protected static final VetoableChangeListener getChildVetoableChangeListener(Object var0) {
- try {
- return (VetoableChangeListener)var0;
- } catch (ClassCastException var2) {
- return null;
- }
- }
-
- protected static final BeanContextMembershipListener getChildBeanContextMembershipListener(Object var0) {
- try {
- return (BeanContextMembershipListener)var0;
- } catch (ClassCastException var2) {
- return null;
- }
- }
-
- protected static final BeanContextChild getChildBeanContextChild(Object var0) {
- try {
- BeanContextChild var1 = (BeanContextChild)var0;
- if (var0 instanceof BeanContextChild && var0 instanceof BeanContextProxy) {
- throw new IllegalArgumentException("child cannot implement both BeanContextChild and BeanContextProxy");
- } else {
- return var1;
- }
- } catch (ClassCastException var4) {
- try {
- return ((BeanContextProxy)var0).getBeanContextProxy();
- } catch (ClassCastException var3) {
- return null;
- }
- }
- }
-
- protected final void fireChildrenAdded(BeanContextMembershipEvent var1) {
- ArrayList var3 = this.bcmListeners;
- Object[] var2;
- synchronized(var3) {
- var2 = this.bcmListeners.toArray();
- }
-
- for(int var4 = 0; var4 < var2.length; ++var4) {
- ((BeanContextMembershipListener)var2[var4]).childrenAdded(var1);
- }
-
- }
-
- protected final void fireChildrenRemoved(BeanContextMembershipEvent var1) {
- ArrayList var3 = this.bcmListeners;
- Object[] var2;
- synchronized(var3) {
- var2 = this.bcmListeners.toArray();
- }
-
- for(int var4 = 0; var4 < var2.length; ++var4) {
- ((BeanContextMembershipListener)var2[var4]).childrenRemoved(var1);
- }
-
- }
-
- protected synchronized void initialize() {
- this.children = new HashMap(this.serializable + 1);
- this.bcmListeners = new ArrayList(1);
- this.childPCL = new 1(this);
- this.childVCL = new 2(this);
- }
-
- protected final Object[] copyChildren() {
- HashMap var1 = this.children;
- synchronized(var1) {
- Object[] var2 = this.children.keySet().toArray();
- return var2;
- }
- }
-
- protected static final boolean classEquals(Class var0, Class var1) {
- return var0.equals(var1) || var0.getName().equals(var1.getName());
- }
- }
-