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 public class DefaultWebConfigProviderFactory extends WebConfigProviderFactory
47 {
48
49 public static final String WEB_CONFIG_PROVIDER = WebConfigProvider.class.getName();
50
51 public static final String WEB_CONFIG_PROVIDER_LIST = WebConfigProvider.class.getName()+".LIST";
52
53 private Logger getLogger()
54 {
55 return Logger.getLogger(DefaultWebConfigProviderFactory.class.getName());
56 }
57
58 @Override
59 public WebConfigProvider getWebConfigProvider(ExternalContext externalContext)
60 {
61 WebConfigProvider returnValue = null;
62 final ExternalContext extContext = externalContext;
63 try
64 {
65 if (System.getSecurityManager() != null)
66 {
67 returnValue = AccessController.doPrivileged(new PrivilegedExceptionAction<WebConfigProvider>()
68 {
69 public WebConfigProvider run() throws ClassNotFoundException,
70 NoClassDefFoundError,
71 InstantiationException,
72 IllegalAccessException,
73 InvocationTargetException,
74 PrivilegedActionException
75 {
76 return resolveWebXmlProviderFromService(extContext);
77 }
78 });
79 }
80 else
81 {
82 returnValue = resolveWebXmlProviderFromService(extContext);
83 }
84 }
85 catch (ClassNotFoundException e)
86 {
87
88 }
89 catch (NoClassDefFoundError e)
90 {
91
92 }
93 catch (InstantiationException e)
94 {
95 getLogger().log(Level.SEVERE, "", e);
96 }
97 catch (IllegalAccessException e)
98 {
99 getLogger().log(Level.SEVERE, "", e);
100 }
101 catch (InvocationTargetException e)
102 {
103 getLogger().log(Level.SEVERE, "", e);
104 }
105 catch (PrivilegedActionException e)
106 {
107 throw new FacesException(e);
108 }
109
110 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 List<String> classList = (List<String>) externalContext.getApplicationMap().get(WEB_CONFIG_PROVIDER_LIST);
122 if (classList == null)
123 {
124 classList = ServiceProviderFinderFactory.getServiceProviderFinder(externalContext).
125 getServiceProviderList(WEB_CONFIG_PROVIDER);
126 externalContext.getApplicationMap().put(WEB_CONFIG_PROVIDER_LIST, classList);
127 }
128
129 return ClassUtils.buildApplicationObject(WebConfigProvider.class, classList, new DefaultWebConfigProvider());
130 }
131
132 }