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 | |
import java.security.PrivilegedExceptionAction; |
24 | |
|
25 | |
import javax.faces.FacesException; |
26 | |
import javax.faces.context.ExternalContext; |
27 | |
|
28 | |
import org.apache.myfaces.spi.impl.DefaultAnnotationProviderFactory; |
29 | |
import org.apache.myfaces.spi.impl.SpiUtils; |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | 0 | public abstract class AnnotationProviderFactory |
38 | |
{ |
39 | 0 | protected static final String FACTORY_DEFAULT = DefaultAnnotationProviderFactory.class.getName(); |
40 | |
|
41 | 0 | private static final String FACTORY_KEY = AnnotationProviderFactory.class.getName(); |
42 | |
|
43 | |
public static AnnotationProviderFactory getAnnotationProviderFactory(ExternalContext ctx) |
44 | |
{ |
45 | 0 | AnnotationProviderFactory instance = (AnnotationProviderFactory) ctx.getApplicationMap().get(FACTORY_KEY); |
46 | 0 | if (instance != null) |
47 | |
{ |
48 | 0 | return instance; |
49 | |
} |
50 | 0 | AnnotationProviderFactory lpf = null; |
51 | |
try |
52 | |
{ |
53 | |
|
54 | 0 | if (System.getSecurityManager() != null) |
55 | |
{ |
56 | 0 | final ExternalContext ectx = ctx; |
57 | 0 | lpf = (AnnotationProviderFactory) AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() |
58 | 0 | { |
59 | |
public Object run() throws PrivilegedActionException |
60 | |
{ |
61 | 0 | return SpiUtils.build(ectx, |
62 | |
AnnotationProviderFactory.class, |
63 | |
FACTORY_DEFAULT); |
64 | |
} |
65 | |
}); |
66 | 0 | } |
67 | |
else |
68 | |
{ |
69 | 0 | lpf = (AnnotationProviderFactory) SpiUtils.build(ctx, AnnotationProviderFactory.class, FACTORY_DEFAULT); |
70 | |
} |
71 | |
} |
72 | 0 | catch (PrivilegedActionException pae) |
73 | |
{ |
74 | 0 | throw new FacesException(pae); |
75 | 0 | } |
76 | 0 | if (lpf != null) |
77 | |
{ |
78 | 0 | setAnnotationProviderFactory(ctx, lpf); |
79 | |
} |
80 | 0 | return lpf; |
81 | |
} |
82 | |
|
83 | |
public static void setAnnotationProviderFactory(ExternalContext ctx, AnnotationProviderFactory instance) |
84 | |
{ |
85 | 0 | ctx.getApplicationMap().put(FACTORY_KEY, instance); |
86 | 0 | } |
87 | |
|
88 | |
public abstract AnnotationProvider createAnnotationProvider(ExternalContext externalContext); |
89 | |
|
90 | |
public AnnotationProvider getAnnotationProvider(ExternalContext externalContext) |
91 | |
{ |
92 | 0 | return createAnnotationProvider(externalContext); |
93 | |
} |
94 | |
} |