Skip to content

Package: ImportELResolver

ImportELResolver

nameinstructionbranchcomplexitylinemethod
ImportELResolver()
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%
getCommonPropertyType(ELContext, Object)
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%
getType(ELContext, Object, Object)
M: 8 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getValue(ELContext, Object, Object)
M: 40 C: 0
0%
M: 12 C: 0
0%
M: 7 C: 0
0%
M: 12 C: 0
0%
M: 1 C: 0
0%
isReadOnly(ELContext, Object, Object)
M: 8 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
setValue(ELContext, Object, Object, Object)
M: 7 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * Copyright (c) 2021 Contributors to the Eclipse Foundation.
3: *
4: * This program and the accompanying materials are made available under the
5: * terms of the Eclipse Public License v. 2.0, which is available at
6: * http://www.eclipse.org/legal/epl-2.0.
7: *
8: * This Source Code may also be made available under the following Secondary
9: * Licenses when the conditions for such availability set forth in the
10: * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11: * version 2 with the GNU Classpath Exception, which is available at
12: * https://www.gnu.org/software/classpath/license.html.
13: *
14: * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15: */
16: package jakarta.servlet.jsp.el;
17:
18: import jakarta.el.ELContext;
19: import jakarta.el.ELClass;
20: import jakarta.el.ELResolver;
21: import jakarta.el.ELException;
22:
23: /**
24: * Defines variable resolution behavior for Class imports and static imports.
25: *
26: * @since JSP 3.1
27: */
28: public class ImportELResolver extends ELResolver {
29:
30: /**
31: * If the base object is <code>null</code>, searches the Class and static imports for an import with the given name
32: * and returns it if an import exists with the given name.
33: *
34: * <p>
35: * The <code>propertyResolved</code> property of the <code>ELContext</code> object must be set to <code>true</code>
36: * by this resolver before returning if an import is matched. If this property is not <code>true</code> after this
37: * method is called, the caller should ignore the return value.
38: * </p>
39: *
40: * @param context The context of this evaluation.
41: * @param base Only <code>null</code> is handled by this resolver. Other values will result in an immediate
42: * return.
43: * @param property The name of the import to resolve.
44: * @return If the <code>propertyResolved</code> property of <code>ELContext</code> was set to <code>true</code>,
45: * then the import; otherwise undefined.
46: * @throws NullPointerException if context is <code>null</code>
47: * @throws ELException if an exception was thrown while performing the property or variable resolution. The
48: * thrown exception must be included as the cause property of this exception, if
49: * available.
50: */
51: @Override
52: public Object getValue(ELContext context, Object base, Object property) {
53:
54:• if (context == null) {
55: throw new NullPointerException();
56: }
57:
58: // check to see if the property is an imported class
59:• if (base == null && property instanceof String && context.getImportHandler() != null) {
60: String attribute = (String) property;
61: Object value = null;
62: Class<?> c = context.getImportHandler().resolveClass(attribute);
63:• if (c != null) {
64: value = new ELClass(c);
65: // A possible optimization is to set the ELClass
66: // instance in an attribute map.
67: }
68:• if (value != null) {
69: context.setPropertyResolved(true);
70: }
71: return value;
72: }
73: return null;
74: }
75:
76: /**
77: * Always returns {@code null} since in normal usage {@link ScopedAttributeELResolver} will handle calls to
78: * {@link ELResolver#getType(ELContext, Object, Object)}.
79: *
80: * @param context The context of this evaluation.
81: * @param base Ignored
82: * @param property Ignored
83: * @return Always {@code null}
84: * @throws NullPointerException if context is <code>null</code>
85: * @throws ELException if an exception was thrown while performing the property or variable resolution. The
86: * thrown exception must be included as the cause property of this exception, if
87: * available.
88: */
89: @Override
90: public Class<Object> getType(ELContext context, Object base, Object property) {
91:
92:• if (context == null) {
93: throw new NullPointerException();
94: }
95:
96: return null;
97: }
98:
99: /**
100: * Always a NO-OP since in normal usage {@link ScopedAttributeELResolver} will handle calls to
101: * {@link ELResolver#setValue(ELContext, Object, Object, Object)}.
102: *
103: * @param context The context of this evaluation.
104: * @param base Ignored
105: * @param property Ignored
106: * @param val Ignored
107: * @throws NullPointerException if context is <code>null</code>.
108: * @throws ELException if an exception was thrown while performing the property or variable resolution. The
109: * thrown exception must be included as the cause property of this exception, if
110: * available.
111: */
112: @Override
113: public void setValue(ELContext context, Object base, Object property, Object val) {
114:• if (context == null) {
115: throw new NullPointerException();
116: }
117: }
118:
119: /**
120: * Always returns {@code false} since in normal usage {@link ScopedAttributeELResolver} will handle calls to
121: * {@link ELResolver#isReadOnly(ELContext, Object, Object)}.
122: *
123: * @param context The context of this evaluation.
124: * @param base Ignored
125: * @param property Ignored
126: * @return Always {@code false}
127: * @throws NullPointerException if context is <code>null</code>.
128: * @throws ELException if an exception was thrown while performing the property or variable resolution. The
129: * thrown exception must be included as the cause property of this exception, if
130: * available.
131: */
132: @Override
133: public boolean isReadOnly(ELContext context, Object base, Object property) {
134:• if (context == null) {
135: throw new NullPointerException();
136: }
137: return false;
138: }
139:
140: /**
141: * Always returns {@code null} since in normal usage {@link ScopedAttributeELResolver} will handle calls to
142: * {@link ELResolver#getCommonPropertyType(ELContext, Object)}.
143: *
144: * @param context Ignored
145: * @param base Ignored
146: *
147: * @return Always {@code null}
148: */
149: @Override
150: public Class<String> getCommonPropertyType(ELContext context, Object base) {
151: return null;
152: }
153: }