View Javadoc

1   //
2   //  ========================================================================
3   //  Copyright (c) 1995-2014 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  public interface Container
24  {
25      /* ------------------------------------------------------------ */
26      /**
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
30       */
31      public boolean addBean(Object o);
32  
33      /**
34       * @return the list of beans known to this aggregate
35       * @see #getBean(Class)
36       */
37      public Collection<Object> getBeans();
38  
39      /**
40       * @param clazz the class of the beans
41       * @return the list of beans of the given class (or subclass)
42       * @see #getBeans()
43       */
44      public <T> Collection<T> getBeans(Class<T> clazz);
45  
46      /**
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
49       */
50      public <T> T getBean(Class<T> clazz);
51  
52      /**
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
56       */
57      public boolean removeBean(Object o);
58      
59      /**
60       * Add an event listener. 
61       * @see Container#addBean(Object)
62       * @param listener
63       */
64      public void addEventListener(Listener listener);
65      
66      /**
67       * Remove an event listener. 
68       * @see Container#removeBean(Object)
69       * @param listener
70       */
71      public void removeEventListener(Listener listener);
72  
73      /**
74       * A listener for Container events.
75       * If an added bean implements this interface it will receive the events
76       * for this container.
77       */
78      public interface Listener
79      {
80          void beanAdded(Container parent,Object child);
81          void beanRemoved(Container parent,Object child);
82      }
83      
84      /**
85       * Inherited Listener.
86       * If an added bean implements this interface, then it will 
87       * be added to all contained beans that are themselves Containers
88       */
89      public interface InheritedListener extends Listener
90      {
91      }
92  }