⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 beancontextsupport.java

📁 JAVA基本类源代码,大家可以学习学习!
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
     * for adding then this method throws an IllegalStateException.     * @param targetChild The child objects to remove     * @see #validatePendingRemove     */    public boolean remove(Object targetChild) {	return remove(targetChild, true);    }    /**     * internal remove used when removal caused by      * unexpected <tt>setBeanContext</tt> or     * by <tt>remove()</tt> invocation.     * @param targetChild the JavaBean, BeanContext, or Object to be removed     * @param callChildSetBC used to indicate that      * the child should be notified that it is no      * longer nested in this <tt>BeanContext</tt>.     */    protected boolean remove(Object targetChild, boolean callChildSetBC) {	if (targetChild == null) throw new IllegalArgumentException();	synchronized(BeanContext.globalHierarchyLock) {	    if (!containsKey(targetChild)) return false;	    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	    synchronized(targetChild) {	        if (callChildSetBC) {	            BeanContextChild cbcc = getChildBeanContextChild(targetChild);	            if (cbcc != null) synchronized(cbcc) {	                cbcc.removePropertyChangeListener("beanContext", childPCL);	                cbcc.removeVetoableChangeListener("beanContext", childVCL);			try {	                    cbcc.setBeanContext(null);	                } catch (PropertyVetoException pve1) {	                    cbcc.addPropertyChangeListener("beanContext", childPCL);	                    cbcc.addVetoableChangeListener("beanContext", childVCL);	    	            throw new IllegalStateException();	                }		    }	        }	        synchronized (children) {		    children.remove(targetChild);		    if (bcsc.isProxyPeer()) {			pbcsc = (BCSChild)children.get(peer = bcsc.getProxyPeer());			children.remove(peer);		    }		}	        if (getChildSerializable(targetChild) != null) serializable--;	        childJustRemovedHook(targetChild, bcsc);		if (peer != null) {	            if (getChildSerializable(peer) != null) serializable--;	            childJustRemovedHook(peer, pbcsc);		}	    }	    fireChildrenRemoved(new BeanContextMembershipEvent(getBeanContextPeer(), peer == null ? new Object[] { targetChild } : new Object[] { targetChild, peer } ));	}	return true;    }    /**     * Tests to see if all objects in the     * specified <tt>Collection</tt> are children of     * this <tt>BeanContext</tt>.     * @param c the specified <tt>Collection</tt>      *      * @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;	}    }    /**     * add Collection to set of Children (Unsupported)     * implementations must synchronized on the hierarchy lock and "children" protected field     * @throws UnsupportedOperationException     */    public boolean addAll(Collection c) {	throw new UnsupportedOperationException();    }    /**     * remove all specified children (Unsupported)     * implementations must synchronized on the hierarchy lock and "children" protected field     * @throws UnsupportedOperationException     */    public boolean removeAll(Collection c) {	throw new UnsupportedOperationException();    }    /**     * retain only specified children (Unsupported)     * implementations must synchronized on the hierarchy lock and "children" protected field     * @throws UnsupportedOperationException     */    public boolean retainAll(Collection c) {	throw new UnsupportedOperationException();    }    /**     * clear the children (Unsupported)     * implementations must synchronized on the hierarchy lock and "children" protected field     * @throws UnsupportedOperationException     */    public void clear() {	throw new UnsupportedOperationException();    }    /**     * Adds a BeanContextMembershipListener     *     * @param  bcml the BeanContextMembershipListener to add     * @throws NullPointerException     */    public void addBeanContextMembershipListener(BeanContextMembershipListener bcml) {	if (bcml == null) throw new NullPointerException("listener");	synchronized(bcmListeners) {	    if (bcmListeners.contains(bcml))		return;	    else	        bcmListeners.add(bcml);	}    }    /**     * Removes a BeanContextMembershipListener     *     * @param  bcml the BeanContextMembershipListener to remove     * @throws NullPointerException     */    public void removeBeanContextMembershipListener(BeanContextMembershipListener bcml) {	if (bcml == null) throw new NullPointerException("listener");	synchronized(bcmListeners) {	    if (!bcmListeners.contains(bcml))		return;	    else	        bcmListeners.remove(bcml);	}    }    /**     * @param name the name of the resource requested.     * @param bcc  the child object making the request.     *     * @return  the requested resource as an InputStream     * @throws  NullPointerException     */    public InputStream getResourceAsStream(String name, BeanContextChild bcc) {	if (name == null) throw new NullPointerException("name");	if (bcc  == null) throw new NullPointerException("bcc");	if (containsKey(bcc)) {	    ClassLoader cl = bcc.getClass().getClassLoader();	    return cl != null ? cl.getResourceAsStream(name)			      : ClassLoader.getSystemResourceAsStream(name);	} else throw new IllegalArgumentException("Not a valid child");    }    /**     * @param name the name of the resource requested.     * @param bcc  the child object making the request.     *     * @return the requested resource as an InputStream     */    public URL getResource(String name, BeanContextChild bcc) {	if (name == null) throw new NullPointerException("name");	if (bcc  == null) throw new NullPointerException("bcc");	if (containsKey(bcc)) {	    ClassLoader cl = bcc.getClass().getClassLoader();	    return cl != null ? cl.getResource(name)			      : ClassLoader.getSystemResource(name);	} else throw new IllegalArgumentException("Not a valid child");    }    /**     * Sets the new design time value for this <tt>BeanContext</tt>.     * @param dTime the new designTime value     */    public synchronized void setDesignTime(boolean dTime) {	if (designTime != dTime) {	    designTime = dTime;	    firePropertyChange("designMode", Boolean.valueOf(!dTime), Boolean.valueOf(dTime));	}    }      /**     * Reports whether or not this object is in     * currently in design time mode.     * @return <tt>true</tt> if in design time mode,      * <tt>false</tt> if not     */    public synchronized boolean isDesignTime() { return designTime; }    /**     * Sets the locale of this BeanContext.     * @param newLocale the new locale. This method call will have     *        no effect if newLocale is <CODE>null</CODE>.     * @throws PropertyVetoException if the new value is rejected     */    public synchronized void setLocale(Locale newLocale) throws PropertyVetoException {	if ((locale != null && !locale.equals(newLocale)) || newLocale != null) {	    Locale old = locale;	    fireVetoableChange("locale", old, newLocale); // throws	    locale = newLocale;	    firePropertyChange("locale", old, newLocale);	}    }    /**     * Gets the locale for this <tt>BeanContext</tt>.     *     * @return the current Locale of the <tt>BeanContext</tt>     */    public synchronized Locale getLocale() { return locale; }    /**     * <p>     * This method is typically called from the environment in order to determine     * if the implementor "needs" a GUI.     * </p>     * <p>     * The algorithm used herein tests the BeanContextPeer, and its current children     * to determine if they are either Containers, Components, or if they implement     * Visibility and return needsGui() == true.     * </p>     * @return <tt>true</tt> if the implementor needs a GUI     */    public synchronized boolean needsGui() {	BeanContext bc = getBeanContextPeer();	if (bc != this) {	    if (bc instanceof Visibility) return ((Visibility)bc).needsGui();	    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) {		        // do nothing ...		    }		    if (c instanceof Container || c instanceof Component)		        return true;	    }	}	return false;    }    /**     * notify this instance that it may no longer render a GUI.     */    public synchronized void dontUseGui() {	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();	       }	    }	}    }    /**     * Notify this instance that it may now render a GUI     */    public synchronized void okToUseGui() {	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();	        }	    }	}    }    /**     * Used to determine if the <tt>BeanContext</tt>      * child is avoiding using its GUI.     * @return is this instance avoiding using its GUI?     * @see Visibility     */    public boolean avoidingGui() {	return !okToUseGui && needsGui();    }    /**     * Is this <tt>BeanContext</tt> in the      * process of being serialized?     * @return if this <tt>BeanContext</tt> is      * currently being serialized     */    public boolean isSerializing() { return serializing; }    /**     * 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.     *     * This method may be overridden by subclasses to perform custom     * serialization of their state prior to this superclass serializing     * the children.     *     * This method should not however be used by subclasses to replace their     * own implementation (if any) of writeObject().     */    protected void bcsPreSerializationHook(ObjectOutputStream oos) throws IOException {    }    /**     * called by readObject after defaultReadObject() but prior to     * deserialization of any children.     *     * This method may be overridden by subclasses to perform custom     * deserialization of their state prior to this superclass deserializing     * the children.     *     * This method should not however be used by subclasses to replace their     * own implementation (if any) of readObject().     */    protected void bcsPreDeserializationHook(ObjectInputStream ois) throws IOException, ClassNotFoundException {    }    /**     * Called by readObject with the newly deserialized child and BCSChild.     * @param child the newly deserialized child     * @param bcsc the newly deserialized BCSChild     */    protected void childDeserializedHook(Object child, BCSChild bcsc) {	synchronized(children) {	    children.put(child, bcsc);	}    }    /**     * Used by writeObject to serialize a Collection.     * @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)		count++;	    else		objects[i] = null;	}        oos.writeInt(count); // number of subsequent objects	for (int i = 0; count > 0; i++) {	    Object o = objects[i];	    if (o != null) {		oos.writeObject(o);		count--;	    }	}    }    /**     * used by readObject to deserialize a collection.     * @param ois the ObjectInputStream to use     * @param coll the Collection     */    protected final void deserialize(ObjectInputStream ois, Collection coll) throws IOException, ClassNotFoundException {	int count = 0;	count = ois.readInt();	while (count-- > 0) {	    coll.add(ois.readObject());	}    }    /**      * Used to serialize all children of      * this <tt>BeanContext</tt>.     * @param oos the <tt>ObjectOutputStream</tt>      * to use during serialization     * @throws IOException if serialization failed     */    public final void writeChildren(ObjectOutputStream oos) throws IOException {	if (serializable <= 0) return;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -