org.apache.commons.el_1.0.0.v201101211617

16:40:59.525 INFO  jd.cli.Main - Decompiling org.apache.commons.el_1.0.0.v201101211617.jar
package org.apache.commons.el;

import javax.servlet.jsp.el.ELException;

public class AndOperator
  extends BinaryOperator
{
  public static final AndOperator SINGLETON = new AndOperator();
  
  public String getOperatorSymbol()
  {
    return "and";
  }
  
  public Object apply(Object pLeft, Object pRight, Logger pLogger)
    throws ELException
  {
    boolean left = Coercions.coerceToBoolean(pLeft, pLogger).booleanValue();
    
    boolean right = Coercions.coerceToBoolean(pRight, pLogger).booleanValue();
    
    return PrimitiveObjects.getBoolean((left) && (right));
  }
  
  public boolean shouldEvaluate(Object pLeft)
  {
    return ((pLeft instanceof Boolean)) && (((Boolean)pLeft).booleanValue() == true);
  }
  
  public boolean shouldCoerceToBoolean()
  {
    return true;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.el.AndOperator
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.el;

import java.math.BigDecimal;
import java.math.BigInteger;
import javax.servlet.jsp.el.ELException;

public abstract class ArithmeticOperator
  extends BinaryOperator
{
  public Object apply(Object pLeft, Object pRight, Logger pLogger)
    throws ELException
  {
    return Coercions.applyArithmeticOperator(pLeft, pRight, this, pLogger);
  }
  
  public abstract double apply(double paramDouble1, double paramDouble2);
  
  public abstract long apply(long paramLong1, long paramLong2);
  
  public abstract BigDecimal apply(BigDecimal paramBigDecimal1, BigDecimal paramBigDecimal2);
  
  public abstract BigInteger apply(BigInteger paramBigInteger1, BigInteger paramBigInteger2);
}

/* Location:
 * Qualified Name:     org.apache.commons.el.ArithmeticOperator
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.el;

import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Map;
import javax.servlet.jsp.el.ELException;
import javax.servlet.jsp.el.FunctionMapper;
import javax.servlet.jsp.el.VariableResolver;

public class ArraySuffix
  extends ValueSuffix
{
  static Object[] sNoArgs = new Object[0];
  Expression mIndex;
  
  public Expression getIndex()
  {
    return mIndex;
  }
  
  public void setIndex(Expression pIndex)
  {
    mIndex = pIndex;
  }
  
  public ArraySuffix(Expression pIndex)
  {
    mIndex = pIndex;
  }
  
  Object evaluateIndex(VariableResolver pResolver, FunctionMapper functions, Logger pLogger)
    throws ELException
  {
    return mIndex.evaluate(pResolver, functions, pLogger);
  }
  
  String getOperatorSymbol()
  {
    return "[]";
  }
  
  public String getExpressionString()
  {
    return "[" + mIndex.getExpressionString() + "]";
  }
  
  public Object evaluate(Object pValue, VariableResolver pResolver, FunctionMapper functions, Logger pLogger)
    throws ELException
  {
    if (pValue == null)
    {
      if (pLogger.isLoggingWarning()) {
        pLogger.logWarning(Constants.CANT_GET_INDEXED_VALUE_OF_NULL, getOperatorSymbol());
      }
      return null;
    }
    Object indexVal;
    if ((indexVal = evaluateIndex(pResolver, functions, pLogger)) == null)
    {
      if (pLogger.isLoggingWarning()) {
        pLogger.logWarning(Constants.CANT_GET_NULL_INDEX, getOperatorSymbol());
      }
      return null;
    }
    if ((pValue instanceof Map))
    {
      Map val = (Map)pValue;
      return val.get(indexVal);
    }
    if (((pValue instanceof List)) || (pValue.getClass().isArray()))
    {
      Integer indexObj = Coercions.coerceToInteger(indexVal, pLogger);
      if (indexObj == null)
      {
        if (pLogger.isLoggingError()) {
          pLogger.logError(Constants.BAD_INDEX_VALUE, getOperatorSymbol(), indexVal.getClass().getName());
        }
        return null;
      }
      if ((pValue instanceof List)) {
        try
        {
          return ((List)pValue).get(indexObj.intValue());
        }
        catch (ArrayIndexOutOfBoundsException exc)
        {
          if (pLogger.isLoggingWarning()) {
            pLogger.logWarning(Constants.EXCEPTION_ACCESSING_LIST, exc, indexObj);
          }
          return null;
        }
        catch (IndexOutOfBoundsException exc)
        {
          if (pLogger.isLoggingWarning()) {
            pLogger.logWarning(Constants.EXCEPTION_ACCESSING_LIST, exc, indexObj);
          }
          return null;
        }
        catch (Exception exc)
        {
          if (pLogger.isLoggingError()) {
            pLogger.logError(Constants.EXCEPTION_ACCESSING_LIST, exc, indexObj);
          }
          return null;
        }
      }
      try
      {
        return Array.get(pValue, indexObj.intValue());
      }
      catch (ArrayIndexOutOfBoundsException exc)
      {
        if (pLogger.isLoggingWarning()) {
          pLogger.logWarning(Constants.EXCEPTION_ACCESSING_ARRAY, exc, indexObj);
        }
        return null;
      }
      catch (IndexOutOfBoundsException exc)
      {
        if (pLogger.isLoggingWarning()) {
          pLogger.logWarning(Constants.EXCEPTION_ACCESSING_ARRAY, exc, indexObj);
        }
        return null;
      }
      catch (Exception exc)
      {
        if (pLogger.isLoggingError()) {
          pLogger.logError(Constants.EXCEPTION_ACCESSING_ARRAY, exc, indexObj);
        }
        return null;
      }
    }
    String indexStr;
    if ((indexStr = Coercions.coerceToString(indexVal, pLogger)) == null) {
      return null;
    }
    BeanInfoProperty property;
    if (((property = BeanInfoManager.getBeanInfoProperty(pValue.getClass(), indexStr, pLogger)) != null) && (property.getReadMethod() != null)) {
      try
      {
        return property.getReadMethod().invoke(pValue, sNoArgs);
      }
      catch (InvocationTargetException exc)
      {
        if (pLogger.isLoggingError()) {
          pLogger.logError(Constants.ERROR_GETTING_PROPERTY, exc.getTargetException(), indexStr, pValue.getClass().getName());
        }
        return null;
      }
      catch (Exception exc)
      {
        if (pLogger.isLoggingError()) {
          pLogger.logError(Constants.ERROR_GETTING_PROPERTY, exc, indexStr, pValue.getClass().getName());
        }
        return null;
      }
    }
    if (pLogger.isLoggingError()) {
      pLogger.logError(Constants.CANT_FIND_INDEX, indexVal, pValue.getClass().getName(), getOperatorSymbol());
    }
    return null;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.el.ArraySuffix
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.el;

import java.beans.IndexedPropertyDescriptor;
import java.lang.reflect.Method;

public class BeanInfoIndexedProperty
{
  Method mReadMethod;
  Method mWriteMethod;
  IndexedPropertyDescriptor mIndexedPropertyDescriptor;
  
  public Method getReadMethod()
  {
    return mReadMethod;
  }
  
  public Method getWriteMethod()
  {
    return mWriteMethod;
  }
  
  public IndexedPropertyDescriptor getIndexedPropertyDescriptor()
  {
    return mIndexedPropertyDescriptor;
  }
  
  public BeanInfoIndexedProperty(Method pReadMethod, Method pWriteMethod, IndexedPropertyDescriptor pIndexedPropertyDescriptor)
  {
    mReadMethod = pReadMethod;
    mWriteMethod = pWriteMethod;
    mIndexedPropertyDescriptor = pIndexedPropertyDescriptor;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.el.BeanInfoIndexedProperty
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.el;

import java.beans.BeanInfo;
import java.beans.EventSetDescriptor;
import java.beans.IndexedPropertyDescriptor;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.security.AccessControlException;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.jsp.el.ELException;

public class BeanInfoManager
{
  Class mBeanClass;
  BeanInfo mBeanInfo;
  Map mPropertyByName;
  Map mIndexedPropertyByName;
  Map mEventSetByName;
  boolean mInitialized;
  
  public Class getBeanClass()
  {
    return mBeanClass;
  }
  
  static Map mBeanInfoManagerByClass = new HashMap();
  
  BeanInfoManager(Class pBeanClass)
  {
    mBeanClass = pBeanClass;
  }
  
  public static BeanInfoManager getBeanInfoManager(Class pClass)
  {
    BeanInfoManager ret = (BeanInfoManager)mBeanInfoManagerByClass.get(pClass);
    if (ret == null) {
      ret = createBeanInfoManager(pClass);
    }
    return ret;
  }
  
  static synchronized BeanInfoManager createBeanInfoManager(Class pClass)
  {
    BeanInfoManager ret = (BeanInfoManager)mBeanInfoManagerByClass.get(pClass);
    if (ret == null)
    {
      ret = new BeanInfoManager(pClass);
      mBeanInfoManagerByClass.put(pClass, ret);
    }
    return ret;
  }
  
  public static BeanInfoProperty getBeanInfoProperty(Class pClass, String pPropertyName, Logger pLogger)
    throws ELException
  {
    return getBeanInfoManager(pClass).getProperty(pPropertyName, pLogger);
  }
  
  public static BeanInfoIndexedProperty getBeanInfoIndexedProperty(Class pClass, String pIndexedPropertyName, Logger pLogger)
    throws ELException
  {
    return getBeanInfoManager(pClass).getIndexedProperty(pIndexedPropertyName, pLogger);
  }
  
  void checkInitialized(Logger pLogger)
    throws ELException
  {
    if (!mInitialized) {
      synchronized (this)
      {
        if (!mInitialized)
        {
          initialize(pLogger);
          mInitialized = true;
        }
      }
    }
  }
  
  void initialize(Logger pLogger)
    throws ELException
  {
    try
    {
      mBeanInfo = Introspector.getBeanInfo(mBeanClass);
      
      mPropertyByName = new HashMap();
      mIndexedPropertyByName = new HashMap();
      PropertyDescriptor[] pds = mBeanInfo.getPropertyDescriptors();
      for (int i = 0; (pds != null) && (i < pds.length); i++)
      {
        PropertyDescriptor pd = pds[i];
        if ((pd instanceof IndexedPropertyDescriptor))
        {
          IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor)pd;
          Method readMethod = getPublicMethod(ipd.getIndexedReadMethod());
          Method writeMethod = getPublicMethod(ipd.getIndexedWriteMethod());
          BeanInfoIndexedProperty property = new BeanInfoIndexedProperty(readMethod, writeMethod, ipd);
          
          mIndexedPropertyByName.put(ipd.getName(), property);
        }
        Method readMethod = getPublicMethod(pd.getReadMethod());
        Method writeMethod = getPublicMethod(pd.getWriteMethod());
        BeanInfoProperty property = new BeanInfoProperty(readMethod, writeMethod, pd);
        
        mPropertyByName.put(pd.getName(), property);
      }
      mEventSetByName = new HashMap();
      EventSetDescriptor[] esds = mBeanInfo.getEventSetDescriptors();
      int i = 0;
      do
      {
        EventSetDescriptor esd = esds[i];
        mEventSetByName.put(esd.getName(), esd);i++;
        if (esds == null) {
          break;
        }
      } while (i < esds.length);
    }
    catch (IntrospectionException exc)
    {
      if (pLogger.isLoggingWarning()) {
        pLogger.logWarning(Constants.EXCEPTION_GETTING_BEANINFO, exc, mBeanClass.getName());
      }
    }
  }
  
  BeanInfo getBeanInfo(Logger pLogger)
    throws ELException
  {
    checkInitialized(pLogger);
    return mBeanInfo;
  }
  
  public BeanInfoProperty getProperty(String pPropertyName, Logger pLogger)
    throws ELException
  {
    checkInitialized(pLogger);
    return (BeanInfoProperty)mPropertyByName.get(pPropertyName);
  }
  
  public BeanInfoIndexedProperty getIndexedProperty(String pIndexedPropertyName, Logger pLogger)
    throws ELException
  {
    checkInitialized(pLogger);
    return (BeanInfoIndexedProperty)mIndexedPropertyByName.get(pIndexedPropertyName);
  }
  
  public EventSetDescriptor getEventSet(String pEventSetName, Logger pLogger)
    throws ELException
  {
    checkInitialized(pLogger);
    return (EventSetDescriptor)mEventSetByName.get(pEventSetName);
  }
  
  static Method getPublicMethod(Method pMethod)
  {
    if (pMethod == null) {
      return null;
    }
    Class cl = pMethod.getDeclaringClass();
    if (Modifier.isPublic(cl.getModifiers())) {
      return pMethod;
    }
    Method ret = getPublicMethod(cl, pMethod);
    if (ret != null) {
      return ret;
    }
    return pMethod;
  }
  
  static Method getPublicMethod(Class pClass, Method pMethod)
  {
    if (Modifier.isPublic(pClass.getModifiers())) {
      try
      {
        Method m;
        try
        {
          m = pClass.getDeclaredMethod(pMethod.getName(), pMethod.getParameterTypes());
        }
        catch (AccessControlException ex)
        {
          m = pClass.getMethod(pMethod.getName(), pMethod.getParameterTypes());
        }
        if (Modifier.isPublic(m.getModifiers())) {
          return m;
        }
      }
      catch (NoSuchMethodException exc) {}
    }
    Class[] interfaces = pClass.getInterfaces();
    if (interfaces != null) {
      for (int i = 0; i < interfaces.length; i++)
      {
        Method m = getPublicMethod(interfaces[i], pMethod);
        if (m != null) {
          return m;
        }
      }
    }
    Class superclass = pClass.getSuperclass();
    if (superclass != null)
    {
      Method m = getPublicMethod(superclass, pMethod);
      if (m != null) {
        return m;
      }
    }
    return null;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.el.BeanInfoManager
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.el;

import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;

public class BeanInfoProperty
{
  Method mReadMethod;
  Method mWriteMethod;
  PropertyDescriptor mPropertyDescriptor;
  
  public Method getReadMethod()
  {
    return mReadMethod;
  }
  
  public Method getWriteMethod()
  {
    return mWriteMethod;
  }
  
  public PropertyDescriptor getPropertyDescriptor()
  {
    return mPropertyDescriptor;
  }
  
  public BeanInfoProperty(Method pReadMethod, Method pWriteMethod, PropertyDescriptor pPropertyDescriptor)
  {
    mReadMethod = pReadMethod;
    mWriteMethod = pWriteMethod;
    mPropertyDescriptor = pPropertyDescriptor;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.el.BeanInfoProperty
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.el;

import javax.servlet.jsp.el.ELException;

public abstract class BinaryOperator
{
  public abstract String getOperatorSymbol();
  
  public abstract Object apply(Object paramObject1, Object paramObject2, Logger paramLogger)
    throws ELException;
  
  public boolean shouldEvaluate(Object pLeft)
  {
    return true;
  }
  
  public boolean shouldCoerceToBoolean()
  {
    return false;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.el.BinaryOperator
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.el;

import java.util.List;
import javax.servlet.jsp.el.ELException;
import javax.servlet.jsp.el.FunctionMapper;
import javax.servlet.jsp.el.VariableResolver;

public class BinaryOperatorExpression
  extends Expression
{
  Expression mExpression;
  List mOperators;
  List mExpressions;
  
  public Expression getExpression()
  {
    return mExpression;
  }
  
  public void setExpression(Expression pExpression)
  {
    mExpression = pExpression;
  }
  
  public List getOperators()
  {
    return mOperators;
  }
  
  public void setOperators(List pOperators)
  {
    mOperators = pOperators;
  }
  
  public List getExpressions()
  {
    return mExpressions;
  }
  
  public void setExpressions(List pExpressions)
  {
    mExpressions = pExpressions;
  }
  
  public BinaryOperatorExpression(Expression pExpression, List pOperators, List pExpressions)
  {
    mExpression = pExpression;
    mOperators = pOperators;
    mExpressions = pExpressions;
  }
  
  public String getExpressionString()
  {
    StringBuffer buf = new StringBuffer();
    buf.append("(");
    buf.append(mExpression.getExpressionString());
    for (int i = 0; i < mOperators.size(); i++)
    {
      BinaryOperator operator = (BinaryOperator)mOperators.get(i);
      Expression expression = (Expression)mExpressions.get(i);
      buf.append(" ");
      buf.append(operator.getOperatorSymbol());
      buf.append(" ");
      buf.append(expression.getExpressionString());
    }
    buf.append(")");
    
    return buf.toString();
  }
  
  public Object evaluate(VariableResolver pResolver, FunctionMapper functions, Logger pLogger)
    throws ELException
  {
    Object value = mExpression.evaluate(pResolver, functions, pLogger);
    for (int i = 0; i < mOperators.size(); i++)
    {
      BinaryOperator operator = (BinaryOperator)mOperators.get(i);
      if (operator.shouldCoerceToBoolean()) {
        value = Coercions.coerceToBoolean(value, pLogger);
      }
      if (operator.shouldEvaluate(value))
      {
        Expression expression = (Expression)mExpressions.get(i);
        Object nextValue = expression.evaluate(pResolver, functions, pLogger);
        
        value = operator.apply(value, nextValue, pLogger);
      }
    }
    return value;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.el.BinaryOperatorExpression
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.el;

public class BooleanLiteral
  extends Literal
{
  public static final BooleanLiteral TRUE = new BooleanLiteral("true");
  public static final BooleanLiteral FALSE = new BooleanLiteral("false");
  
  public BooleanLiteral(String pToken)
  {
    super(getValueFromToken(pToken));
  }
  
  static Object getValueFromToken(String pToken)
  {
    return "true".equals(pToken) ? Boolean.TRUE : Boolean.FALSE;
  }
  
  public String getExpressionString()
  {
    return getValue() == Boolean.TRUE ? "true" : "false";
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.el.BooleanLiteral
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.el;

import java.beans.PropertyEditor;
import java.beans.PropertyEditorManager;
import java.math.BigDecimal;
import java.math.BigInteger;
import javax.servlet.jsp.el.ELException;

public class Coercions
{
  private static final Number ZERO = new Integer(0);
  
  public static Object coerce(Object pValue, Class pClass, Logger pLogger)
    throws ELException
  {
    if (pClass == String.class) {
      return coerceToString(pValue, pLogger);
    }
    if (isNumberClass(pClass)) {
      return coerceToPrimitiveNumber(pValue, pClass, pLogger);
    }
    if ((pClass == Character.class) || (pClass == Character.TYPE)) {
      return coerceToCharacter(pValue, pLogger);
    }
    if ((pClass == Boolean.class) || (pClass == Boolean.TYPE)) {
      return coerceToBoolean(pValue, pLogger);
    }
    return coerceToObject(pValue, pClass, pLogger);
  }
  
  static boolean isNumberClass(Class pClass)
  {
    return (pClass == Byte.class) || (pClass == Byte.TYPE) || (pClass == Short.class) || (pClass == Short.TYPE) || (pClass == Integer.class) || (pClass == Integer.TYPE) || (pClass == Long.class) || (pClass == Long.TYPE) || (pClass == Float.class) || (pClass == Float.TYPE) || (pClass == Double.class) || (pClass == Double.TYPE) || (pClass == BigInteger.class) || (pClass == BigDecimal.class);
  }
  
  public static String coerceToString(Object pValue, Logger pLogger)
    throws ELException
  {
    if (pValue == null) {
      return "";
    }
    if ((pValue instanceof String)) {
      return (String)pValue;
    }
    try
    {
      return pValue.toString();
    }
    catch (Exception exc)
    {
      if (pLogger.isLoggingError()) {
        pLogger.logError(Constants.TOSTRING_EXCEPTION, exc, pValue.getClass().getName());
      }
    }
    return "";
  }
  
  public static Number coerceToPrimitiveNumber(Object pValue, Class pClass, Logger pLogger)
    throws ELException
  {
    if ((pValue == null) || ("".equals(pValue))) {
      return coerceToPrimitiveNumber(ZERO, pClass);
    }
    if ((pValue instanceof Character))
    {
      char val = ((Character)pValue).charValue();
      return coerceToPrimitiveNumber(new Short((short)val), pClass);
    }
    if ((pValue instanceof Boolean))
    {
      if (pLogger.isLoggingError()) {
        pLogger.logError(Constants.BOOLEAN_TO_NUMBER, pValue, pClass.getName());
      }
      return coerceToPrimitiveNumber(ZERO, pClass);
    }
    if (pValue.getClass() == pClass) {
      return (Number)pValue;
    }
    if ((pValue instanceof Number)) {
      return coerceToPrimitiveNumber((Number)pValue, pClass);
    }
    if ((pValue instanceof String)) {
      try
      {
        return coerceToPrimitiveNumber((String)pValue, pClass);
      }
      catch (Exception exc)
      {
        if (pLogger.isLoggingError()) {
          pLogger.logError(Constants.STRING_TO_NUMBER_EXCEPTION, (String)pValue, pClass.getName());
        }
        return coerceToPrimitiveNumber(ZERO, pClass);
      }
    }
    if (pLogger.isLoggingError()) {
      pLogger.logError(Constants.COERCE_TO_NUMBER, pValue.getClass().getName(), pClass.getName());
    }
    return coerceToPrimitiveNumber(0L, pClass);
  }
  
  public static Integer coerceToInteger(Object pValue, Logger pLogger)
    throws ELException
  {
    if (pValue == null) {
      return null;
    }
    if ((pValue instanceof Character)) {
      return PrimitiveObjects.getInteger(((Character)pValue).charValue());
    }
    if ((pValue instanceof Boolean))
    {
      if (pLogger.isLoggingWarning()) {
        pLogger.logWarning(Constants.BOOLEAN_TO_NUMBER, pValue, Integer.class.getName());
      }
      return PrimitiveObjects.getInteger(((Boolean)pValue).booleanValue() ? 1 : 0);
    }
    if ((pValue instanceof Integer)) {
      return (Integer)pValue;
    }
    if ((pValue instanceof Number)) {
      return PrimitiveObjects.getInteger(((Number)pValue).intValue());
    }
    if ((pValue instanceof String)) {
      try
      {
        return Integer.valueOf((String)pValue);
      }
      catch (Exception exc)
      {
        if (pLogger.isLoggingWarning()) {
          pLogger.logWarning(Constants.STRING_TO_NUMBER_EXCEPTION, (String)pValue, Integer.class.getName());
        }
        return null;
      }
    }
    if (pLogger.isLoggingWarning()) {
      pLogger.logWarning(Constants.COERCE_TO_NUMBER, pValue.getClass().getName(), Integer.class.getName());
    }
    return null;
  }
  
  static Number coerceToPrimitiveNumber(long pValue, Class pClass)
    throws ELException
  {
    if ((pClass == Byte.class) || (pClass == Byte.TYPE)) {
      return PrimitiveObjects.getByte((byte)(int)pValue);
    }
    if ((pClass == Short.class) || (pClass == Short.TYPE)) {
      return PrimitiveObjects.getShort((short)(int)pValue);
    }
    if ((pClass == Integer.class) || (pClass == Integer.TYPE)) {
      return PrimitiveObjects.getInteger((int)pValue);
    }
    if ((pClass == Long.class) || (pClass == Long.TYPE)) {
      return PrimitiveObjects.getLong(pValue);
    }
    if ((pClass == Float.class) || (pClass == Float.TYPE)) {
      return PrimitiveObjects.getFloat((float)pValue);
    }
    if ((pClass == Double.class) || (pClass == Double.TYPE)) {
      return PrimitiveObjects.getDouble(pValue);
    }
    return PrimitiveObjects.getInteger(0);
  }
  
  static Number coerceToPrimitiveNumber(double pValue, Class pClass)
    throws ELException
  {
    if ((pClass == Byte.class) || (pClass == Byte.TYPE)) {
      return PrimitiveObjects.getByte((byte)(int)pValue);
    }
    if ((pClass == Short.class) || (pClass == Short.TYPE)) {
      return PrimitiveObjects.getShort((short)(int)pValue);
    }
    if ((pClass == Integer.class) || (pClass == Integer.TYPE)) {
      return PrimitiveObjects.getInteger((int)pValue);
    }
    if ((pClass == Long.class) || (pClass == Long.TYPE)) {
      return PrimitiveObjects.getLong(pValue);
    }
    if ((pClass == Float.class) || (pClass == Float.TYPE)) {
      return PrimitiveObjects.getFloat((float)pValue);
    }
    if ((pClass == Double.class) || (pClass == Double.TYPE)) {
      return PrimitiveObjects.getDouble(pValue);
    }
    return PrimitiveObjects.getInteger(0);
  }
  
  static Number coerceToPrimitiveNumber(Number pValue, Class pClass)
    throws ELException
  {
    if ((pClass == Byte.class) || (pClass == Byte.TYPE)) {
      return PrimitiveObjects.getByte(pValue.byteValue());
    }
    if ((pClass == Short.class) || (pClass == Short.TYPE)) {
      return PrimitiveObjects.getShort(pValue.shortValue());
    }
    if ((pClass == Integer.class) || (pClass == Integer.TYPE)) {
      return PrimitiveObjects.getInteger(pValue.intValue());
    }
    if ((pClass == Long.class) || (pClass == Long.TYPE)) {
      return PrimitiveObjects.getLong(pValue.longValue());
    }
    if ((pClass == Float.class) || (pClass == Float.TYPE)) {
      return PrimitiveObjects.getFloat(pValue.floatValue());
    }
    if ((pClass == Double.class) || (pClass == Double.TYPE)) {
      return PrimitiveObjects.getDouble(pValue.doubleValue());
    }
    if (pClass == BigInteger.class)
    {
      if ((pValue instanceof BigDecimal)) {
        return ((BigDecimal)pValue).toBigInteger();
      }
      return BigInteger.valueOf(pValue.longValue());
    }
    if (pClass == BigDecimal.class)
    {
      if ((pValue instanceof BigInteger)) {
        return new BigDecimal((BigInteger)pValue);
      }
      return new BigDecimal(pValue.doubleValue());
    }
    return PrimitiveObjects.getInteger(0);
  }
  
  static Number coerceToPrimitiveNumber(String pValue, Class pClass)
    throws ELException
  {
    if ((pClass == Byte.class) || (pClass == Byte.TYPE)) {
      return Byte.valueOf(pValue);
    }
    if ((pClass == Short.class) || (pClass == Short.TYPE)) {
      return Short.valueOf(pValue);
    }
    if ((pClass == Integer.class) || (pClass == Integer.TYPE)) {
      return Integer.valueOf(pValue);
    }
    if ((pClass == Long.class) || (pClass == Long.TYPE)) {
      return Long.valueOf(pValue);
    }
    if ((pClass == Float.class) || (pClass == Float.TYPE)) {
      return Float.valueOf(pValue);
    }
    if ((pClass == Double.class) || (pClass == Double.TYPE)) {
      return Double.valueOf(pValue);
    }
    if (pClass == BigInteger.class) {
      return new BigInteger(pValue);
    }
    if (pClass == BigDecimal.class) {
      return new BigDecimal(pValue);
    }
    return PrimitiveObjects.getInteger(0);
  }
  
  public static Character coerceToCharacter(Object pValue, Logger pLogger)
    throws ELException
  {
    if ((pValue == null) || ("".equals(pValue))) {
      return PrimitiveObjects.getCharacter('\000');
    }
    if ((pValue instanceof Character)) {
      return (Character)pValue;
    }
    if ((pValue instanceof Boolean))
    {
      if (pLogger.isLoggingError()) {
        pLogger.logError(Constants.BOOLEAN_TO_CHARACTER, pValue);
      }
      return PrimitiveObjects.getCharacter('\000');
    }
    if ((pValue instanceof Number)) {
      return PrimitiveObjects.getCharacter((char)((Number)pValue).shortValue());
    }
    if ((pValue instanceof String))
    {
      String str = (String)pValue;
      return PrimitiveObjects.getCharacter(str.charAt(0));
    }
    if (pLogger.isLoggingError()) {
      pLogger.logError(Constants.COERCE_TO_CHARACTER, pValue.getClass().getName());
    }
    return PrimitiveObjects.getCharacter('\000');
  }
  
  public static Boolean coerceToBoolean(Object pValue, Logger pLogger)
    throws ELException
  {
    if ((pValue == null) || ("".equals(pValue))) {
      return Boolean.FALSE;
    }
    if ((pValue instanceof Boolean)) {
      return (Boolean)pValue;
    }
    if ((pValue instanceof String))
    {
      String str = (String)pValue;
      try
      {
        return Boolean.valueOf(str);
      }
      catch (Exception exc)
      {
        if (pLogger.isLoggingError()) {
          pLogger.logError(Constants.STRING_TO_BOOLEAN, exc, (String)pValue);
        }
        return Boolean.FALSE;
      }
    }
    if (pLogger.isLoggingError()) {
      pLogger.logError(Constants.COERCE_TO_BOOLEAN, pValue.getClass().getName());
    }
    return Boolean.TRUE;
  }
  
  public static Object coerceToObject(Object pValue, Class pClass, Logger pLogger)
    throws ELException
  {
    if (pValue == null) {
      return null;
    }
    if (pClass.isAssignableFrom(pValue.getClass())) {
      return pValue;
    }
    if ((pValue instanceof String))
    {
      String str = (String)pValue;
      PropertyEditor pe = PropertyEditorManager.findEditor(pClass);
      if (pe == null)
      {
        if ("".equals(str)) {
          return null;
        }
        if (pLogger.isLoggingError()) {
          pLogger.logError(Constants.NO_PROPERTY_EDITOR, str, pClass.getName());
        }
        return null;
      }
      try
      {
        pe.setAsText(str);
        return pe.getValue();
      }
      catch (IllegalArgumentException exc)
      {
        if ("".equals(str)) {
          return null;
        }
        if (pLogger.isLoggingError()) {
          pLogger.logError(Constants.PROPERTY_EDITOR_ERROR, exc, pValue, pClass.getName());
        }
        return null;
      }
    }
    if (pLogger.isLoggingError()) {
      pLogger.logError(Constants.COERCE_TO_OBJECT, pValue.getClass().getName(), pClass.getName());
    }
    return null;
  }
  
  public static Object applyArithmeticOperator(Object pLeft, Object pRight, ArithmeticOperator pOperator, Logger pLogger)
    throws ELException
  {
    if ((pLeft == null) && (pRight == null))
    {
      if (pLogger.isLoggingWarning()) {
        pLogger.logWarning(Constants.ARITH_OP_NULL, pOperator.getOperatorSymbol());
      }
      return PrimitiveObjects.getInteger(0);
    }
    if ((isBigDecimal(pLeft)) || (isBigDecimal(pRight)))
    {
      BigDecimal left = (BigDecimal)coerceToPrimitiveNumber(pLeft, BigDecimal.class, pLogger);
      
      BigDecimal right = (BigDecimal)coerceToPrimitiveNumber(pRight, BigDecimal.class, pLogger);
      
      return pOperator.apply(left, right);
    }
    if ((isFloatingPointType(pLeft)) || (isFloatingPointType(pRight)) || (isFloatingPointString(pLeft)) || (isFloatingPointString(pRight)))
    {
      if ((isBigInteger(pLeft)) || (isBigInteger(pRight)))
      {
        BigDecimal left = (BigDecimal)coerceToPrimitiveNumber(pLeft, BigDecimal.class, pLogger);
        
        BigDecimal right = (BigDecimal)coerceToPrimitiveNumber(pRight, BigDecimal.class, pLogger);
        
        return pOperator.apply(left, right);
      }
      double left = coerceToPrimitiveNumber(pLeft, Double.class, pLogger).doubleValue();
      
      double right = coerceToPrimitiveNumber(pRight, Double.class, pLogger).doubleValue();
      
      return PrimitiveObjects.getDouble(pOperator.apply(left, right));
    }
    if ((isBigInteger(pLeft)) || (isBigInteger(pRight)))
    {
      BigInteger left = (BigInteger)coerceToPrimitiveNumber(pLeft, BigInteger.class, pLogger);
      
      BigInteger right = (BigInteger)coerceToPrimitiveNumber(pRight, BigInteger.class, pLogger);
      
      return pOperator.apply(left, right);
    }
    long left = coerceToPrimitiveNumber(pLeft, Long.class, pLogger).longValue();
    
    long right = coerceToPrimitiveNumber(pRight, Long.class, pLogger).longValue();
    
    return PrimitiveObjects.getLong(pOperator.apply(left, right));
  }
  
  public static Object applyRelationalOperator(Object pLeft, Object pRight, RelationalOperator pOperator, Logger pLogger)
    throws ELException
  {
    if ((isBigDecimal(pLeft)) || (isBigDecimal(pRight)))
    {
      BigDecimal left = (BigDecimal)coerceToPrimitiveNumber(pLeft, BigDecimal.class, pLogger);
      
      BigDecimal right = (BigDecimal)coerceToPrimitiveNumber(pRight, BigDecimal.class, pLogger);
      
      return PrimitiveObjects.getBoolean(pOperator.apply(left, right));
    }
    if ((isFloatingPointType(pLeft)) || (isFloatingPointType(pRight)))
    {
      double left = coerceToPrimitiveNumber(pLeft, Double.class, pLogger).doubleValue();
      
      double right = coerceToPrimitiveNumber(pRight, Double.class, pLogger).doubleValue();
      
      return PrimitiveObjects.getBoolean(pOperator.apply(left, right));
    }
    if ((isBigInteger(pLeft)) || (isBigInteger(pRight)))
    {
      BigInteger left = (BigInteger)coerceToPrimitiveNumber(pLeft, BigInteger.class, pLogger);
      
      BigInteger right = (BigInteger)coerceToPrimitiveNumber(pRight, BigInteger.class, pLogger);
      
      return PrimitiveObjects.getBoolean(pOperator.apply(left, right));
    }
    if ((isIntegerType(pLeft)) || (isIntegerType(pRight)))
    {
      long left = coerceToPrimitiveNumber(pLeft, Long.class, pLogger).longValue();
      
      long right = coerceToPrimitiveNumber(pRight, Long.class, pLogger).longValue();
      
      return PrimitiveObjects.getBoolean(pOperator.apply(left, right));
    }
    if (((pLeft instanceof String)) || ((pRight instanceof String)))
    {
      String left = coerceToString(pLeft, pLogger);
      String right = coerceToString(pRight, pLogger);
      return PrimitiveObjects.getBoolean(pOperator.apply(left, right));
    }
    if ((pLeft instanceof Comparable)) {
      try
      {
        int result = ((Comparable)pLeft).compareTo(pRight);
        return PrimitiveObjects.getBoolean(pOperator.apply(result, -result));
      }
      catch (Exception exc)
      {
        if (pLogger.isLoggingError()) {
          pLogger.logError(Constants.COMPARABLE_ERROR, exc, pLeft.getClass().getName(), pRight == null ? "null" : pRight.getClass().getName(), pOperator.getOperatorSymbol());
        }
        return Boolean.FALSE;
      }
    }
    if ((pRight instanceof Comparable)) {
      try
      {
        int result = ((Comparable)pRight).compareTo(pLeft);
        return PrimitiveObjects.getBoolean(pOperator.apply(-result, result));
      }
      catch (Exception exc)
      {
        if (pLogger.isLoggingError()) {
          pLogger.logError(Constants.COMPARABLE_ERROR, exc, pRight.getClass().getName(), pLeft == null ? "null" : pLeft.getClass().getName(), pOperator.getOperatorSymbol());
        }
        return Boolean.FALSE;
      }
    }
    if (pLogger.isLoggingError()) {
      pLogger.logError(Constants.ARITH_OP_BAD_TYPE, pOperator.getOperatorSymbol(), pLeft.getClass().getName(), pRight.getClass().getName());
    }
    return Boolean.FALSE;
  }
  
  public static Object applyEqualityOperator(Object pLeft, Object pRight, EqualityOperator pOperator, Logger pLogger)
    throws ELException
  {
    if (pLeft == pRight) {
      return PrimitiveObjects.getBoolean(pOperator.apply(true, pLogger));
    }
    if ((pLeft == null) || (pRight == null)) {
      return PrimitiveObjects.getBoolean(pOperator.apply(false, pLogger));
    }
    if ((isBigDecimal(pLeft)) || (isBigDecimal(pRight)))
    {
      BigDecimal left = (BigDecimal)coerceToPrimitiveNumber(pLeft, BigDecimal.class, pLogger);
      
      BigDecimal right = (BigDecimal)coerceToPrimitiveNumber(pRight, BigDecimal.class, pLogger);
      
      return PrimitiveObjects.getBoolean(pOperator.apply(left.equals(right), pLogger));
    }
    if ((isFloatingPointType(pLeft)) || (isFloatingPointType(pRight)))
    {
      double left = coerceToPrimitiveNumber(pLeft, Double.class, pLogger).doubleValue();
      
      double right = coerceToPrimitiveNumber(pRight, Double.class, pLogger).doubleValue();
      
      return PrimitiveObjects.getBoolean(pOperator.apply(left == right, pLogger));
    }
    if ((isBigInteger(pLeft)) || (isBigInteger(pRight)))
    {
      BigInteger left = (BigInteger)coerceToPrimitiveNumber(pLeft, BigInteger.class, pLogger);
      
      BigInteger right = (BigInteger)coerceToPrimitiveNumber(pRight, BigInteger.class, pLogger);
      
      return PrimitiveObjects.getBoolean(pOperator.apply(left.equals(right), pLogger));
    }
    if ((isIntegerType(pLeft)) || (isIntegerType(pRight)))
    {
      long left = coerceToPrimitiveNumber(pLeft, Long.class, pLogger).longValue();
      
      long right = coerceToPrimitiveNumber(pRight, Long.class, pLogger).longValue();
      
      return PrimitiveObjects.getBoolean(pOperator.apply(left == right, pLogger));
    }
    if (((pLeft instanceof Boolean)) || ((pRight instanceof Boolean)))
    {
      boolean left = coerceToBoolean(pLeft, pLogger).booleanValue();
      boolean right = coerceToBoolean(pRight, pLogger).booleanValue();
      return PrimitiveObjects.getBoolean(pOperator.apply(left == right, pLogger));
    }
    if (((pLeft instanceof String)) || ((pRight instanceof String)))
    {
      String left = coerceToString(pLeft, pLogger);
      String right = coerceToString(pRight, pLogger);
      return PrimitiveObjects.getBoolean(pOperator.apply(left.equals(right), pLogger));
    }
    try
    {
      return PrimitiveObjects.getBoolean(pOperator.apply(pLeft.equals(pRight), pLogger));
    }
    catch (Exception exc)
    {
      if (pLogger.isLoggingError()) {
        pLogger.logError(Constants.ERROR_IN_EQUALS, exc, pLeft.getClass().getName(), pRight.getClass().getName(), pOperator.getOperatorSymbol());
      }
    }
    return Boolean.FALSE;
  }
  
  public static boolean isFloatingPointType(Object pObject)
  {
    return (pObject != null) && (isFloatingPointType(pObject.getClass()));
  }
  
  public static boolean isFloatingPointType(Class pClass)
  {
    return (pClass == Float.class) || (pClass == Float.TYPE) || (pClass == Double.class) || (pClass == Double.TYPE);
  }
  
  public static boolean isFloatingPointString(Object pObject)
  {
    if ((pObject instanceof String))
    {
      String str = (String)pObject;
      int len = str.length();
      for (int i = 0; i < len; i++)
      {
        char ch = str.charAt(i);
        if ((ch == '.') || (ch == 'e') || (ch == 'E')) {
          return true;
        }
      }
      return false;
    }
    return false;
  }
  
  public static boolean isIntegerType(Object pObject)
  {
    return (pObject != null) && (isIntegerType(pObject.getClass()));
  }
  
  public static boolean isIntegerType(Class pClass)
  {
    return (pClass == Byte.class) || (pClass == Byte.TYPE) || (pClass == Short.class) || (pClass == Short.TYPE) || (pClass == Character.class) || (pClass == Character.TYPE) || (pClass == Integer.class) || (pClass == Integer.TYPE) || (pClass == Long.class) || (pClass == Long.TYPE);
  }
  
  public static boolean isBigInteger(Object pObject)
  {
    return (pObject != null) && ((pObject instanceof BigInteger));
  }
  
  public static boolean isBigDecimal(Object pObject)
  {
    return (pObject != null) && ((pObject instanceof BigDecimal));
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.el.Coercions
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.el;

import java.util.List;
import javax.servlet.jsp.el.ELException;
import javax.servlet.jsp.el.FunctionMapper;
import javax.servlet.jsp.el.VariableResolver;

public class ComplexValue
  extends Expression
{
  Expression mPrefix;
  List mSuffixes;
  
  public Expression getPrefix()
  {
    return mPrefix;
  }
  
  public void setPrefix(Expression pPrefix)
  {
    mPrefix = pPrefix;
  }
  
  public List getSuffixes()
  {
    return mSuffixes;
  }
  
  public void setSuffixes(List pSuffixes)
  {
    mSuffixes = pSuffixes;
  }
  
  public ComplexValue(Expression pPrefix, List pSuffixes)
  {
    mPrefix = pPrefix;
    mSuffixes = pSuffixes;
  }
  
  public String getExpressionString()
  {
    StringBuffer buf = new StringBuffer();
    buf.append(mPrefix.getExpressionString());
    for (int i = 0; (mSuffixes != null) && (i < mSuffixes.size()); i++)
    {
      ValueSuffix suffix = (ValueSuffix)mSuffixes.get(i);
      buf.append(suffix.getExpressionString());
    }
    return buf.toString();
  }
  
  public Object evaluate(VariableResolver pResolver, Function
1 2 3 4 5 6

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd