1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.myfaces.flow.cdi; |
20 | |
|
21 | |
import java.util.ArrayList; |
22 | |
import java.util.Iterator; |
23 | |
import java.util.List; |
24 | |
|
25 | |
import javax.enterprise.context.ApplicationScoped; |
26 | |
import javax.enterprise.inject.Produces; |
27 | |
import javax.enterprise.inject.spi.BeanManager; |
28 | |
import javax.enterprise.inject.spi.Producer; |
29 | |
import javax.faces.context.FacesContext; |
30 | |
import javax.faces.flow.Flow; |
31 | |
import javax.faces.flow.builder.FlowBuilder; |
32 | |
import javax.faces.flow.builder.FlowBuilderParameter; |
33 | |
import javax.inject.Inject; |
34 | |
import javax.inject.Named; |
35 | |
|
36 | |
import org.apache.myfaces.cdi.util.CDIUtils; |
37 | |
import org.apache.myfaces.flow.builder.FlowBuilderImpl; |
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
@Named(FlowBuilderFactoryBean.FLOW_BUILDER_FACTORY_BEAN_NAME) |
45 | |
@ApplicationScoped |
46 | |
public class FlowBuilderFactoryBean |
47 | |
{ |
48 | |
public static final String FLOW_BUILDER_FACTORY_BEAN_NAME = |
49 | |
"oam_FLOW_BUILDER_FACTORY_BEAN_NAME"; |
50 | |
|
51 | 0 | private List<Flow> flowDefinitions = null; |
52 | |
|
53 | |
@Inject |
54 | |
private FlowBuilderCDIExtension flowBuilderExtension; |
55 | |
|
56 | |
public FlowBuilderFactoryBean() |
57 | 0 | { |
58 | 0 | } |
59 | |
|
60 | |
@Produces |
61 | |
@FlowBuilderParameter |
62 | |
public FlowBuilder createFlowBuilderInstance() |
63 | |
{ |
64 | 0 | return new FlowBuilderImpl(); |
65 | |
} |
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
public synchronized List<Flow> getFlowDefinitions() |
71 | |
{ |
72 | 0 | if (flowDefinitions == null) |
73 | |
{ |
74 | 0 | flowDefinitions = new ArrayList<Flow>(); |
75 | 0 | BeanManager beanManager = CDIUtils.getBeanManager(FacesContext.getCurrentInstance().getExternalContext()); |
76 | 0 | Iterator<Producer<Flow>> it = flowBuilderExtension.getFlowProducers().iterator(); |
77 | |
|
78 | 0 | if (it != null) |
79 | |
{ |
80 | 0 | while (it.hasNext()) |
81 | |
{ |
82 | 0 | Flow flow = it.next().produce(beanManager.<Flow>createCreationalContext(null)); |
83 | 0 | flowDefinitions.add(flow); |
84 | 0 | } |
85 | |
} |
86 | |
} |
87 | |
|
88 | 0 | return flowDefinitions; |
89 | |
} |
90 | |
} |