There are two ways a object can be removed from a BeanContext, by either explicitly invoking the
remove() api or if the child implements BeanContextChild by calling its setBeanContext() api.

@param o
@param publicApi
@return true if successful
484823
private boolean internalRemove(Object o, boolean publicApi) {

        if (!contains(o)) return false;

        // todo: for multithreaded usage this block needs to be synchronized
        BeanContextChild bcc = null;
        if (o instanceof BeanContextProxy) {
            bcc = ((BeanContextProxy) o).getBeanContextProxy();
        }
        else if (o instanceof BeanContextChild) {
            bcc = (BeanContextChild) o;
        }

        if (bcc != null) {

            /*
             If remove invoked as a result of the BeanContext receiving an unexpected PropertyChangeEvent
             notification as a result of a 3rd party invoking setBeanContext() then the remove implementation
             shall not invoke setBeanContext(null) on that child as part of the remove() semantics, since
             doing so would overwrite the value previously set by the 3rd party.
            */
            if (publicApi) {

                // remove the property/veto listeners -- we know we want to remove the bean
                // and don't need to be notified if we have initiated the removal
                bcc.removePropertyChangeListener("beanContext", _childPcl);
                bcc.removeVetoableChangeListener("beanContext", _childVcl);

                try {
                    bcc.setBeanContext(null);
                }
                catch (PropertyVetoException e) {
                    // rewire the listeners we removed above then except
                    bcc.addPropertyChangeListener("beanContext", _childPcl);
                    bcc.addVetoableChangeListener("beanContext", _childVcl);
                    throw new IllegalStateException(e);
                }
            }
        }

        if (o instanceof BeanContextMembershipListener) {
            removeBeanContextMembershipListener((BeanContextMembershipListener) o);
        }

        BCChild bc = _children.get(o);
        if (bc.isProxy()) {
            _children.remove(bc.getChild());
        }
        else if (bc.hasProxy()) {
            _children.remove(bc.getProxy());
        }
        _children.remove(o);

        BeanContextMembershipEvent bcme = new BeanContextMembershipEvent((BeanContext) getPeer(), new Object[]{o});
        fireMembershipEvent(bcme, false);
        // end synchronized block
        return true;
    }
348276
@Override
    @PreAuthorize("hasRole(@configHolder.getSuperAdminRoleName()) or hasPermission(#plugin, 'DELETE')")
    public void delete(E plugin) {
        if (applicationService == null) {
            LOG.error("Plugin cannot be deleted, failed to autowire application service");
            return;
        }

        List<Application> apps = applicationService.findAllWithCollectionContaining("plugins", plugin);
        Integer pluginId = plugin.getId();
        for (Application app : apps) {
            List<Plugin> plugins = app.getPlugins();
            if (plugins != null && plugins.contains(plugin)) {
                String msg = String.format(
                    "Remove plugin (id=%s) from application (id=%s)",
                    pluginId, app.getId()
                );
                LOG.debug(msg);
                plugins.remove(plugin);
                // TODO will this use the the PreAuthorize annotations of AbstractCrudService wrt WRITE on the app?
                applicationService.saveOrUpdate(app);
            }
        }
        LOG.debug(String.format("Delete plugin (id=%s)", pluginId));
        // call overridden parent to actually delete the entity itself
        super.delete(plugin);
    }
1372189
public boolean remove(Object o) {
        boolean removed = false;
        for (Set<T> s : sets)
            if (s.remove(o))
                removed = true;
        return removed;
    }
41927
@Override
    public boolean remove(Object o) {

        for (;;) {
            final long head = this.head.sum();
            // we are optimistically advancing the head by one
            // if the object does not exist we have to put it back
            if (headCursor.compareAndSet(head, head + 1)) {
                for (;;) {
                    final long tail = this.tail.sum();
                    if (tailCursor.compareAndSet(tail, tail + 1)) {
                        // number removed
                        int n = 0;

                        // just blocked access to the entire queue - go for it
                        for (int i = 0; i < size(); i++) {
                            final int slot = (int) ((this.head.sum() + i) & mask);
                            if (buffer[slot] != null && buffer[slot].equals(o)) {
                                n++;

                                for (int j = i; j > 0; j--) {
                                    final int cSlot = (int) ((this.head.sum() + j - 1) & mask);
                                    final int nextSlot = (int) ((this.head.sum() + j) & mask);
                                    // overwrite ith element with previous
                                    buffer[nextSlot] = buffer[cSlot];
                                }
                            }
                        }

                        if (n > 0) {
                            // head is advanced once for each
                            headCursor.set(head + n);

                            // undo the change to tail state - this was only
                            // done to block others from changing
                            tailCursor.set(tail);
                            // tail is unchanged
                            this.head.add(n);


                            // queue is not full now
                            queueNotFullCondition.signal();
                            return true;


                        } else {
                            // no change to the queue - unblock others
                            tailCursor.set(tail);
                            headCursor.set(head);
                            return false;
                        }
                    }
                }
            }
        }
    }
826900
@Override
    public final void remove(final V entity) {
        final SqlParameterSource parameterSource; // Parameters source

        parameterSource = new BeanPropertySqlParameterSource(entity);

        getTemplate().update(getDeleteQueryTemplate(), parameterSource);
    }
568172
public void remove(EJSHome home)
    {
        List<BeanO> removedBeans = new ArrayList<BeanO>();

        // Clear out any entries eligible for garbage collection and then
        // loop through the remaining entries, looking for values that belong
        // to the specified home and remove them.  This will hold the cache
        // lock for longer than normal, but it is not expected that
        // applications will be stopped very often.
        synchronized (ivCache)
        {
            poll();

            for (Iterator<Map.Entry<WeakReference<EJSWrapperBase>, BeanO>> it = ivCache.entrySet().iterator(); it.hasNext();)
            {
                BeanO bean = it.next().getValue();

                if (bean.home == home)
                {
                    it.remove(); // d730739
                    removedBeans.add(bean);
                }
            }
        }

        // Now that the cache lock has been dropped, go ahead and destroy
        // all of the beans that were removed.
        for (BeanO bean : removedBeans)
        {
            bean.destroy();
        }
    }
693421
public boolean remove (ObjectInfo info)
    {
        int opos = indexOf(info);
        if (opos >= 0) {
            remove(opos);
            return true;
        } else {
            return false;
        }
    }
1018939
@Override
	public Object remove(java.lang.Object key) {
		return internalMap.remove(key);
	}
40841
@Override
    public boolean remove(Object o) {

        synchronized (partitions) {
            boolean remove = getPartitions().remove(o);
            updateCache();
            return remove;
        }
    }
204004
public void removeBeanContextServicesListener(BeanContextServicesListener listener)
	{
		if (listener == null)
		{
			throw new NullPointerException();
		}
		synchronized (bcsListeners)
		{
			bcsListeners.remove(listener);
		}
	}
816266
V removeMapping(final Object o) {
        if (!(o instanceof Map.Entry)) {
            throw new IllegalArgumentException();
        }

        @SuppressWarnings("unchecked") final Entry<? extends CharSequence, V> e = (Map.Entry<? extends CharSequence, V>) o;
        final CharSequence key = keyCheck(e.getKey());
        final V value = e.getValue();
        final TrieNode<V> currentNode = findPreviousNode(key);

        if (currentNode == null) {
			/* Node not found for the given key */
            return null;
        }

        final TrieNode<V> node = currentNode.children.get(key.charAt(key
                .length() - 1));

        if (node == null || !node.inUse) {
			/* Node not found for the given key or is not in use */
            return null;
        }

        final V removed = node.value;

        if (removed != value && (removed == null || !removed.equals(value))) {
			/*
			 * Value in the map differs from the value given in the entry so do
			 * nothing and return null.
			 */
            return null;
        }

        node.unset();
        --size;
        ++modCount;

        if (node.children.isEmpty()) {
			/* Since there are no children left, we can compact the trie */
            compact(key);
        }

        return removed;
    }
584195
@Override
  @Beta
  protected boolean standardRemove(@Nullable Object object) {
    try {
      // any ClassCastExceptions are caught
      @SuppressWarnings("unchecked")
      SortedSet<Object> self = (SortedSet<Object>) this;
      Iterator<Object> iterator = self.tailSet(object).iterator();
      if (iterator.hasNext()) {
        Object ceiling = iterator.next();
        if (unsafeCompare(ceiling, object) == 0) {
          iterator.remove();
          return true;
        }
      }
    } catch (ClassCastException e) {
      return false;
    } catch (NullPointerException e) {
      return false;
    }
    return false;
  }
1243187
@Override
  public void delete(ApiType obj) {
    String key = keyFunc.apply(obj);
    lock.lock();
    try {
      boolean exists = this.items.containsKey(key);
      if (exists) {
        this.deleteFromIndices(this.items.get(key), key);
        this.items.remove(key);
      }
    } finally {
      lock.unlock();
    }
  }
94203
public void remove(Object primaryKey)
                    throws RemoteException,
                    RemoveException,
                    FinderException
    {
        // d141216 method rewritten to avoid calling preinvoke/postinvoke
        //         twice in code path (i.e. don't just call remove on the
        //         bean after it is activated).  With the re-write, the
        //         bean will be activated and removed in the same tran
        //         as defined by the tx attribute on home.remove().

        final boolean isTraceOn = TraceComponent.isAnyTracingEnabled(); // d532639.2

        if (isTraceOn && tc.isEntryEnabled())
            Tr.entry(tc, "remove(pk) : " + primaryKey);

        homeEnabled();

        // Session beans and MDBs cannot be removed using this method.
        // For session beans, the spec calls for throwing an exception
        // to indicate this (no PK). MDB section not specific, thus do
        // the same for consistency.

        if (statefulSessionHome || statelessSessionHome || messageDrivenHome)
        {
            throw new RemoveException();
        }

        BeanId beanId = ivEntityHelper.remove(this, primaryKey);

        if (isTraceOn && tc.isEntryEnabled())
            Tr.exit(tc, "remove(pk) : " + beanId);
    }
1072507
public void delist(BeanO beanO)
    {
        final boolean isTraceOn = TraceComponent.isAnyTracingEnabled();
        if (isTraceOn && tc.isEntryEnabled())
            Tr.entry(tc, "delist : " + beanO);
        ensureActive();
        ivBeanOs.remove(beanO.beanId); // d130022
        ivBeanOList.remove(beanO); // d130022

        if (isTraceOn && tc.isEntryEnabled())
            Tr.exit(tc, "delist : " + beanO);
    }
1067538
public static Object handleGetProperty(Object o, String prop) throws JspCoreException {
        if (o == null) {
            throw new JspCoreException("jsp.error.beans.nullbean");
        }
        Object value = null;
        try {
            Method method = getReadMethod(o.getClass(), prop);
            value = method.invoke(o, null);
        }
        catch (Exception ex) {
            throw new JspCoreException(ex);
        }
        return value;
    }
611825
public boolean remove(O object) {
		Integer multiplicity = multiplicities.get(object);
		if (multiplicities.remove(object) == null) {
			return false;
		}
		decMultiplicityCount(multiplicity);
		return true;
	}