public String interpreterCall()

in java/org/apache/jasper/optimizations/ELInterpreterTagSetters.java [73:268]


    public String interpreterCall(JspCompilationContext context, boolean isTagFile, String expression,
            Class<?> expectedType, String fnmapvar) {

        String result = null;

        // Boolean
        if (Boolean.TYPE == expectedType) {
            Matcher m = PATTERN_BOOLEAN.matcher(expression);
            if (m.matches()) {
                result = m.group(2);
            }
        } else if (Boolean.class == expectedType) {
            Matcher m = PATTERN_BOOLEAN.matcher(expression);
            if (m.matches()) {
                if ("true".equals(m.group(2))) {
                    result = "Boolean.TRUE";
                } else {
                    result = "Boolean.FALSE";
                }
            }
            // Character
        } else if (Character.TYPE == expectedType) {
            Matcher m = PATTERN_STRING_CONSTANT.matcher(expression);
            if (m.matches()) {
                return "\'" + m.group(2).charAt(0) + "\'";
            }
        } else if (Character.class == expectedType) {
            Matcher m = PATTERN_STRING_CONSTANT.matcher(expression);
            if (m.matches()) {
                return "Character.valueOf(\'" + m.group(2).charAt(0) + "\')";
            }
            // Numeric - BigDecimal
        } else if (BigDecimal.class == expectedType) {
            Matcher m = PATTERN_NUMERIC.matcher(expression);
            if (m.matches()) {
                try {
                    @SuppressWarnings("unused")
                    BigDecimal unused = new BigDecimal(m.group(2));
                    result = "new java.math.BigDecimal(\"" + m.group(2) + "\")";
                } catch (NumberFormatException e) {
                    log.debug(Localizer.getMessage("jsp.error.typeConversion", m.group(2), "BigDecimal"), e);
                    // Continue and resolve the value at runtime
                }
            }
            // Numeric - long/Long
        } else if (Long.TYPE == expectedType || Long.class == expectedType) {
            Matcher m = PATTERN_NUMERIC.matcher(expression);
            if (m.matches()) {
                try {
                    @SuppressWarnings("unused")
                    Long unused = Long.valueOf(m.group(2));
                    if (expectedType.isPrimitive()) {
                        // Long requires explicit declaration as a long literal
                        result = m.group(2) + "L";
                    } else {
                        result = "Long.valueOf(\"" + m.group(2) + "\")";
                    }
                } catch (NumberFormatException e) {
                    log.debug(Localizer.getMessage("jsp.error.typeConversion", m.group(2), "Long"), e);
                    // Continue and resolve the value at runtime
                }
            }
            // Numeric - int/Integer
        } else if (Integer.TYPE == expectedType || Integer.class == expectedType) {
            Matcher m = PATTERN_NUMERIC.matcher(expression);
            if (m.matches()) {
                try {
                    @SuppressWarnings("unused")
                    Integer unused = Integer.valueOf(m.group(2));
                    if (expectedType.isPrimitive()) {
                        result = m.group(2);
                    } else {
                        result = "Integer.valueOf(\"" + m.group(2) + "\")";
                    }
                } catch (NumberFormatException e) {
                    log.debug(Localizer.getMessage("jsp.error.typeConversion", m.group(2), "Integer"), e);
                    // Continue and resolve the value at runtime
                }
            }
            // Numeric - short/Short
        } else if (Short.TYPE == expectedType || Short.class == expectedType) {
            Matcher m = PATTERN_NUMERIC.matcher(expression);
            if (m.matches()) {
                try {
                    @SuppressWarnings("unused")
                    Short unused = Short.valueOf(m.group(2));
                    if (expectedType.isPrimitive()) {
                        // short requires a downcast
                        result = "(short) " + m.group(2);
                    } else {
                        result = "Short.valueOf(\"" + m.group(2) + "\")";
                    }
                } catch (NumberFormatException e) {
                    log.debug(Localizer.getMessage("jsp.error.typeConversion", m.group(2), "Short"), e);
                    // Continue and resolve the value at runtime
                }
            }
            // Numeric - byte/Byte
        } else if (Byte.TYPE == expectedType || Byte.class == expectedType) {
            Matcher m = PATTERN_NUMERIC.matcher(expression);
            if (m.matches()) {
                try {
                    @SuppressWarnings("unused")
                    Byte unused = Byte.valueOf(m.group(2));
                    if (expectedType.isPrimitive()) {
                        // byte requires a downcast
                        result = "(byte) " + m.group(2);
                    } else {
                        result = "Byte.valueOf(\"" + m.group(2) + "\")";
                    }
                } catch (NumberFormatException e) {
                    log.debug(Localizer.getMessage("jsp.error.typeConversion", m.group(2), "Byte"), e);
                    // Continue and resolve the value at runtime
                }
            }
            // Numeric - double/Double
        } else if (Double.TYPE == expectedType || Double.class == expectedType) {
            Matcher m = PATTERN_NUMERIC.matcher(expression);
            if (m.matches()) {
                try {
                    @SuppressWarnings("unused")
                    Double unused = Double.valueOf(m.group(2));
                    if (expectedType.isPrimitive()) {
                        result = m.group(2);
                    } else {
                        result = "Double.valueOf(\"" + m.group(2) + "\")";
                    }
                } catch (NumberFormatException e) {
                    log.debug(Localizer.getMessage("jsp.error.typeConversion", m.group(2), "Double"), e);
                    // Continue and resolve the value at runtime
                }
            }
            // Numeric - float/Float
        } else if (Float.TYPE == expectedType || Float.class == expectedType) {
            Matcher m = PATTERN_NUMERIC.matcher(expression);
            if (m.matches()) {
                try {
                    @SuppressWarnings("unused")
                    Float unused = Float.valueOf(m.group(2));
                    if (expectedType.isPrimitive()) {
                        // Float requires explicit declaration as a float literal
                        result = m.group(2) + "f";
                    } else {
                        result = "Float.valueOf(\"" + m.group(2) + "\")";
                    }
                } catch (NumberFormatException e) {
                    log.debug(Localizer.getMessage("jsp.error.typeConversion", m.group(2), "Float"), e);
                    // Continue and resolve the value at runtime
                }
            }
            // Numeric - BigInteger
        } else if (BigInteger.class == expectedType) {
            Matcher m = PATTERN_NUMERIC.matcher(expression);
            if (m.matches()) {
                try {
                    @SuppressWarnings("unused")
                    BigInteger unused = new BigInteger(m.group(2));
                    result = "new java.math.BigInteger(\"" + m.group(2) + "\")";
                } catch (NumberFormatException e) {
                    log.debug(Localizer.getMessage("jsp.error.typeConversion", m.group(2), "BigInteger"), e);
                    // Continue and resolve the value at runtime
                }
            }
            // Enum
        } else if (expectedType.isEnum()) {
            Matcher m = PATTERN_STRING_CONSTANT.matcher(expression);
            if (m.matches()) {
                try {
                    @SuppressWarnings({ "unchecked", "rawtypes" })
                    Enum<?> enumValue = Enum.valueOf((Class<? extends Enum>) expectedType, m.group(2));
                    result = expectedType.getName() + "." + enumValue.name();
                } catch (IllegalArgumentException iae) {
                    log.debug(Localizer.getMessage("jsp.error.typeConversion", m.group(2),
                            "Enum[" + expectedType.getName() + "]"), iae);
                    // Continue and resolve the value at runtime
                }
            }
            // String
        } else if (String.class == expectedType) {
            Matcher m = PATTERN_STRING_CONSTANT.matcher(expression);
            if (m.matches()) {
                result = "\"" + m.group(2) + "\"";
            }
        }

        if (result == null) {
            result = JspUtil.interpreterCall(isTagFile, expression, expectedType, fnmapvar);
        }

        if (log.isTraceEnabled()) {
            log.trace(
                    "Expression [" + expression + "], type [" + expectedType.getName() + "], returns [" + result + "]");
        }

        return result;
    }