private boolean internalAdd(Object o, boolean publicApi) {

        if (contains(o)) return false;

        // todo: for multithreaded usage this block needs to be synchronized
        // spec: if the object being added implements BeanContextChild or BeanContextProxy
        // need to set the bean context of the object to this bean context.
        BeanContextChild bcc = null;
        BeanContextProxy bcp = null;

        if (o instanceof BeanContextProxy) {
            if (o instanceof BeanContext) {
                throw new IllegalArgumentException("May not implement both BeanContextProxy and BeanContext!!");
            }
            bcp = (BeanContextProxy) o;
            bcc = bcp.getBeanContextProxy();
        }
        else if (o instanceof BeanContextChild) {
            bcc = (BeanContextChild) o;
        }

        if (bcc != null) {
            try {
                bcc.setBeanContext((BeanContext) getPeer());
            }
            catch (PropertyVetoException e) {
                throw new IllegalStateException(e);
            }

            bcc.addPropertyChangeListener("beanContext", _childPcl);
            bcc.addVetoableChangeListener("beanContext", _childVcl);
        }

        if (publicApi) {
            if (o instanceof Visibility) {
                if (_mayUseGui) {
                    ((Visibility) o).okToUseGui();
                }
                else {
                    ((Visibility) o).dontUseGui();
                }
            }
            if (o instanceof BeanContextMembershipListener) {
                addBeanContextMembershipListener((BeanContextMembershipListener) o);
            }
        }

        if (bcp == null) {
            _children.put(o, new BCChild(o));
        }
        else {
            _children.put(bcp, new BCChild(bcp, bcc, true));
            _children.put(bcc, new BCChild(bcp, bcc, false));
        }

        BeanContextMembershipEvent bcme = new BeanContextMembershipEvent((BeanContext) getPeer(), new Object[]{o});
        fireMembershipEvent(bcme, true);
//        }
        return true;
    }
private boolean internalAdd ( Object o , boolean publicApi ) { if ( contains ( o ) ) return false ; BeanContextChild bcc = null ; BeanContextProxy bcp = null ; if ( o instanceof BeanContextProxy ) { if ( o instanceof BeanContext ) { throw new IllegalArgumentException ( "May not implement both BeanContextProxy and BeanContext!!" ) ; } bcp = ( BeanContextProxy ) o ; bcc = bcp . getBeanContextProxy ( ) ; } else if ( o instanceof BeanContextChild ) { bcc = ( BeanContextChild ) o ; } if ( bcc != null ) { try { bcc . setBeanContext ( ( BeanContext ) getPeer ( ) ) ; } catch ( PropertyVetoException e ) { throw new IllegalStateException ( e ) ; } bcc . addPropertyChangeListener ( "beanContext" , _childPcl ) ; bcc . addVetoableChangeListener ( "beanContext" , _childVcl ) ; } if ( publicApi ) { if ( o instanceof Visibility ) { if ( _mayUseGui ) { ( ( Visibility ) o ) . okToUseGui ( ) ; } else { ( ( Visibility ) o ) . dontUseGui ( ) ; } } if ( o instanceof BeanContextMembershipListener ) { addBeanContextMembershipListener ( ( BeanContextMembershipListener ) o ) ; } } if ( bcp == null ) { _children . put ( o , new BCChild ( o ) ) ; } else { _children . put ( bcp , new BCChild ( bcp , bcc , true ) ) ; _children . put ( bcc , new BCChild ( bcp , bcc , false ) ) ; } BeanContextMembershipEvent bcme = new BeanContextMembershipEvent ( ( BeanContext ) getPeer ( ) , new Object [ ] { o } ) ; fireMembershipEvent ( bcme , true ) ; return true ; }
The internalAdd method is used in two different cases. If an add is done
through the public add() api, this method is invoked with the publicApi
parameter set to true.  During deserialization of children this method
is invoked with publicApi set to false.  During deserialization it is
not necessary to set Visibility features or re-register as a listener.

@param o
@param publicApi
@return true if added.