Class BeanContextSupport

    • Field Detail

      • bcmListeners

        protected transient java.util.ArrayList bcmListeners
        A list of registered membership listeners. All access to this object should be synchronized on itself.
      • children

        protected transient java.util.HashMap children
        A map of children - key is child instance, value is BCSChild instance. All access to this object should be synchronized on itself.
      • locale

        protected java.util.Locale locale
        The locale of this context.
      • okToUseGui

        protected boolean okToUseGui
        A flag indicating whether this context is allowed to use GUI.
      • designTime

        protected boolean designTime
        A flag indicating whether this context is in design mode.
    • Constructor Detail

      • BeanContextSupport

        public BeanContextSupport()
        Constructs a standload BeanContextSupport.
      • BeanContextSupport

        public BeanContextSupport​(BeanContext peer)
        Constructs a BeanContextSupport which is a delegate of the given peer.
        Parameters:
        peer - the peer of this context
      • BeanContextSupport

        public BeanContextSupport​(BeanContext peer,
                                  java.util.Locale locale)
        Constructs a BeanContextSupport which is a delegate of the given peer.
        Parameters:
        peer - the peer of this context
        locale - the locale of this context
      • BeanContextSupport

        public BeanContextSupport​(BeanContext peer,
                                  java.util.Locale locale,
                                  boolean designTime)
        Constructs a BeanContextSupport which is a delegate of the given peer.
        Parameters:
        peer - the peer of this context
        locale - the locale of this context
        designTime - whether in design mode or not
      • BeanContextSupport

        public BeanContextSupport​(BeanContext peer,
                                  java.util.Locale locale,
                                  boolean designTime,
                                  boolean okToUseGui)
        Constructs a BeanContextSupport which is a delegate of the given peer.
        Parameters:
        peer - the peer of this context
        locale - the locale of this context
        designTime - whether in design mode or not
        okToUseGui - whether GUI is usable or not
    • Method Detail

      • add

        public boolean add​(java.lang.Object child)
        Add a child to this context. validatePendingAdd(). If the add is valid, the child and its proxy (if the child implements BeanContextProxy) is then added, and setBeanContext() is called on it (if the child implements BeanContextChild or it has a proxy). Last, the childJustAddedHook() is called and all registered BeanContextMembershipListeners are notified.
        Specified by:
        add in interface java.util.Collection
        Parameters:
        child - the child to add
        Returns:
        true if the child is added to this context; otherwise false
        Throws:
        java.lang.IllegalStateException - if the child is not valid to add
        See Also:
        Collection.add(java.lang.Object)
      • addAll

        public boolean addAll​(java.util.Collection collection)
        This method is unsupported, throws UnsupportedOperationException.
        Specified by:
        addAll in interface java.util.Collection
        See Also:
        Collection.addAll(java.util.Collection)
      • bcsChildren

        protected java.util.Iterator bcsChildren()
        Returns an iterator of all BCSChild instances, with remove() disabled.
        Returns:
        an iterator of all BCSChild instances
      • bcsPreDeserializationHook

        protected void bcsPreDeserializationHook​(java.io.ObjectInputStream ois)
                                          throws java.io.IOException,
                                                 java.lang.ClassNotFoundException
        This method is called by readObject() after defaultReadObject() and before deserializing any children or listeners. Subclass can insert its specific deserialization behavior by overrideing this method.
        Parameters:
        ois - the object input stream
        Throws:
        java.io.IOException
        java.lang.ClassNotFoundException
      • bcsPreSerializationHook

        protected void bcsPreSerializationHook​(java.io.ObjectOutputStream oos)
                                        throws java.io.IOException
        This method is called by writeObject() after defaultWriteObject() and before serializing any children or listeners. Subclass can insert its specific serialization behavior by overrideing this method.
        Parameters:
        oos - the object output stream
        Throws:
        java.io.IOException
      • childDeserializedHook

        protected void childDeserializedHook​(java.lang.Object child,
                                             BeanContextSupport.BCSChild bcsChild)
        This method is called during deserialization everytime a child is read.
        Parameters:
        child - the child just deserialized
        bcsChild - the BCSChild just deserialized
      • childJustAddedHook

        protected void childJustAddedHook​(java.lang.Object child,
                                          BeanContextSupport.BCSChild bcsChild)
        This method is called everytime a child is added to this context. This method is called with child synchronized.
        Parameters:
        child - the child just added
        bcsChild - the BCSChild just added
      • childJustRemovedHook

        protected void childJustRemovedHook​(java.lang.Object child,
                                            BeanContextSupport.BCSChild bcsChild)
        This method is called everytime a child is removed from this context. This method is called with child synchronized.
        Parameters:
        child - the child just removed
        bcsChild - the BCSChild just removed
      • classEquals

        protected static final boolean classEquals​(java.lang.Class clz1,
                                                   java.lang.Class clz2)
        Compares if two classes are equal or their class names are equal.
        Parameters:
        clz1 - a class
        clz2 - another class
        Returns:
        true if two class objects are equal or their class names are equal.
      • clear

        public void clear()
        This method is unsupported, throws UnsupportedOperationException.
        Specified by:
        clear in interface java.util.Collection
        See Also:
        Collection.clear()
      • contains

        public boolean contains​(java.lang.Object child)
        Returns true if the given object is a child of this context.
        Specified by:
        contains in interface java.util.Collection
        Parameters:
        child - the object to test
        Returns:
        true if the given object is a child of this context
        See Also:
        Collection.contains(java.lang.Object)
      • containsAll

        public boolean containsAll​(java.util.Collection collection)
        Returns true if given objects are children of this context.
        Specified by:
        containsAll in interface java.util.Collection
        Parameters:
        collection - a collection of objects
        Returns:
        true if given objects are children of this context
        See Also:
        Collection.containsAll(java.util.Collection)
      • containsKey

        public boolean containsKey​(java.lang.Object child)
        Returns true if the given object is a child of this context.
        Parameters:
        child - the object to test
        Returns:
        true if the given object is a child of this context
      • copyChildren

        protected final java.lang.Object[] copyChildren()
        Returns an array containing all children of this context.
        Returns:
        an array containing all children of this context
      • createBCSChild

        protected BeanContextSupport.BCSChild createBCSChild​(java.lang.Object child,
                                                             java.lang.Object proxyPeer)
        Creates a BCSChild object to company the given child.
        Parameters:
        child - the child
        proxyPeer - the proxy peer of the child if there is one
        Returns:
        a BCSChild object to company the given child
      • deserialize

        protected final void deserialize​(java.io.ObjectInputStream ois,
                                         java.util.Collection collection)
                                  throws java.io.IOException,
                                         java.lang.ClassNotFoundException
        Deserialize a collection. int indicating of number of rest objects, then read the objects one by one.
        Parameters:
        ois - the stream where the collection is read from
        collection - the collection to hold read objects
        Throws:
        java.io.IOException - if I/O exception occurs
        java.lang.ClassNotFoundException - if class of any read object is not found
      • fireChildrenAdded

        protected final void fireChildrenAdded​(BeanContextMembershipEvent event)
        Notifies registered BeanContextMembershipListeners that a new child has been added.
        Parameters:
        event - the BeanContextMembershipEvent
      • fireChildrenRemoved

        protected final void fireChildrenRemoved​(BeanContextMembershipEvent event)
        Notifies registered BeanContextMembershipListeners that a child has been removed.
        Parameters:
        event - the BeanContextMembershipEvent
      • getBeanContextPeer

        public BeanContext getBeanContextPeer()
        Returns the peer of this context casted as BeanContext.
        Returns:
        the peer of this context casted as BeanContext
      • getChildBeanContextChild

        protected static final BeanContextChild getChildBeanContextChild​(java.lang.Object child)
        Returns the BeanContextChild related with the given child. BeanContextChild, it is returned. If the child implements BeanContextProxy, the proxy is returned. Otherwise, null is returned.
        Parameters:
        child - a child
        Returns:
        the BeanContextChild related with the given child
        Throws:
        java.lang.IllegalStateException - if the child implements both BeanContextChild and BeanContextProxy
      • getChildBeanContextMembershipListener

        protected static final BeanContextMembershipListener getChildBeanContextMembershipListener​(java.lang.Object child)
        Returns the given child casted to BeanContextMembershipListener, or null if it does not implements the interface.
        Parameters:
        child - a child
        Returns:
        the given child casted to BeanContextMembershipListener, or null if it does not implements the interface
      • getChildPropertyChangeListener

        protected static final PropertyChangeListener getChildPropertyChangeListener​(java.lang.Object child)
        Returns the given child casted to PropertyChangeListener, or null if it does not implements the interface.
        Parameters:
        child - a child
        Returns:
        the given child casted to PropertyChangeListener, or null if it does not implements the interface
      • getChildSerializable

        protected static final java.io.Serializable getChildSerializable​(java.lang.Object child)
        Returns the given child casted to Serializable, or null if it does not implements the interface.
        Parameters:
        child - a child
        Returns:
        the given child casted to Serializable, or null if it does not implements the interface
      • getChildVetoableChangeListener

        protected static final VetoableChangeListener getChildVetoableChangeListener​(java.lang.Object child)
        Returns the given child casted to VetoableChangeListener, or null if it does not implements the interface.
        Parameters:
        child - a child
        Returns:
        the given child casted to VetoableChangeListener, or null if it does not implements the interface
      • getChildVisibility

        protected static final Visibility getChildVisibility​(java.lang.Object child)
        Returns the given child casted to Visibility, or null if it does not implements the interface.
        Parameters:
        child - a child
        Returns:
        the given child casted to Visibility, or null if it does not implements the interface
      • getLocale

        public java.util.Locale getLocale()
        Returns the locale of this context.
        Returns:
        the locale of this context
      • getResourceAsStream

        public java.io.InputStream getResourceAsStream​(java.lang.String resourceName,
                                                       BeanContextChild child)
                                                throws java.lang.IllegalArgumentException
        Specified by:
        getResourceAsStream in interface BeanContext
        Throws:
        java.lang.IllegalArgumentException
      • initialize

        protected void initialize()
        Initializes all transient fields of this instance, called by constructors and readObject().
      • instantiateChild

        public java.lang.Object instantiateChild​(java.lang.String beanName)
                                          throws java.io.IOException,
                                                 java.lang.ClassNotFoundException
        Specified by:
        instantiateChild in interface BeanContext
        Throws:
        java.io.IOException
        java.lang.ClassNotFoundException
      • isEmpty

        public boolean isEmpty()
        Specified by:
        isEmpty in interface java.util.Collection
      • isSerializing

        public boolean isSerializing()
        Returns true if this context is currently being serialized (by another thread).
        Returns:
        true if this context is currently being serialized (by another thread)
      • iterator

        public java.util.Iterator iterator()
        Returns an iterator of children of this context, with remove() disabled.
        Specified by:
        iterator in interface java.util.Collection
        Specified by:
        iterator in interface java.lang.Iterable
        See Also:
        Collection.iterator()
      • needsGui

        public boolean needsGui()
        Returns true if this context or its children needs GUI to work properly. Visibility to see if any of their needsGui() returns true, and if any of the children extends java.awt.Component.
        Specified by:
        needsGui in interface Visibility
        See Also:
        Visibility.needsGui()
      • readChildren

        public final void readChildren​(java.io.ObjectInputStream ois)
                                throws java.io.IOException,
                                       java.lang.ClassNotFoundException
        Deserializes children from the given object input stream. BCSChild object according to serializable property. For each pair, it is added to the children map and the childDeserializedHook() is called. If the child implements BeanContextChild, its setBeanContext() is also called. readObject() if the context works standalone. Or if this support object is a delegate of another BeanContext implementation, then this method should be called by the peer. Doing this means that derialization can proceed without any circular dependency problems.
        Parameters:
        ois - the object input stream
        Throws:
        java.io.IOException - if I/O exception occurs
        java.lang.ClassNotFoundException - if class of read object is not found
      • remove

        public boolean remove​(java.lang.Object child)
        Removes the given child from this context. remove(child, true).
        Specified by:
        remove in interface java.util.Collection
        Parameters:
        child - a child of this context
        Returns:
        true if the child is removed; or false if it is not a child of this context
        Throws:
        java.lang.IllegalArgumentException - if the child is null
        java.lang.IllegalStateException - if the child is not valid to remove
        See Also:
        Collection.remove(java.lang.Object)
      • remove

        protected boolean remove​(java.lang.Object child,
                                 boolean setChildBC)
        Removes the given child from this context. validatePendingRemove() is called. If the removal is valid, the child's beanContext property is updated (if required) and the child and its proxy peer (if there is one) is removed. Last, childJustRemovedHook() is called and listeners are notified.
        Parameters:
        child - a child of this context
        setChildBC - whether to call setBeanContext() on the child or not
        Returns:
        true if the child is removed; or false if it is not a child of this context
        Throws:
        java.lang.IllegalArgumentException - if the child is null
        java.lang.IllegalStateException - if the child is not valid to remove
      • removeAll

        public boolean removeAll​(java.util.Collection collection)
        This method is unsupported, throws UnsupportedOperationException.
        Specified by:
        removeAll in interface java.util.Collection
        See Also:
        Collection.removeAll(java.util.Collection)
      • retainAll

        public boolean retainAll​(java.util.Collection collection)
        This method is unsupported, throws UnsupportedOperationException.
        Specified by:
        retainAll in interface java.util.Collection
        See Also:
        Collection.retainAll(java.util.Collection)
      • serialize

        protected final void serialize​(java.io.ObjectOutputStream oos,
                                       java.util.Collection collection)
                                throws java.io.IOException
        Serializes the given collection. int indicating the number of all serializable elements (implements Serializable, then objects are writtern one by one.
        Parameters:
        oos - the stream where the collection is writtern to
        collection - the collection to serialize
        Throws:
        java.io.IOException - if I/O exception occurs
      • setDesignTime

        public void setDesignTime​(boolean designTime)
        Specified by:
        setDesignTime in interface DesignMode
      • setLocale

        public void setLocale​(java.util.Locale newLocale)
                       throws PropertyVetoException
        Sets the locale of this context. VetoableChangeListeners and PropertyChangeListeners are notified.
        Parameters:
        newLocale - the new locale to set
        Throws:
        PropertyVetoException - if any VetoableChangeListener vetos this change
      • size

        public int size()
        Returns the number children of this context.
        Specified by:
        size in interface java.util.Collection
        Returns:
        the number children of this context
        See Also:
        Collection.size()
      • toArray

        public java.lang.Object[] toArray()
        Returns an array of children of this context.
        Specified by:
        toArray in interface java.util.Collection
        Returns:
        an array of children of this context
        See Also:
        Collection.toArray()
      • toArray

        public java.lang.Object[] toArray​(java.lang.Object[] array)
        Returns an array of children of this context.
        Specified by:
        toArray in interface java.util.Collection
        Returns:
        an array of children of this context
        See Also:
        Collection.toArray(java.lang.Object[])
      • validatePendingAdd

        protected boolean validatePendingAdd​(java.lang.Object child)
        Validates the pending add of child.
        Parameters:
        child - the child to be added
        Returns:
        true if it is valid to add the child
      • validatePendingRemove

        protected boolean validatePendingRemove​(java.lang.Object child)
        Validates the pending removal of child.
        Parameters:
        child - the child to be removed
        Returns:
        true if it is valid to remove the child
      • writeChildren

        public final void writeChildren​(java.io.ObjectOutputStream oos)
                                 throws java.io.IOException
        Serializes children to the given object input stream. BCSChild object if the child is serializable (implements Serialization.writeObject() if the context works standalone. Or if this support object is a delegate of another BeanContext implementation, then this method should be called by the peer to avoid the 'chicken and egg' problem during deserialization.
        Parameters:
        oos - the stream to write
        Throws:
        java.io.IOException - if I/O exception occurs