Skip to content

Package: ELManager

ELManager

nameinstructionbranchcomplexitylinemethod
ELManager()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
addBeanNameResolver(BeanNameResolver)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
addELResolver(ELResolver)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
addEvaluationListener(EvaluationListener)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
defineBean(String, Object)
M: 15 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getELContext()
M: 12 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getExpressionFactory()
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
importClass(String)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
importPackage(String)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
importStatic(String)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
mapFunction(String, String, Method)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
setELContext(ELContext)
M: 11 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
setVariable(String, ValueExpression)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * Copyright (c) 2013, 2022 Oracle and/or its affiliates and others.
3: * All rights reserved.
4: *
5: * This program and the accompanying materials are made available under the
6: * terms of the Eclipse Public License v. 2.0, which is available at
7: * http://www.eclipse.org/legal/epl-2.0.
8: *
9: * This Source Code may also be made available under the following Secondary
10: * Licenses when the conditions for such availability set forth in the
11: * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
12: * version 2 with the GNU Classpath Exception, which is available at
13: * https://www.gnu.org/software/classpath/license.html.
14: *
15: * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16: */
17:
18: package jakarta.el;
19:
20: import java.lang.reflect.Method;
21:
22: /**
23: * Manages Jakarta Expression Language parsing and evaluation environment. The ELManager maintains an instance of
24: * ExpressionFactory and StandardELContext, for parsing and evaluating Jakarta Expression Language expressions.
25: *
26: * @since Jakarta Expression Language 3.0
27: */
28: public class ELManager {
29:
30: private static ExpressionFactory exprFactory = ExpressionFactory.newInstance();
31:
32: private StandardELContext elContext;
33:
34: /**
35: * Return the ExpressionFactory instance used for Jakarta Expression Language evaluations.
36: *
37: * @return The ExpressionFactory
38: */
39: public static ExpressionFactory getExpressionFactory() {
40: return exprFactory;
41: }
42:
43: /**
44: * Return the ELContext used for parsing and evaluating Jakarta Expression Language expressions. If there is currently
45: * no ELContext, a default instance of StandardELContext is returned.
46: *
47: * @return The ELContext used for parsing and evaluating Jakarta Expression Language expressions..
48: */
49: public StandardELContext getELContext() {
50:• if (elContext == null) {
51: elContext = new StandardELContext(getExpressionFactory());
52: }
53:
54: return elContext;
55: }
56:
57: /**
58: * Set the ELContext used for parsing and evaluating Jakarta Expression Language expressions. The supplied ELContext
59: * will not be modified, except for the context object map.
60: *
61: * @param context The new ELContext.
62: * @return The previous ELContext, null if none.
63: */
64: public ELContext setELContext(ELContext context) {
65: ELContext prevELContext = elContext;
66: elContext = new StandardELContext(context);
67: return prevELContext;
68: }
69:
70: /**
71: * Register a BeanNameResolver. Construct a BeanNameELResolver with the BeanNameResolver and add it to the list of
72: * ELResolvers. Once registered, the BeanNameResolver cannot be removed.
73: *
74: * @param beanNameResolver The BeanNameResolver to be registered.
75: */
76: public void addBeanNameResolver(BeanNameResolver beanNameResolver) {
77: getELContext().addELResolver(new BeanNameELResolver(beanNameResolver));
78: }
79:
80: /**
81: * Add an user defined ELResolver to the list of ELResolvers. Can be called multiple times. The new ELResolver is placed
82: * ahead of the default ELResolvers. The list of the ELResolvers added this way are ordered chronologically.
83: *
84: * @param elResolver The ELResolver to be added to the list of ELResolvers in ELContext.
85: * @see StandardELContext#addELResolver
86: */
87: public void addELResolver(ELResolver elResolver) {
88: getELContext().addELResolver(elResolver);
89: }
90:
91: /**
92: * Maps a static method to Jakarta Expression Language function.
93: *
94: * @param prefix The namespace of the functions, can be "".
95: * @param function The name of the function.
96: * @param method The static method to be invoked when the function is used.
97: */
98: public void mapFunction(String prefix, String function, Method method) {
99: getELContext().getFunctionMapper().mapFunction(prefix, function, method);
100: }
101:
102: /**
103: * Assign a ValueExpression to a Jakarta Expression Language variable, replacing any previous assignment to the same
104: * variable. The assignment for the variable is removed if the expression is <code>null</code>.
105: *
106: * @param variable The variable name
107: * @param expression The ValueExpression to be assigned to the variable.
108: */
109: public void setVariable(String variable, ValueExpression expression) {
110: getELContext().getVariableMapper().setVariable(variable, expression);
111: }
112:
113: /**
114: * Import a static field or method. The class of the static member must be loadable from the classloader, at class
115: * resolution time.
116: *
117: * @param staticMemberName The full class name of the class to be imported
118: * @throws ELException if the name is not a full class name.
119: */
120: public void importStatic(String staticMemberName) throws ELException {
121: getELContext().getImportHandler().importStatic(staticMemberName);
122: }
123:
124: /**
125: * Import a class. The imported class must be loadable from the classloader at the expression evaluation time.
126: *
127: * @param className The full class name of the class to be imported
128: * @throws ELException if the name is not a full class name.
129: */
130: public void importClass(String className) throws ELException {
131: getELContext().getImportHandler().importClass(className);
132: }
133:
134: /**
135: * Import a package. At the expression evaluation time, the imported package name will be used to construct the full
136: * class name, which will then be used to load the class. Inherently, this is less efficient than importing a class.
137: *
138: * @param packageName The package name to be imported
139: */
140: public void importPackage(String packageName) {
141: getELContext().getImportHandler().importPackage(packageName);
142: }
143:
144: /**
145: * Define a bean in the local bean repository
146: *
147: * @param name The name of the bean
148: * @param bean The bean instance to be defined. If null, the definition of the bean is removed.
149: * @return the previous bean (if any) mapped to <code>name</code>
150: */
151: public Object defineBean(String name, Object bean) {
152: Object previousBean = getELContext().getBeans().get(name);
153: getELContext().getBeans().put(name, bean);
154: return previousBean;
155: }
156:
157: /**
158: * Register an evaluation listener.
159: *
160: * @param listener The evaluation listener to be added.
161: */
162: public void addEvaluationListener(EvaluationListener listener) {
163: getELContext().addEvaluationListener(listener);
164: }
165: }