jakarta.servlet.jsp.el.ImportELResolver Maven / Gradle / Ivy
/*
* Copyright (c) 2021 Contributors to the Eclipse Foundation.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package jakarta.servlet.jsp.el;
import jakarta.el.ELContext;
import jakarta.el.ELClass;
import jakarta.el.ELResolver;
import jakarta.el.ELException;
/**
* Defines variable resolution behavior for Class imports and static imports.
*
* @since JSP 3.1
*/
public class ImportELResolver extends ELResolver {
/**
* If the base object is null
, searches the Class and static imports for an import with the given name
* and returns it if an import exists with the given name.
*
*
* The propertyResolved
property of the ELContext
object must be set to true
* by this resolver before returning if an import is matched. If this property is not true
after this
* method is called, the caller should ignore the return value.
*
*
* @param context The context of this evaluation.
* @param base Only null
is handled by this resolver. Other values will result in an immediate
* return.
* @param property The name of the import to resolve.
* @return If the propertyResolved
property of ELContext
was set to true
,
* then the import; otherwise undefined.
* @throws NullPointerException if context is null
* @throws ELException if an exception was thrown while performing the property or variable resolution. The
* thrown exception must be included as the cause property of this exception, if
* available.
*/
@Override
public Object getValue(ELContext context, Object base, Object property) {
if (context == null) {
throw new NullPointerException();
}
// check to see if the property is an imported class
if (base == null && property instanceof String && context.getImportHandler() != null) {
String attribute = (String) property;
Object value = null;
Class> c = context.getImportHandler().resolveClass(attribute);
if (c != null) {
value = new ELClass(c);
// A possible optimization is to set the ELClass
// instance in an attribute map.
}
if (value != null) {
context.setPropertyResolved(true);
}
return value;
}
return null;
}
/**
* Always returns {@code null} since in normal usage {@link ScopedAttributeELResolver} will handle calls to
* {@link ELResolver#getType(ELContext, Object, Object)}.
*
* @param context The context of this evaluation.
* @param base Ignored
* @param property Ignored
* @return Always {@code null}
* @throws NullPointerException if context is null
* @throws ELException if an exception was thrown while performing the property or variable resolution. The
* thrown exception must be included as the cause property of this exception, if
* available.
*/
@Override
public Class
© 2015 - 2024 Weber Informatics LLC | Privacy Policy