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