1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.myfaces.spi.impl; |
20 | |
|
21 | |
import java.lang.reflect.InvocationTargetException; |
22 | |
import java.security.AccessController; |
23 | |
import java.security.PrivilegedActionException; |
24 | |
import java.security.PrivilegedExceptionAction; |
25 | |
import java.util.List; |
26 | |
import java.util.logging.Level; |
27 | |
import java.util.logging.Logger; |
28 | |
|
29 | |
import javax.faces.FacesException; |
30 | |
import javax.faces.context.ExternalContext; |
31 | |
|
32 | |
import org.apache.myfaces.shared.util.ClassUtils; |
33 | |
import org.apache.myfaces.spi.ServiceProviderFinderFactory; |
34 | |
import org.apache.myfaces.spi.WebConfigProvider; |
35 | |
import org.apache.myfaces.spi.WebConfigProviderFactory; |
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | 0 | public class DefaultWebConfigProviderFactory extends WebConfigProviderFactory |
47 | |
{ |
48 | |
|
49 | 0 | public static final String WEB_CONFIG_PROVIDER = WebConfigProvider.class.getName(); |
50 | |
|
51 | 0 | public static final String WEB_CONFIG_PROVIDER_LIST = WebConfigProvider.class.getName()+".LIST"; |
52 | |
|
53 | |
private Logger getLogger() |
54 | |
{ |
55 | 0 | return Logger.getLogger(DefaultWebConfigProviderFactory.class.getName()); |
56 | |
} |
57 | |
|
58 | |
@Override |
59 | |
public WebConfigProvider getWebConfigProvider(ExternalContext externalContext) |
60 | |
{ |
61 | 0 | WebConfigProvider returnValue = null; |
62 | 0 | final ExternalContext extContext = externalContext; |
63 | |
try |
64 | |
{ |
65 | 0 | if (System.getSecurityManager() != null) |
66 | |
{ |
67 | 0 | returnValue = AccessController.doPrivileged(new PrivilegedExceptionAction<WebConfigProvider>() |
68 | 0 | { |
69 | |
public WebConfigProvider run() throws ClassNotFoundException, |
70 | |
NoClassDefFoundError, |
71 | |
InstantiationException, |
72 | |
IllegalAccessException, |
73 | |
InvocationTargetException, |
74 | |
PrivilegedActionException |
75 | |
{ |
76 | 0 | return resolveWebXmlProviderFromService(extContext); |
77 | |
} |
78 | |
}); |
79 | |
} |
80 | |
else |
81 | |
{ |
82 | 0 | returnValue = resolveWebXmlProviderFromService(extContext); |
83 | |
} |
84 | |
} |
85 | 0 | catch (ClassNotFoundException e) |
86 | |
{ |
87 | |
|
88 | |
} |
89 | 0 | catch (NoClassDefFoundError e) |
90 | |
{ |
91 | |
|
92 | |
} |
93 | 0 | catch (InstantiationException e) |
94 | |
{ |
95 | 0 | getLogger().log(Level.SEVERE, "", e); |
96 | |
} |
97 | 0 | catch (IllegalAccessException e) |
98 | |
{ |
99 | 0 | getLogger().log(Level.SEVERE, "", e); |
100 | |
} |
101 | 0 | catch (InvocationTargetException e) |
102 | |
{ |
103 | 0 | getLogger().log(Level.SEVERE, "", e); |
104 | |
} |
105 | 0 | catch (PrivilegedActionException e) |
106 | |
{ |
107 | 0 | throw new FacesException(e); |
108 | 0 | } |
109 | |
|
110 | 0 | return returnValue; |
111 | |
} |
112 | |
|
113 | |
private WebConfigProvider resolveWebXmlProviderFromService( |
114 | |
ExternalContext externalContext) throws ClassNotFoundException, |
115 | |
NoClassDefFoundError, |
116 | |
InstantiationException, |
117 | |
IllegalAccessException, |
118 | |
InvocationTargetException, |
119 | |
PrivilegedActionException |
120 | |
{ |
121 | 0 | List<String> classList = (List<String>) externalContext.getApplicationMap().get(WEB_CONFIG_PROVIDER_LIST); |
122 | 0 | if (classList == null) |
123 | |
{ |
124 | 0 | classList = ServiceProviderFinderFactory.getServiceProviderFinder(externalContext). |
125 | |
getServiceProviderList(WEB_CONFIG_PROVIDER); |
126 | 0 | externalContext.getApplicationMap().put(WEB_CONFIG_PROVIDER_LIST, classList); |
127 | |
} |
128 | |
|
129 | 0 | return ClassUtils.buildApplicationObject(WebConfigProvider.class, classList, new DefaultWebConfigProvider()); |
130 | |
} |
131 | |
|
132 | |
} |