/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.
*/ package jakarta.el;
/** * Create a new {@link ExpressionFactory}. The class to use is determined by the following search order: * <ol> * <li>services API (META-INF/services/jakarta.el.ExpressionFactory)</li> * <li>$JRE_HOME/lib/el.properties - key jakarta.el.ExpressionFactory</li> * <li>jakarta.el.ExpressionFactory</li> * <li>Platform default implementation - org.apache.el.ExpressionFactoryImpl</li> * </ol> * * @return the new ExpressionFactory
*/ publicstatic ExpressionFactory newInstance() { return newInstance(null);
}
/** * Create a new {@link ExpressionFactory} passing in the provided {@link Properties}. Search order is the same as * {@link #newInstance()}. * * @param properties the properties to be passed to the new instance (may be null) * * @return the new ExpressionFactory
*/ publicstatic ExpressionFactory newInstance(Properties properties) {
ExpressionFactory result = null;
ClassLoader tccl = Util.getContextClassLoader();
CacheValue cacheValue; Class<?> clazz;
if (tccl == null) {
cacheValue = nullTcclFactory;
} else {
CacheKey key = new CacheKey(tccl);
cacheValue = factoryCache.get(key); if (cacheValue == null) {
CacheValue newCacheValue = new CacheValue();
cacheValue = factoryCache.putIfAbsent(key, newCacheValue); if (cacheValue == null) {
cacheValue = newCacheValue;
}
}
}
try {
Constructor<?> constructor = null; // Do we need to look for a constructor that will take properties? if (properties != null) { try {
constructor = clazz.getConstructor(Properties.class);
} catch (SecurityException se) { thrownew ELException(se);
} catch (NoSuchMethodException nsme) { // This can be ignored // This is OK for this constructor not to exist
}
} if (constructor == null) {
result = (ExpressionFactory) clazz.getConstructor().newInstance();
} else {
result = (ExpressionFactory) constructor.newInstance(properties);
}
/** * Create a new value expression. * * @param context The EL context for this evaluation * @param expression The String representation of the value expression * @param expectedType The expected type of the result of evaluating the expression * * @return A new value expression formed from the input parameters * * @throws NullPointerException If the expected type is <code>null</code> * @throws ELException If there are syntax errors in the provided expression
*/ publicabstract ValueExpression createValueExpression(ELContext context, String expression, Class<?> expectedType);
/** * Create a new method expression instance. * * @param context The EL context for this evaluation * @param expression The String representation of the method expression * @param expectedReturnType The expected type of the result of invoking the method * @param expectedParamTypes The expected types of the input parameters * * @return A new method expression formed from the input parameters. * * @throws NullPointerException If the expected parameters types are <code>null</code> * @throws ELException If there are syntax errors in the provided expression
*/ publicabstract MethodExpression createMethodExpression(ELContext context, String expression, Class<?> expectedReturnType, Class<?>[] expectedParamTypes);
/** * Coerce the supplied object to the requested type. * * @param <T> The type to which the object should be coerced * @param obj The object to be coerced * @param expectedType The type to which the object should be coerced * * @return An instance of the requested type. * * @throws ELException If the conversion fails
*/ publicabstract <T> T coerceToType(Object obj, Class<T> expectedType);
/** * @return This default implementation returns null * * @since EL 3.0
*/ public ELResolver getStreamELResolver() { returnnull;
}
/** * @return This default implementation returns null * * @since EL 3.0
*/ public Map<String,Method> getInitFunctionMap() { returnnull;
}
/** * Key used to cache ExpressionFactory discovery information per class loader. The class loader reference is never * {@code null}, because {@code null} tccl is handled separately.
*/ privatestaticclass CacheKey { privatefinalint hash; privatefinal WeakReference<ClassLoader> ref;
publicvoid setFactoryClass(Class<?> clazz) {
ref = new WeakReference<>(clazz);
}
}
/** * Discover the name of class that implements ExpressionFactory. * * @param tccl {@code ClassLoader} * * @return Class name. There is default, so it is never {@code null}.
*/ privatestatic String discoverClassName(ClassLoader tccl) {
String className = null;
// First services API
className = getClassNameServices(tccl); if (className == null) { if (IS_SECURITY_ENABLED) {
className =
AccessController.doPrivileged((PrivilegedAction<String>) ExpressionFactory::getClassNameJreDir);
} else { // Second el.properties file
className = getClassNameJreDir();
}
} if (className == null) { if (IS_SECURITY_ENABLED) {
className = AccessController
.doPrivileged((PrivilegedAction<String>) ExpressionFactory::getClassNameSysProp);
} else { // Third system property
className = getClassNameSysProp();
}
} if (className == null) { // Fourth - default
className = "org.apache.el.ExpressionFactoryImpl";
} return className;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.