Skip to content

Package: ExpressionFactoryImpl

ExpressionFactoryImpl

nameinstructionbranchcomplexitylinemethod
ExpressionFactoryImpl()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
ExpressionFactoryImpl(Properties)
M: 13 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
coerceToType(Object, Class)
M: 12 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
createMethodExpression(ELContext, String, Class, Class[])
M: 22 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
createValueExpression(ELContext, String, Class)
M: 16 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
createValueExpression(Object, Class)
M: 14 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getInitFunctionMap()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getProperty(String)
M: 10 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getStreamELResolver()
M: 4 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) 1997, 2021 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 com.sun.el;
19:
20: import java.lang.reflect.Method;
21: import java.util.HashMap;
22: import java.util.Map;
23: import java.util.Properties;
24:
25: import jakarta.el.ELContext;
26: import jakarta.el.ELException;
27: import jakarta.el.ELResolver;
28: import jakarta.el.ExpressionFactory;
29: import jakarta.el.MethodExpression;
30: import jakarta.el.ValueExpression;
31:
32: import com.sun.el.lang.ELSupport;
33: import com.sun.el.lang.ExpressionBuilder;
34: import com.sun.el.stream.StreamELResolver;
35: import com.sun.el.util.MessageFactory;
36:
37: /**
38: * @see ExpressionFactory
39: *
40: * @author Jacob Hookom [jacob@hookom.net]
41: * @author Kin-man Chung
42: * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author: kchung $
43: */
44: public class ExpressionFactoryImpl extends ExpressionFactory {
45:
46: private Properties properties;
47: private boolean isBackwardCompatible22;
48:
49: public ExpressionFactoryImpl() {
50: super();
51: }
52:
53: public ExpressionFactoryImpl(Properties properties) {
54: super();
55: this.properties = properties;
56: this.isBackwardCompatible22 = "true".equals(getProperty("jakarta.el.bc2.2"));
57: }
58:
59: /**
60: * Coerces an object to a specific type according to the Jakarta Expression Language type conversion rules. The custom
61: * type conversions in the <code>ELResolver</code>s are not considered.
62: *
63: * Jakarta Expression Language version 2.2 backward compatibility conversion rules apply if ExpressionFactoryImpl was created with property
64: * "jakarta.el.bc2.2" set to true.
65: */
66: @Override
67: public <T> T coerceToType(Object obj, Class<T> type) {
68: try {
69: return ELSupport.coerceToType(obj, type, isBackwardCompatible22);
70: } catch (IllegalArgumentException ex) {
71: throw new ELException(ex);
72: }
73: }
74:
75: @Override
76: public MethodExpression createMethodExpression(ELContext context, String expression, Class<?> expectedReturnType, Class<?>[] expectedParamTypes) {
77: MethodExpression methodExpression =
78: new ExpressionBuilder(expression, context)
79: .createMethodExpression(expectedReturnType, expectedParamTypes);
80:
81:• if (expectedParamTypes == null && !methodExpression.isParametersProvided()) {
82: throw new NullPointerException(MessageFactory.get("error.method.nullParms"));
83: }
84:
85: return methodExpression;
86: }
87:
88: @Override
89: public ValueExpression createValueExpression(ELContext context, String expression, Class<?> expectedType) {
90:• if (expectedType == null) {
91: throw new NullPointerException(MessageFactory.get("error.value.expectedType"));
92: }
93:
94: return new ExpressionBuilder(expression, context).createValueExpression(expectedType);
95: }
96:
97: @Override
98: public ValueExpression createValueExpression(Object instance, Class<?> expectedType) {
99:• if (expectedType == null) {
100: throw new NullPointerException(MessageFactory.get("error.value.expectedType"));
101: }
102:
103: return new ValueExpressionLiteral(instance, expectedType);
104: }
105:
106: public String getProperty(String key) {
107:• if (properties == null) {
108: return null;
109: }
110:
111: return properties.getProperty(key);
112: }
113:
114: @Override
115: public ELResolver getStreamELResolver() {
116: return new StreamELResolver();
117: }
118:
119: @Override
120: public Map<String, Method> getInitFunctionMap() {
121: return new HashMap<String, Method>();
122: }
123: }