1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
package org.mule.module.ibeans.config; |
11 | |
|
12 | |
import org.mule.api.MuleContext; |
13 | |
import org.mule.api.MuleException; |
14 | |
import org.mule.api.construct.FlowConstruct; |
15 | |
import org.mule.module.ibeans.spi.MuleIBeansPlugin; |
16 | |
|
17 | |
import org.ibeans.impl.IBeansNotationHelper; |
18 | |
import org.ibeans.impl.view.TextView; |
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
public class IBeanHolder implements Comparable |
25 | |
{ |
26 | |
private Class ibean; |
27 | |
private String usage; |
28 | |
|
29 | |
public IBeanHolder(Class ibean) |
30 | 0 | { |
31 | 0 | this.ibean = ibean; |
32 | 0 | } |
33 | |
|
34 | |
public int compareTo(Object o) |
35 | |
{ |
36 | 0 | IBeanHolder to = (IBeanHolder) o; |
37 | 0 | return getId().compareTo(to.getId()); |
38 | |
} |
39 | |
|
40 | |
public Class getIbeanClass() |
41 | |
{ |
42 | 0 | return ibean; |
43 | |
} |
44 | |
|
45 | |
public Object create(MuleContext muleContext, MuleIBeansPlugin plugin) throws MuleException |
46 | |
{ |
47 | 0 | final String name = String.format("%s.%d", ibean.getSimpleName(), System.identityHashCode(this)); |
48 | 0 | IBeanFlowConstruct flow = new IBeanFlowConstruct(name, muleContext); |
49 | 0 | muleContext.getRegistry().registerObject(flow.getName(), flow, FlowConstruct.class); |
50 | |
|
51 | 0 | IBeanBinding router = new IBeanBinding(flow, muleContext, plugin); |
52 | 0 | router.setInterface(ibean); |
53 | 0 | return router.createProxy(new Object()); |
54 | |
} |
55 | |
|
56 | |
public String getId() |
57 | |
{ |
58 | 0 | return IBeansNotationHelper.getIBeanShortID(ibean); |
59 | |
} |
60 | |
|
61 | |
public String getUsage() |
62 | |
{ |
63 | 0 | if (usage == null) |
64 | |
{ |
65 | 0 | TextView view = new TextView(); |
66 | 0 | usage = view.createView(ibean); |
67 | |
} |
68 | 0 | return usage; |
69 | |
} |
70 | |
|
71 | |
@Override |
72 | |
public String toString() |
73 | |
{ |
74 | 0 | return "IBean: " + getId() + " : " + ibean.getName(); |
75 | |
} |
76 | |
} |