2 // ========================================================================
3 // Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
4 // ------------------------------------------------------------------------
5 // All rights reserved. This program and the accompanying materials
6 // are made available under the terms of the Eclipse Public License v1.0
7 // and Apache License v2.0 which accompanies this distribution.
9 // The Eclipse Public License is available at
10 // http://www.eclipse.org/legal/epl-v10.html
12 // The Apache License v2.0 is available at
13 // http://www.opensource.org/licenses/apache2.0.php
15 // You may elect to redistribute this code under either of these licenses.
16 // ========================================================================
19 package org.eclipse.jetty.util.component;
21 import java.util.Collection;
23 public interface Container
25 /* ------------------------------------------------------------ */
27 * Add a bean. If the bean is-a {@link Listener}, then also do an implicit {@link #addEventListener(Listener)}.
28 * @param o the bean object to add
29 * @return true if the bean was added, false if it was already present
31 public boolean addBean(Object o);
34 * @return the list of beans known to this aggregate
35 * @see #getBean(Class)
37 public Collection<Object> getBeans();
40 * @param clazz the class of the beans
41 * @return the list of beans of the given class (or subclass)
44 public <T> Collection<T> getBeans(Class<T> clazz);
47 * @param clazz the class of the bean
48 * @return the first bean of a specific class (or subclass), or null if no such bean exist
50 public <T> T getBean(Class<T> clazz);
53 * Removes the given bean.
54 * If the bean is-a {@link Listener}, then also do an implicit {@link #removeEventListener(Listener)}.
55 * @return whether the bean was removed
57 public boolean removeBean(Object o);
60 * Add an event listener.
61 * @see Container#addBean(Object)
64 public void addEventListener(Listener listener);
67 * Remove an event listener.
68 * @see Container#removeBean(Object)
71 public void removeEventListener(Listener listener);
74 * A listener for Container events.
75 * If an added bean implements this interface it will receive the events
78 public interface Listener
80 void beanAdded(Container parent,Object child);
81 void beanRemoved(Container parent,Object child);
86 * If an added bean implements this interface, then it will
87 * be added to all contained beans that are themselves Containers
89 public interface InheritedListener extends Listener