src/share/classes/java/beans/beancontext/BeanContextSupport.java
Print this page
*** 252,262 ****
/**
* Gets all JavaBean or <tt>BeanContext</tt> instances
* currently nested in this <tt>BeanContext</tt>.
* @return an <tt>Iterator</tt> of the nested children
*/
! public Iterator iterator() {
synchronized(children) {
return new BCSIterator(children.keySet().iterator());
}
}
--- 252,262 ----
/**
* Gets all JavaBean or <tt>BeanContext</tt> instances
* currently nested in this <tt>BeanContext</tt>.
* @return an <tt>Iterator</tt> of the nested children
*/
! public Iterator<Object> iterator() {
synchronized(children) {
return new BCSIterator(children.keySet().iterator());
}
}
*** 290,307 ****
/**
* protected final subclass that encapsulates an iterator but implements
* a noop remove() method.
*/
! protected static final class BCSIterator implements Iterator {
! BCSIterator(Iterator i) { super(); src = i; }
public boolean hasNext() { return src.hasNext(); }
public Object next() { return src.next(); }
public void remove() { /* do nothing */ }
! private Iterator src;
}
/************************************************************************/
/*
--- 290,307 ----
/**
* protected final subclass that encapsulates an iterator but implements
* a noop remove() method.
*/
! protected static final class BCSIterator implements Iterator<Object> {
! BCSIterator(Iterator<?> i) { super(); src = i; }
public boolean hasNext() { return src.hasNext(); }
public Object next() { return src.next(); }
public void remove() { /* do nothing */ }
! private Iterator<?> src;
}
/************************************************************************/
/*
*** 502,512 ****
if (!validatePendingRemove(targetChild)) {
throw new IllegalStateException();
}
! BCSChild bcsc = (BCSChild)children.get(targetChild);
BCSChild pbcsc = null;
Object peer = null;
// we are required to notify the child that it is no longer nested here if
// it implements java.beans.beancontext.BeanContextChild
--- 502,512 ----
if (!validatePendingRemove(targetChild)) {
throw new IllegalStateException();
}
! BCSChild bcsc = children.get(targetChild);
BCSChild pbcsc = null;
Object peer = null;
// we are required to notify the child that it is no longer nested here if
// it implements java.beans.beancontext.BeanContextChild
*** 531,541 ****
synchronized (children) {
children.remove(targetChild);
if (bcsc.isProxyPeer()) {
! pbcsc = (BCSChild)children.get(peer = bcsc.getProxyPeer());
children.remove(peer);
}
}
if (getChildSerializable(targetChild) != null) serializable--;
--- 531,541 ----
synchronized (children) {
children.remove(targetChild);
if (bcsc.isProxyPeer()) {
! pbcsc = children.get(peer = bcsc.getProxyPeer());
children.remove(peer);
}
}
if (getChildSerializable(targetChild) != null) serializable--;
*** 564,576 ****
*
* @return <tt>true</tt> if all objects
* in the collection are children of
* this <tt>BeanContext</tt>, false if not.
*/
public boolean containsAll(Collection c) {
synchronized(children) {
! Iterator i = c.iterator();
while (i.hasNext())
if(!contains(i.next()))
return false;
return true;
--- 564,577 ----
*
* @return <tt>true</tt> if all objects
* in the collection are children of
* this <tt>BeanContext</tt>, false if not.
*/
+ @SuppressWarnings("rawtypes")
public boolean containsAll(Collection c) {
synchronized(children) {
! Iterator<?> i = c.iterator();
while (i.hasNext())
if(!contains(i.next()))
return false;
return true;
*** 581,590 ****
--- 582,592 ----
* add Collection to set of Children (Unsupported)
* implementations must synchronized on the hierarchy lock and "children" protected field
* @throws UnsupportedOperationException thrown unconditionally by this implementation
* @return this implementation unconditionally throws {@code UnsupportedOperationException}
*/
+ @SuppressWarnings("rawtypes")
public boolean addAll(Collection c) {
throw new UnsupportedOperationException();
}
/**
*** 592,601 ****
--- 594,604 ----
* implementations must synchronized on the hierarchy lock and "children" protected field
* @throws UnsupportedOperationException thrown unconditionally by this implementation
* @return this implementation unconditionally throws {@code UnsupportedOperationException}
*/
+ @SuppressWarnings("rawtypes")
public boolean removeAll(Collection c) {
throw new UnsupportedOperationException();
}
*** 603,612 ****
--- 606,616 ----
* retain only specified children (Unsupported)
* implementations must synchronized on the hierarchy lock and "children" protected field
* @throws UnsupportedOperationException thrown unconditionally by this implementation
* @return this implementation unconditionally throws {@code UnsupportedOperationException}
*/
+ @SuppressWarnings("rawtypes")
public boolean retainAll(Collection c) {
throw new UnsupportedOperationException();
}
/**
*** 761,771 ****
if (bc instanceof Container || bc instanceof Component)
return true;
}
synchronized(children) {
! for (Iterator i = children.keySet().iterator(); i.hasNext();) {
Object c = i.next();
try {
return ((Visibility)c).needsGui();
} catch (ClassCastException cce) {
--- 765,775 ----
if (bc instanceof Container || bc instanceof Component)
return true;
}
synchronized(children) {
! for (Iterator<Object> i = children.keySet().iterator(); i.hasNext();) {
Object c = i.next();
try {
return ((Visibility)c).needsGui();
} catch (ClassCastException cce) {
*** 788,798 ****
if (okToUseGui) {
okToUseGui = false;
// lets also tell the Children that can that they may not use their GUI's
synchronized(children) {
! for (Iterator i = children.keySet().iterator(); i.hasNext();) {
Visibility v = getChildVisibility(i.next());
if (v != null) v.dontUseGui();
}
}
--- 792,802 ----
if (okToUseGui) {
okToUseGui = false;
// lets also tell the Children that can that they may not use their GUI's
synchronized(children) {
! for (Iterator<Object> i = children.keySet().iterator(); i.hasNext();) {
Visibility v = getChildVisibility(i.next());
if (v != null) v.dontUseGui();
}
}
*** 807,817 ****
if (!okToUseGui) {
okToUseGui = true;
// lets also tell the Children that can that they may use their GUI's
synchronized(children) {
! for (Iterator i = children.keySet().iterator(); i.hasNext();) {
Visibility v = getChildVisibility(i.next());
if (v != null) v.okToUseGui();
}
}
--- 811,821 ----
if (!okToUseGui) {
okToUseGui = true;
// lets also tell the Children that can that they may use their GUI's
synchronized(children) {
! for (Iterator<Object> i = children.keySet().iterator(); i.hasNext();) {
Visibility v = getChildVisibility(i.next());
if (v != null) v.okToUseGui();
}
}
*** 839,849 ****
/**
* Returns an iterator of all children
* of this <tt>BeanContext</tt>.
* @return an iterator for all the current BCSChild values
*/
! protected Iterator bcsChildren() { synchronized(children) { return children.values().iterator(); } }
/**
* called by writeObject after defaultWriteObject() but prior to
* serialization of currently serializable children.
*
--- 843,853 ----
/**
* Returns an iterator of all children
* of this <tt>BeanContext</tt>.
* @return an iterator for all the current BCSChild values
*/
! protected Iterator<BCSChild> bcsChildren() { synchronized(children) { return children.values().iterator(); } }
/**
* called by writeObject after defaultWriteObject() but prior to
* serialization of currently serializable children.
*
*** 894,904 ****
* @param oos the <tt>ObjectOutputStream</tt>
* to use during serialization
* @param coll the <tt>Collection</tt> to serialize
* @throws IOException if serialization failed
*/
! protected final void serialize(ObjectOutputStream oos, Collection coll) throws IOException {
int count = 0;
Object[] objects = coll.toArray();
for (int i = 0; i < objects.length; i++) {
if (objects[i] instanceof Serializable)
--- 898,908 ----
* @param oos the <tt>ObjectOutputStream</tt>
* to use during serialization
* @param coll the <tt>Collection</tt> to serialize
* @throws IOException if serialization failed
*/
! protected final void serialize(ObjectOutputStream oos, Collection<?> coll) throws IOException {
int count = 0;
Object[] objects = coll.toArray();
for (int i = 0; i < objects.length; i++) {
if (objects[i] instanceof Serializable)
*** 924,933 ****
--- 928,938 ----
* @param ois the ObjectInputStream to use
* @param coll the Collection
* @throws IOException if deserialization failed
* @throws ClassNotFoundException if needed classes are not found
*/
+ @SuppressWarnings({"rawtypes", "unchecked"})
protected final void deserialize(ObjectInputStream ois, Collection coll) throws IOException, ClassNotFoundException {
int count = 0;
count = ois.readInt();
*** 951,964 ****
serializing = true;
int count = 0;
synchronized(children) {
! Iterator i = children.entrySet().iterator();
while (i.hasNext() && count < serializable) {
! Map.Entry entry = (Map.Entry)i.next();
if (entry.getKey() instanceof Serializable) {
try {
oos.writeObject(entry.getKey()); // child
oos.writeObject(entry.getValue()); // BCSChild
--- 956,969 ----
serializing = true;
int count = 0;
synchronized(children) {
! Iterator<Map.Entry<Object, BCSChild>> i = children.entrySet().iterator();
while (i.hasNext() && count < serializable) {
! Map.Entry<Object, BCSChild> entry = i.next();
if (entry.getKey() instanceof Serializable) {
try {
oos.writeObject(entry.getKey()); // child
oos.writeObject(entry.getValue()); // BCSChild
*** 1080,1090 ****
bcsPreDeserializationHook(ois);
if (serializable > 0 && this.equals(getBeanContextPeer()))
readChildren(ois);
! deserialize(ois, bcmListeners = new ArrayList(1));
}
}
/**
* subclasses may envelope to monitor veto child property changes.
--- 1085,1095 ----
bcsPreDeserializationHook(ois);
if (serializable > 0 && this.equals(getBeanContextPeer()))
readChildren(ois);
! deserialize(ois, bcmListeners = new ArrayList<>(1));
}
}
/**
* subclasses may envelope to monitor veto child property changes.
*** 1099,1109 ****
containsKey(source) &&
!getBeanContextPeer().equals(pce.getNewValue())
) {
if (!validatePendingRemove(source)) {
throw new PropertyVetoException("current BeanContext vetoes setBeanContext()", pce);
! } else ((BCSChild)children.get(source)).setRemovePending(true);
}
}
}
/**
--- 1104,1114 ----
containsKey(source) &&
!getBeanContextPeer().equals(pce.getNewValue())
) {
if (!validatePendingRemove(source)) {
throw new PropertyVetoException("current BeanContext vetoes setBeanContext()", pce);
! } else children.get(source).setRemovePending(true);
}
}
}
/**
*** 1115,1131 ****
Object source = pce.getSource();
synchronized(children) {
if ("beanContext".equals(propertyName) &&
containsKey(source) &&
! ((BCSChild)children.get(source)).isRemovePending()) {
BeanContext bc = getBeanContextPeer();
if (bc.equals(pce.getOldValue()) && !bc.equals(pce.getNewValue())) {
remove(source, false);
} else {
! ((BCSChild)children.get(source)).setRemovePending(false);
}
}
}
}
--- 1120,1136 ----
Object source = pce.getSource();
synchronized(children) {
if ("beanContext".equals(propertyName) &&
containsKey(source) &&
! children.get(source).isRemovePending()) {
BeanContext bc = getBeanContextPeer();
if (bc.equals(pce.getOldValue()) && !bc.equals(pce.getNewValue())) {
remove(source, false);
} else {
! children.get(source).setRemovePending(false);
}
}
}
}
*** 1310,1321 ****
* subclasses may envelope this method to add their own initialization
* behavior
*/
protected synchronized void initialize() {
! children = new HashMap(serializable + 1);
! bcmListeners = new ArrayList(1);
childPCL = new PropertyChangeListener() {
/*
* this adaptor is used by the BeanContextSupport class to forward
--- 1315,1326 ----
* subclasses may envelope this method to add their own initialization
* behavior
*/
protected synchronized void initialize() {
! children = new HashMap<>(serializable + 1);
! bcmListeners = new ArrayList<>(1);
childPCL = new PropertyChangeListener() {
/*
* this adaptor is used by the BeanContextSupport class to forward
*** 1357,1367 ****
* or their names are equal.
* @param first the first object
* @param second the second object
* @return true if equal, false if not
*/
! protected static final boolean classEquals(Class first, Class second) {
return first.equals(second) || first.getName().equals(second.getName());
}
/*
--- 1362,1372 ----
* or their names are equal.
* @param first the first object
* @param second the second object
* @return true if equal, false if not
*/
! protected static final boolean classEquals(Class<?> first, Class<?> second) {
return first.equals(second) || first.getName().equals(second.getName());
}
/*
*** 1371,1389 ****
/**
* all accesses to the <code> protected HashMap children </code> field
* shall be synchronized on that object.
*/
! protected transient HashMap children;
private int serializable = 0; // children serializable
/**
* all accesses to the <code> protected ArrayList bcmListeners </code> field
* shall be synchronized on that object.
*/
! protected transient ArrayList bcmListeners;
//
/**
* The current locale of this BeanContext.
--- 1376,1394 ----
/**
* all accesses to the <code> protected HashMap children </code> field
* shall be synchronized on that object.
*/
! protected transient HashMap<Object, BCSChild> children;
private int serializable = 0; // children serializable
/**
* all accesses to the <code> protected ArrayList bcmListeners </code> field
* shall be synchronized on that object.
*/
! protected transient ArrayList<BeanContextMembershipListener> bcmListeners;
//
/**
* The current locale of this BeanContext.