Skip to content

Commit

Permalink
Refactor creation of ExpressionFactory
Browse files Browse the repository at this point in the history
ELUtil doesn't require a factory for all operations whereas the
ELManager does. Moving construction of the factory to the ELManager
allows some limited unit testing of ELUtil without placing additional
limits on how ELManager can be used.
  • Loading branch information
markt-asf committed Jun 20, 2022
1 parent ac8ab39 commit 460c25e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
4 changes: 2 additions & 2 deletions api/src/main/java/jakarta/el/ELContext.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2021 Oracle and/or its affiliates and others.
* Copyright (c) 1997, 2022 Oracle and/or its affiliates and others.
* All rights reserved.
* Copyright 2004 The Apache Software Foundation
*
Expand Down Expand Up @@ -439,7 +439,7 @@ public <T> T convertToType(Object obj, Class<T> targetType) {

ExpressionFactory exprFactory = (ExpressionFactory) getContext(ExpressionFactory.class);
if (exprFactory == null) {
exprFactory = ELUtil.getExpressionFactory();
exprFactory = ELManager.getExpressionFactory();
}

return exprFactory.coerceToType(obj, targetType);
Expand Down
6 changes: 4 additions & 2 deletions api/src/main/java/jakarta/el/ELManager.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2019 Oracle and/or its affiliates and others.
* Copyright (c) 2013, 2022 Oracle and/or its affiliates and others.
* All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -27,6 +27,8 @@
*/
public class ELManager {

private static ExpressionFactory exprFactory = ExpressionFactory.newInstance();

private StandardELContext elContext;

/**
Expand All @@ -35,7 +37,7 @@ public class ELManager {
* @return The ExpressionFactory
*/
public static ExpressionFactory getExpressionFactory() {
return ELUtil.getExpressionFactory();
return exprFactory;
}

/**
Expand Down
8 changes: 1 addition & 7 deletions api/src/main/java/jakarta/el/ELUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ class ELUtil {
private ELUtil() {
}

public static ExpressionFactory exprFactory = ExpressionFactory.newInstance();

/**
* <p>
* The <code>ThreadLocal</code> variable used to record the <code>jakarta.faces.context.FacesContext</code> instance for
Expand Down Expand Up @@ -161,10 +159,6 @@ public static String getExceptionMessageString(ELContext context, String message
return result;
}

static ExpressionFactory getExpressionFactory() {
return exprFactory;
}

static Constructor<?> findConstructor(Class<?> klass, Class<?>[] paramTypes, Object[] params) {
String methodName = "<init>";

Expand Down Expand Up @@ -533,7 +527,7 @@ private static boolean isCoercibleFrom(Object src, Class<?> target) {
// TODO: This isn't pretty but it works. Significant refactoring would
// be required to avoid the exception.
try {
getExpressionFactory().coerceToType(src, target);
ELManager.getExpressionFactory().coerceToType(src, target);
} catch (Exception e) {
return false;
}
Expand Down

0 comments on commit 460c25e

Please sign in to comment.