KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > picocontainer > gems > util > Multicaster


1 /*****************************************************************************
2  * Copyright (C) NanoContainer Organization. All rights reserved. *
3  * ------------------------------------------------------------------------- *
4  * The software in this package is published under the terms of the BSD *
5  * style license a copy of which has been included with this distribution in *
6  * the LICENSE.txt file. *
7  * *
8  * Original code by Aslak Hellesoy & Joerg Schaible *
9  *****************************************************************************/

10 package org.picocontainer.gems.util;
11
12 import com.thoughtworks.proxy.ProxyFactory;
13 import com.thoughtworks.proxy.toys.multicast.Multicasting;
14 import org.picocontainer.PicoContainer;
15
16 import java.util.ArrayList JavaDoc;
17 import java.util.Collections JavaDoc;
18 import java.util.List JavaDoc;
19
20 /**
21  * Factory for creating a multicaster object that multicasts calls to all
22  * components in a PicoContainer instance.
23  *
24  * @author Aslak Hellesøy
25  * @author Chris Stevenson
26  * @author Paul Hammant
27  * @since 1.2
28  */

29 public class Multicaster {
30     /**
31      * Create a {@link Multicasting} proxy for the components of a {@link PicoContainer}.
32      *
33      * @param pico the container
34      * @param callInInstantiationOrder <code>true</code> if the components will be called in instantiation order
35      * @param proxyFactory the ProxyFactory to use
36      * @return the Multicasting proxy
37      * @since 1.2
38      */

39     public static Object JavaDoc object(PicoContainer pico, boolean callInInstantiationOrder, ProxyFactory proxyFactory) {
40         List JavaDoc copy = new ArrayList JavaDoc(pico.getComponentInstances());
41
42         if (!callInInstantiationOrder) {
43             // reverse the list
44
Collections.reverse(copy);
45         }
46         Object JavaDoc[] targets = copy.toArray();
47         return Multicasting.object(proxyFactory, targets);
48     }
49 }
Popular Tags