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