01: /*
02: * Created on 10-Mar-2006
03: */
04: package uk.org.ponder.rsac;
05:
06: import java.util.ArrayList;
07: import java.util.HashMap;
08: import java.util.Iterator;
09: import java.util.List;
10: import java.util.Map;
11:
12: import org.springframework.context.ApplicationContext;
13:
14: import uk.org.ponder.util.RunnableInvoker;
15:
16: /**
17: * Acquire all beans of type BeanFetchBracketer and add them into the RBIMap.
18: */
19: public class BracketerPopulator {
20:
21: public static void populateBracketers(
22: ApplicationContext applicationContext, Map rbimap) {
23: HashMap build = new HashMap();
24: String[] names = applicationContext.getBeanNamesForType(
25: BeanFetchBracketer.class, false, false);
26: for (int i = 0; i < names.length; ++i) {
27: BeanFetchBracketer bracketer = (BeanFetchBracketer) applicationContext
28: .getBean(names[i]);
29: String targetname = bracketer.getTargetBeanName();
30: if (targetname == null)
31: throw new IllegalArgumentException(
32: "Error in configuration: BeanFetchBracketer "
33: + names[i]
34: + " does not carry a targetBeanName");
35: List bracks = (ArrayList) build.get(targetname);
36: if (bracks == null) {
37: bracks = new ArrayList();
38: build.put(targetname, bracks);
39: }
40: bracks.add(bracketer.getWrappingBean());
41: }
42:
43: for (Iterator nameit = build.keySet().iterator(); nameit
44: .hasNext();) {
45: String name = (String) nameit.next();
46: List wrappers = (List) build.get(name);
47: Object[] resolved = new Object[wrappers.size()];
48: for (int i = 0; i < wrappers.size(); ++i) {
49: Object wrappero = wrappers.get(i);
50: if (wrappero instanceof RunnableInvoker) {
51: resolved[i] = wrappero;
52: } else {
53: String wrappername = (String) wrappero;
54: if (applicationContext
55: .containsBeanDefinition(wrappername)) {
56: RunnableInvoker wrapper = (RunnableInvoker) applicationContext
57: .getBean(wrappername);
58: resolved[i] = wrapper;
59: } else {
60: resolved[i] = wrappername;
61: }
62: }
63: } // end for each wrapper for this target
64: RSACBeanInfo rbi = (RSACBeanInfo) rbimap.get(name);
65: rbi.fetchwrappers = resolved;
66: }
67:
68: }
69:
70: }
|