1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.myfaces.spi; |
20 | |
|
21 | |
import java.security.AccessController; |
22 | |
import java.security.PrivilegedActionException; |
23 | |
|
24 | |
import javax.faces.FacesException; |
25 | |
import javax.faces.context.ExternalContext; |
26 | |
|
27 | |
import org.apache.myfaces.spi.impl.DefaultFacesConfigurationProviderFactory; |
28 | |
import org.apache.myfaces.spi.impl.SpiUtils; |
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | 0 | public abstract class FacesConfigurationProviderFactory |
38 | |
{ |
39 | |
|
40 | 0 | protected static final String FACTORY_DEFAULT = DefaultFacesConfigurationProviderFactory.class.getName(); |
41 | |
|
42 | 0 | private static final String FACTORY_KEY = FacesConfigurationProviderFactory.class.getName(); |
43 | |
|
44 | |
public static FacesConfigurationProviderFactory getFacesConfigurationProviderFactory(ExternalContext ctx) |
45 | |
{ |
46 | 0 | FacesConfigurationProviderFactory factory |
47 | |
= (FacesConfigurationProviderFactory) ctx.getApplicationMap().get(FACTORY_KEY); |
48 | 0 | if (factory != null) |
49 | |
{ |
50 | |
|
51 | 0 | return factory; |
52 | |
} |
53 | |
|
54 | |
|
55 | |
try |
56 | |
{ |
57 | |
|
58 | 0 | if (System.getSecurityManager() != null) |
59 | |
{ |
60 | 0 | final ExternalContext ectx = ctx; |
61 | 0 | factory = (FacesConfigurationProviderFactory) AccessController.doPrivileged( |
62 | |
new java.security.PrivilegedExceptionAction<Object>() |
63 | 0 | { |
64 | |
public Object run() throws PrivilegedActionException |
65 | |
{ |
66 | |
|
67 | 0 | return SpiUtils.build(ectx, |
68 | |
FacesConfigurationProviderFactory.class, |
69 | |
FACTORY_DEFAULT); |
70 | |
} |
71 | |
}); |
72 | 0 | } |
73 | |
else |
74 | |
{ |
75 | 0 | factory = (FacesConfigurationProviderFactory) |
76 | |
SpiUtils.build(ctx, FacesConfigurationProviderFactory.class, FACTORY_DEFAULT); |
77 | |
} |
78 | |
} |
79 | 0 | catch (PrivilegedActionException pae) |
80 | |
{ |
81 | 0 | throw new FacesException(pae); |
82 | 0 | } |
83 | |
|
84 | 0 | if (factory != null) |
85 | |
{ |
86 | |
|
87 | 0 | setFacesConfigurationProviderFactory(ctx, factory); |
88 | |
} |
89 | |
|
90 | 0 | return factory; |
91 | |
} |
92 | |
|
93 | |
public static void setFacesConfigurationProviderFactory(ExternalContext ctx, |
94 | |
FacesConfigurationProviderFactory factory) |
95 | |
{ |
96 | 0 | ctx.getApplicationMap().put(FACTORY_KEY, factory); |
97 | 0 | } |
98 | |
|
99 | |
public abstract FacesConfigurationProvider getFacesConfigurationProvider(ExternalContext externalContext); |
100 | |
|
101 | |
} |