01: /*****************************************************************************
02: * Copyright (C) NanoContainer Organization. All rights reserved. *
03: * ------------------------------------------------------------------------- *
04: * The software in this package is published under the terms of the BSD *
05: * style license a copy of which has been included with this distribution in *
06: * the LICENSE.txt file. *
07: * *
08: * Original code by Aslak Hellesoy & Joerg Schaible *
09: *****************************************************************************/package org.picocontainer.gems.util;
10:
11: import com.thoughtworks.proxy.ProxyFactory;
12: import com.thoughtworks.proxy.toys.multicast.Multicasting;
13: import org.picocontainer.PicoContainer;
14:
15: import java.util.ArrayList;
16: import java.util.Collections;
17: import java.util.List;
18:
19: /**
20: * Factory for creating a multicaster object that multicasts calls to all
21: * components in a PicoContainer instance.
22: *
23: * @author Aslak Hellesøy
24: * @author Chris Stevenson
25: * @author Paul Hammant
26: */
27: public class Multicaster {
28: /**
29: * Create a {@link Multicasting} proxy for the components of a {@link PicoContainer}.
30: *
31: * @param pico the container
32: * @param callInInstantiationOrder <code>true</code> if the components will be called in instantiation order
33: * @param proxyFactory the ProxyFactory to use
34: * @return the Multicasting proxy
35: */
36: public static Object object(PicoContainer pico,
37: boolean callInInstantiationOrder, ProxyFactory proxyFactory) {
38: List copy = new ArrayList(pico.getComponents());
39:
40: if (!callInInstantiationOrder) {
41: // reverse the list
42: Collections.reverse(copy);
43: }
44: Object[] targets = copy.toArray();
45: return Multicasting.object(proxyFactory, targets);
46: }
47: }
|