1 // 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. 8 // 9 // The Eclipse Public License is available at 10 // http://www.eclipse.org/legal/epl-v10.html 11 // 12 // The Apache License v2.0 is available at 13 // http://www.opensource.org/licenses/apache2.0.php 14 // 15 // You may elect to redistribute this code under either of these licenses. 16 // ======================================================================== 17 // 18 19 package org.eclipse.jetty.util.component; 20 21 import java.util.Collection; 22 23 /** 24 * A Container 25 */ 26 public interface Container 27 { 28 /* ------------------------------------------------------------ */ 29 /** 30 * Add a bean. If the bean is-a {@link Listener}, then also do an implicit {@link #addEventListener(Listener)}. 31 * @param o the bean object to add 32 * @return true if the bean was added, false if it was already present 33 */ 34 public boolean addBean(Object o); 35 36 /** 37 * @return the list of beans known to this aggregate 38 * @see #getBean(Class) 39 */ 40 public Collection<Object> getBeans(); 41 42 /** 43 * @param clazz the class of the beans 44 * @return the list of beans of the given class (or subclass) 45 * @param <T> the Bean type 46 * @see #getBeans() 47 */ 48 public <T> Collection<T> getBeans(Class<T> clazz); 49 50 /** 51 * @param clazz the class of the bean 52 * @return the first bean of a specific class (or subclass), or null if no such bean exist 53 * @param <T> the Bean type 54 */ 55 public <T> T getBean(Class<T> clazz); 56 57 /** 58 * Removes the given bean. 59 * If the bean is-a {@link Listener}, then also do an implicit {@link #removeEventListener(Listener)}. 60 * @param o the bean to remove 61 * @return whether the bean was removed 62 */ 63 public boolean removeBean(Object o); 64 65 /** 66 * Add an event listener. 67 * @see Container#addBean(Object) 68 * @param listener the listener to add 69 */ 70 public void addEventListener(Listener listener); 71 72 /** 73 * Remove an event listener. 74 * @see Container#removeBean(Object) 75 * @param listener the listener to remove 76 */ 77 public void removeEventListener(Listener listener); 78 79 /** 80 * A listener for Container events. 81 * If an added bean implements this interface it will receive the events 82 * for this container. 83 */ 84 public interface Listener 85 { 86 void beanAdded(Container parent,Object child); 87 void beanRemoved(Container parent,Object child); 88 } 89 90 /** 91 * Inherited Listener. 92 * If an added bean implements this interface, then it will 93 * be added to all contained beans that are themselves Containers 94 */ 95 public interface InheritedListener extends Listener 96 { 97 } 98 }