1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.extensions.validator.core;
20
21 import org.apache.myfaces.extensions.validator.core.storage.ViolationSeverityInterpreterStorage;
22 import org.apache.myfaces.extensions.validator.core.validation.parameter.ViolationSeverityInterpreter;
23 import org.apache.myfaces.extensions.validator.internal.UsageCategory;
24 import org.apache.myfaces.extensions.validator.internal.UsageInformation;
25 import org.apache.myfaces.extensions.validator.util.ClassUtils;
26 import org.apache.myfaces.extensions.validator.util.ExtValUtils;
27
28 import javax.faces.context.FacesContext;
29 import java.util.ArrayList;
30 import java.util.List;
31 import java.util.Map;
32
33
34
35
36 @UsageInformation(UsageCategory.INTERNAL)
37 class ExtValContextInternals
38 {
39 boolean isComponentInitializationActivated()
40 {
41 return !ExtValCoreConfiguration.get().deactivateComponentInitialization();
42 }
43
44 @SuppressWarnings({"unchecked"})
45 synchronized InformationProviderBean initInformationProviderBean(Map applicationMap)
46 {
47 List<String> informationProviderBeanClassNames = new ArrayList<String>();
48
49 informationProviderBeanClassNames.add(ExtValCoreConfiguration.get().customInformationProviderBeanClassName());
50 informationProviderBeanClassNames.add(InformationProviderBean.CUSTOM_BEAN);
51
52 InformationProviderBean informationProviderBean;
53 for (String className : informationProviderBeanClassNames)
54 {
55 informationProviderBean = (InformationProviderBean) ClassUtils.tryToInstantiateClassForName(className);
56
57 if (informationProviderBean != null)
58 {
59 applicationMap.put(InformationProviderBean.BEAN_NAME, informationProviderBean);
60 return informationProviderBean;
61 }
62 }
63
64 tryToInitCustomConfiguredInformationProviderBeanClassName(applicationMap);
65
66 if (applicationMap.containsKey(InformationProviderBean.BEAN_NAME))
67 {
68 return (InformationProviderBean) applicationMap.get(InformationProviderBean.BEAN_NAME);
69 }
70 return new InformationProviderBean();
71 }
72
73 @SuppressWarnings({"unchecked"})
74 synchronized void tryToInitCustomConfiguredInformationProviderBeanClassName(Map applicationMap)
75 {
76 InformationProviderBean bean = (InformationProviderBean) ExtValUtils.getELHelper()
77 .getBean(InformationProviderBean.CUSTOM_BEAN.replace(".", "_"));
78
79 if (bean != null)
80 {
81 applicationMap.put(InformationProviderBean.BEAN_NAME, bean);
82 }
83 }
84
85 InformationProviderBean getInformationProviderBean()
86 {
87 Map applicationMap = FacesContext.getCurrentInstance().getExternalContext().getApplicationMap();
88 InformationProviderBean bean = (InformationProviderBean) applicationMap.get(InformationProviderBean.BEAN_NAME);
89
90 if (bean == null)
91 {
92 return initInformationProviderBean(applicationMap);
93 }
94 return bean;
95 }
96
97 ViolationSeverityInterpreter getRequestScopedViolationSeverityInterpreter()
98 {
99 return ExtValUtils.getStorage(
100 ViolationSeverityInterpreterStorage.class, ViolationSeverityInterpreterStorage.class.getName())
101 .getViolationSeverityInterpreter();
102 }
103 }