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%

Coverage

1: /*
2: * Copyright (c) 2013, 2019 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 StandardELContext elContext;
31:
32: /**
33: * Return the ExpressionFactory instance used for Jakarta Expression Language evaluations.
34: *
35: * @return The ExpressionFactory
36: */
37: public static ExpressionFactory getExpressionFactory() {
38: return ELUtil.getExpressionFactory();
39: }
40:
41: /**
42: * Return the ELContext used for parsing and evaluating Jakarta Expression Language expressions. If there is currently
43: * no ELContext, a default instance of StandardELContext is returned.
44: *
45: * @return The ELContext used for parsing and evaluating Jakarta Expression Language expressions..
46: */
47: public StandardELContext getELContext() {
48:• if (elContext == null) {
49: elContext = new StandardELContext(getExpressionFactory());
50: }
51:
52: return elContext;
53: }
54:
55: /**
56: * Set the ELContext used for parsing and evaluating Jakarta Expression Language expressions. The supplied ELContext
57: * will not be modified, except for the context object map.
58: *
59: * @param context The new ELContext.
60: * @return The previous ELContext, null if none.
61: */
62: public ELContext setELContext(ELContext context) {
63: ELContext prevELContext = elContext;
64: elContext = new StandardELContext(context);
65: return prevELContext;
66: }
67:
68: /**
69: * Register a BeanNameResolver. Construct a BeanNameELResolver with the BeanNameResolver and add it to the list of
70: * ELResolvers. Once registered, the BeanNameResolver cannot be removed.
71: *
72: * @param beanNameResolver The BeanNameResolver to be registered.
73: */
74: public void addBeanNameResolver(BeanNameResolver beanNameResolver) {
75: getELContext().addELResolver(new BeanNameELResolver(beanNameResolver));
76: }
77:
78: /**
79: * Add an user defined ELResolver to the list of ELResolvers. Can be called multiple times. The new ELResolver is placed
80: * ahead of the default ELResolvers. The list of the ELResolvers added this way are ordered chronologically.
81: *
82: * @param elResolver The ELResolver to be added to the list of ELResolvers in ELContext.
83: * @see StandardELContext#addELResolver
84: */
85: public void addELResolver(ELResolver elResolver) {
86: getELContext().addELResolver(elResolver);
87: }
88:
89: /**
90: * Maps a static method to Jakarta Expression Language function.
91: *
92: * @param prefix The namespace of the functions, can be "".
93: * @param function The name of the function.
94: * @param method The static method to be invoked when the function is used.
95: */
96: public void mapFunction(String prefix, String function, Method method) {
97: getELContext().getFunctionMapper().mapFunction(prefix, function, method);
98: }
99:
100: /**
101: * Assign a ValueExpression to a Jakarta Expression Language variable, replacing any previous assignment to the same
102: * variable. The assignment for the variable is removed if the expression is <code>null</code>.
103: *
104: * @param variable The variable name
105: * @param expression The ValueExpression to be assigned to the variable.
106: */
107: public void setVariable(String variable, ValueExpression expression) {
108: getELContext().getVariableMapper().setVariable(variable, expression);
109: }
110:
111: /**
112: * Import a static field or method. The class of the static member must be loadable from the classloader, at class
113: * resolution time.
114: *
115: * @param staticMemberName The full class name of the class to be imported
116: * @throws ELException if the name is not a full class name.
117: */
118: public void importStatic(String staticMemberName) throws ELException {
119: getELContext().getImportHandler().importStatic(staticMemberName);
120: }
121:
122: /**
123: * Import a class. The imported class must be loadable from the classloader at the expression evaluation time.
124: *
125: * @param className The full class name of the class to be imported
126: * @throws ELException if the name is not a full class name.
127: */
128: public void importClass(String className) throws ELException {
129: getELContext().getImportHandler().importClass(className);
130: }
131:
132: /**
133: * Import a package. At the expression evaluation time, the imported package name will be used to construct the full
134: * class name, which will then be used to load the class. Inherently, this is less efficient than importing a class.
135: *
136: * @param packageName The package name to be imported
137: */
138: public void importPackage(String packageName) {
139: getELContext().getImportHandler().importPackage(packageName);
140: }
141:
142: /**
143: * Define a bean in the local bean repository
144: *
145: * @param name The name of the bean
146: * @param bean The bean instance to be defined. If null, the definition of the bean is removed.
147: * @return the previous bean (if any) mapped to <code>name</code>
148: */
149: public Object defineBean(String name, Object bean) {
150: Object previousBean = getELContext().getBeans().get(name);
151: getELContext().getBeans().put(name, bean);
152: return previousBean;
153: }
154:
155: /**
156: * Register an evaluation listener.
157: *
158: * @param listener The evaluation listener to be added.
159: */
160: public void addEvaluationListener(EvaluationListener listener) {
161: getELContext().addEvaluationListener(listener);
162: }
163: }