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