1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.orchestra.dynaForm.jsf.guiBuilder.impl.jsf;
20
21 import org.apache.commons.logging.LogFactory;
22 import org.apache.myfaces.orchestra.dynaForm.jsf.guiBuilder.impl.myfaces.MyFacesCheck;
23 import org.apache.myfaces.orchestra.lib.OrchestraException;
24 import org.apache.myfaces.shared_orchestra.util.ClassUtils;
25
26 import javax.faces.context.FacesContext;
27 import java.lang.reflect.Constructor;
28 import java.lang.reflect.InvocationTargetException;
29
30 public class JsfGuiBuilderFactory
31 {
32 public final static String CONTEXT_GUI_BUILDER = "org.apache.myfaces.custom.dynaForm.GUI_BUILDER";
33
34 private JsfGuiBuilderFactory()
35 {
36 }
37
38 public static JsfGuiBuilder create(final FacesContext facesContext)
39 {
40 JsfGuiBuilder guiBuilder = null;
41
42 String guiBuilderName = facesContext.getExternalContext().getInitParameter(CONTEXT_GUI_BUILDER);
43 if (guiBuilderName == null)
44 {
45 guiBuilder = createGuiBuilderInternal();
46 }
47 else
48 {
49 try
50 {
51 @SuppressWarnings("unchecked")
52 Class<? extends JsfGuiBuilder> guiBuilderClass =
53 (Class<? extends JsfGuiBuilder>) Class.forName(guiBuilderName);
54 try
55 {
56
57 Constructor<? extends JsfGuiBuilder> decoratorConst =
58 guiBuilderClass.getConstructor(new Class[]{JsfGuiBuilder.class});
59 return decoratorConst.newInstance(new Object[]{
60 createGuiBuilderInternal()
61 });
62 }
63 catch (NoSuchMethodException e)
64 {
65
66 return (JsfGuiBuilder) guiBuilderClass.newInstance();
67 }
68 }
69 catch (IllegalArgumentException e)
70 {
71 throw new OrchestraException(e);
72 }
73 catch (InvocationTargetException e)
74 {
75 throw new OrchestraException(e);
76 }
77 catch (SecurityException e)
78 {
79 throw new OrchestraException(e);
80 }
81 catch (InstantiationException e)
82 {
83 throw new OrchestraException(e);
84 }
85 catch (IllegalAccessException e)
86 {
87 throw new OrchestraException(e);
88 }
89 catch (ClassNotFoundException e)
90 {
91 throw new OrchestraException(e);
92 }
93 }
94 return guiBuilder;
95 }
96
97 protected static JsfGuiBuilder createGuiBuilderInternal()
98 {
99 JsfGuiBuilder guiBuilder = null;
100 if (MyFacesCheck.isTomahawkAvailable())
101 {
102 try
103 {
104
105
106 String myfacesImpl =
107 "org.apache.myfaces.orchestra.dynaForm.jsf.guiBuilder.impl.myfaces.MyFacesGuiBuilder";
108 @SuppressWarnings("unchecked")
109 Class<? extends JsfGuiBuilder> myfacesGuiBuilder =
110 ClassUtils.classForName(myfacesImpl);
111 guiBuilder = (JsfGuiBuilder) myfacesGuiBuilder.newInstance();
112 }
113 catch (ClassNotFoundException e)
114 {
115 LogFactory.getLog(JsfGuiBuilderFactory.class)
116 .warn("consider using the myfaces-orchestra-sandbox for better gui support", e);
117 }
118 catch (InstantiationException e)
119 {
120 LogFactory.getLog(JsfGuiBuilderFactory.class)
121 .warn("can't create the myfaces gui builder - reverting to plain JSF", e);
122 }
123 catch (IllegalAccessException e)
124 {
125 LogFactory.getLog(JsfGuiBuilderFactory.class)
126 .warn("can't create the myfaces gui builder - reverting to plain JSF", e);
127 }
128 }
129
130 if (guiBuilder == null)
131 {
132 guiBuilder = new JsfGuiBuilder();
133 }
134 return guiBuilder;
135 }
136 }