You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2010/03/20 01:00:09 UTC
svn commit: r925490 - in /myfaces/shared/trunk: ./
core/src/main/java/org/apache/myfaces/shared/util/
Author: lu4242
Date: Sat Mar 20 00:00:09 2010
New Revision: 925490
URL: http://svn.apache.org/viewvc?rev=925490&view=rev
Log:
ORCHESTRA-50 Unresolved dependency of org.apache.commons.el.Logger
Added:
myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/_Coercions.java
myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/_Constants.java
myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/_MessageUtil.java
myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/_PrimitiveObjects.java
Modified:
myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/ClassUtils.java
myfaces/shared/trunk/pom.xml
Modified: myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/ClassUtils.java
URL: http://svn.apache.org/viewvc/myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/ClassUtils.java?rev=925490&r1=925489&r2=925490&view=diff
==============================================================================
--- myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/ClassUtils.java (original)
+++ myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/ClassUtils.java Sat Mar 20 00:00:09 2010
@@ -18,8 +18,6 @@
*/
package org.apache.myfaces.shared.util;
-import org.apache.commons.el.Coercions;
-import org.apache.commons.el.Logger;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -41,7 +39,7 @@ public final class ClassUtils
//~ Static fields/initializers -----------------------------------------------------------------
private static final Log log = LogFactory.getLog(ClassUtils.class);
- private static final Logger COERCION_LOGGER = new Logger(System.out);
+ //private static final Logger COERCION_LOGGER = new Logger(System.out);
public static final Class BOOLEAN_ARRAY_CLASS = boolean[].class;
public static final Class BYTE_ARRAY_CLASS = byte[].class;
@@ -327,7 +325,9 @@ public final class ClassUtils
{
// Use coersion implemented by JSP EL for consistency with EL
// expressions. Additionally, it caches some of the coersions.
- return Coercions.coerce(value, desiredClass, COERCION_LOGGER);
+ //return Coercions.coerce(value, desiredClass, COERCION_LOGGER);
+ //return coerce(value, desiredClass);
+ return _Coercions.coerce(value, desiredClass);
}
catch (ELException e)
{
@@ -337,7 +337,7 @@ public final class ClassUtils
throw new FacesException(message, e);
}
}
-
+
/**
* Gets the ClassLoader associated with the current thread. Returns the class loader associated with
* the specified default object if no context loader is associated with the current thread.
Added: myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/_Coercions.java
URL: http://svn.apache.org/viewvc/myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/_Coercions.java?rev=925490&view=auto
==============================================================================
--- myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/_Coercions.java (added)
+++ myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/_Coercions.java Sat Mar 20 00:00:09 2010
@@ -0,0 +1,1192 @@
+/*
+ * 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 org.apache.myfaces.shared.util;
+
+import java.beans.PropertyEditor;
+import java.beans.PropertyEditorManager;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+
+import javax.servlet.jsp.el.ELException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ *
+ * <p>This class contains the logic for coercing data types before
+ * operators are applied to them.
+ *
+ * <p>The following is the list of rules applied for various type
+ * conversions.
+ *
+ * <ul><pre>
+ * Applying arithmetic operator
+ * Binary operator - A {+,-,*} B
+ * if A and B are null
+ * return 0
+ * if A or B is BigDecimal, coerce both to BigDecimal and then:
+ * if operator is +, return <code>A.add(B)</code>
+ * if operator is -, return <code>A.subtract(B)</code>
+ * if operator is *, return <code>A.multiply(B)</code>
+ * if A or B is Float, Double, or String containing ".", "e", or "E"
+ * if A or B is BigInteger, coerce both A and B to BigDecimal and apply operator
+ * coerce both A and B to Double and apply operator
+ * if A or B is BigInteger, coerce both to BigInteger and then:
+ * if operator is +, return <code>A.add(B)</code>
+ * if operator is -, return <code>A.subtract(B)</code>
+ * if operator is *, return <code>A.multiply(B)</code>
+ * otherwise
+ * coerce both A and B to Long
+ * apply operator
+ * if operator results in exception (such as divide by 0), error
+ *
+ * Binary operator - A {/,div} B
+ * if A and B are null
+ * return 0
+ * if A or B is a BigDecimal or BigInteger, coerce both to BigDecimal and
+ * return <code>A.divide(B, BigDecimal.ROUND_HALF_UP)</code>
+ * otherwise
+ * coerce both A and B to Double
+ * apply operator
+ * if operator results in exception (such as divide by 0), error
+ *
+ * Binary operator - A {%,mod} B
+ * if A and B are null
+ * return 0
+ * if A or B is BigDecimal, Float, Double, or String containing ".", "e" or "E"
+ * coerce both to Double
+ * apply operator
+ * if A or B is BigInteger, coerce both to BigInteger and return
+ * <code>A.remainder(B)</code>
+ * otherwise
+ * coerce both A and B to Long
+ * apply operator
+ * if operator results in exception (such as divide by 0), error
+ *
+ * Unary minus operator - -A
+ * if A is null
+ * return 0
+ * if A is BigInteger or BigDecimal, return <code>A.negate()</code>
+ * if A is String
+ * if A contains ".", "e", or "E"
+ * coerce to Double, apply operator
+ * otherwise
+ * coerce to a Long and apply operator
+ * if A is Byte,Short,Integer,Long,Float,Double
+ * retain type, apply operator
+ * if operator results in exception, error
+ * otherwise
+ * error
+ *
+ * Applying "empty" operator - empty A
+ * if A is null
+ * return true
+ * if A is zero-length String
+ * return true
+ * if A is zero-length array
+ * return true
+ * if A is List and ((List) A).isEmpty()
+ * return true
+ * if A is Map and ((Map) A).isEmpty()
+ * return true
+ * if A is Collection an ((Collection) A).isEmpty()
+ * return true
+ * otherwise
+ * return false
+ *
+ * Applying logical operators
+ * Binary operator - A {and,or} B
+ * coerce both A and B to Boolean, apply operator
+ * NOTE - operator stops as soon as expression can be determined, i.e.,
+ * A and B and C and D - if B is false, then only A and B is evaluated
+ * Unary not operator - not A
+ * coerce A to Boolean, apply operator
+ *
+ * Applying relational operator
+ * A {<,>,<=,>=,lt,gt,lte,gte} B
+ * if A==B
+ * if operator is >= or <=
+ * return true
+ * otherwise
+ * return false
+ * if A or B is null
+ * return false
+ * if A or B is BigDecimal, coerce both A and B to BigDecimal and use the
+ * return value of <code>A.compareTo(B)</code>
+ * if A or B is Float or Double
+ * coerce both A and B to Double
+ * apply operator
+ * if A or B is BigInteger, coerce both A and B to BigInteger and use the
+ * return value of <code>A.compareTo(B)</code>
+ * if A or B is Byte,Short,Character,Integer,Long
+ * coerce both A and B to Long
+ * apply operator
+ * if A or B is String
+ * coerce both A and B to String, compare lexically
+ * if A is Comparable
+ * if A.compareTo (B) throws exception
+ * error
+ * otherwise
+ * use result of A.compareTo(B)
+ * if B is Comparable
+ * if B.compareTo (A) throws exception
+ * error
+ * otherwise
+ * use result of B.compareTo(A)
+ * otherwise
+ * error
+ *
+ * Applying equality operator
+ * A {==,!=} B
+ * if A==B
+ * apply operator
+ * if A or B is null
+ * return false for ==, true for !=
+ * if A or B is BigDecimal, coerce both A and B to BigDecimal and then:
+ * if operator is == or eq, return <code>A.equals(B)</code>
+ * if operator is != or ne, return <code>!A.equals(B)</code>
+ * if A or B is Float or Double
+ * coerce both A and B to Double
+ * apply operator
+ * if A or B is BigInteger, coerce both A and B to BigInteger and then:
+ * if operator is == or eq, return <code>A.equals(B)</code>
+ * if operator is != or ne, return <code>!A.equals(B)</code>
+ * if A or B is Byte,Short,Character,Integer,Long
+ * coerce both A and B to Long
+ * apply operator
+ * if A or B is Boolean
+ * coerce both A and B to Boolean
+ * apply operator
+ * if A or B is String
+ * coerce both A and B to String, compare lexically
+ * otherwise
+ * if an error occurs while calling A.equals(B)
+ * error
+ * apply operator to result of A.equals(B)
+ *
+ * coercions
+ *
+ * coerce A to String
+ * A is String
+ * return A
+ * A is null
+ * return ""
+ * A.toString throws exception
+ * error
+ * otherwise
+ * return A.toString
+ *
+ * coerce A to Number type N
+ * A is null or ""
+ * return 0
+ * A is Character
+ * convert to short, apply following rules
+ * A is Boolean
+ * error
+ * A is Number type N
+ * return A
+ * A is Number, coerce quietly to type N using the following algorithm
+ * If N is BigInteger
+ * If A is BigDecimal, return <code>A.toBigInteger()</code>
+ * Otherwise, return <code>BigInteger.valueOf(A.longValue())</code>
+ * if N is BigDecimal
+ * If A is a BigInteger, return <code>new BigDecimal(A)</code>
+ * Otherwise, return <code>new BigDecimal(A.doubleValue())</code>
+ * If N is Byte, return <code>new Byte(A.byteValue())</code>
+ * If N is Short, return <code>new Short(A.shortValue())</code>
+ * If N is Integer, return <code>new Integer(A.integerValue())</code>
+ * If N is Long, return <code>new Long(A.longValue())</code>
+ * If N is Float, return <code>new Float(A.floatValue())</code>
+ * If N is Double, return <code>new Double(A.doubleValue())</code>
+ * otherwise ERROR
+ * A is String
+ * If N is BigDecimal then:
+ * If <code>new BigDecimal(A)</code> throws an exception then ERROR
+ * Otherwise, return <code>new BigDecimal(A)</code>
+ * If N is BigInteger then:
+ * If <code>new BigInteger(A)</code> throws an exception, then ERROR
+ * Otherwise, return <code>new BigInteger(A)</code>
+ * new <code>N.valueOf(A)</code> throws exception
+ * error
+ * return <code>N.valueOf(A)</code>
+ * otherwise
+ * error
+ *
+ * coerce A to Character should be
+ * A is null or ""
+ * return (char) 0
+ * A is Character
+ * return A
+ * A is Boolean
+ * error
+ * A is Number with less precision than short
+ * coerce quietly - return (char) A
+ * A is Number with greater precision than short
+ * coerce quietly - return (char) A
+ * A is String
+ * return A.charAt (0)
+ * otherwise
+ * error
+ *
+ * coerce A to Boolean
+ * A is null or ""
+ * return false
+ * A is Boolean
+ * return A
+ * A is String
+ * Boolean.valueOf(A) throws exception
+ * error
+ * return Boolean.valueOf(A)
+ * otherwise
+ * error
+ *
+ * coerce A to any other type T
+ * A is null
+ * return null
+ * A is assignable to T
+ * coerce quietly
+ * A is String
+ * T has no PropertyEditor
+ * if A is "", return null
+ * otherwise error
+ * T's PropertyEditor throws exception
+ * if A is "", return null
+ * otherwise error
+ * otherwise
+ * apply T's PropertyEditor
+ * otherwise
+ * error
+ * </pre></ul>
+ *
+ * This is a copy from commons-el Coercions class.
+ *
+ * @author Nathan Abramson - Art Technology Group
+ * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
+ **/
+
+class _Coercions
+{
+ //-------------------------------------
+ // Constants
+ //-------------------------------------
+ private static final Number ZERO = new Integer(0);
+ private static Log log = LogFactory.getLog(_Coercions.class);
+
+ //-------------------------------------
+ /**
+ *
+ * Coerces the given value to the specified class.
+ **/
+ public static Object coerce (Object pValue,
+ Class pClass)
+ throws ELException
+ {
+ if (pClass == String.class) {
+ return coerceToString (pValue);
+ }
+ else if (isNumberClass (pClass)) {
+ return coerceToPrimitiveNumber (pValue, pClass);
+ }
+ else if (pClass == Character.class ||
+ pClass == Character.TYPE) {
+ return coerceToCharacter (pValue);
+ }
+ else if (pClass == Boolean.class ||
+ pClass == Boolean.TYPE) {
+ return coerceToBoolean (pValue);
+ }
+ else {
+ return coerceToObject (pValue, pClass);
+ }
+ }
+
+ //-------------------------------------
+ /**
+ *
+ * Returns true if the given class is Byte, Short, Integer, Long,
+ * Float, Double, BigInteger, or BigDecimal
+ **/
+ 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;
+ }
+
+ //-------------------------------------
+ /**
+ *
+ * Coerces the specified value to a String
+ **/
+ public static String coerceToString (Object pValue)
+ throws ELException
+ {
+ if (pValue == null) {
+ return "";
+ }
+ else if (pValue instanceof String) {
+ return (String) pValue;
+ }
+ else {
+ try {
+ return pValue.toString ();
+ }
+ catch (Exception exc) {
+ if (log.isErrorEnabled()) {
+ String message = _MessageUtil.getMessageWithArgs(
+ _Constants.TOSTRING_EXCEPTION,
+ pValue.getClass().getName());
+ log.error(message, exc);
+ throw new ELException(exc);
+ }
+ return "";
+ }
+ }
+ }
+
+ //-------------------------------------
+ /**
+ *
+ * Coerces a value to the given primitive number class
+ **/
+ public static Number coerceToPrimitiveNumber (Object pValue,
+ Class pClass)
+ throws ELException
+ {
+ if (pValue == null ||
+ "".equals (pValue)) {
+ return coerceToPrimitiveNumber (ZERO, pClass);
+ }
+ else if (pValue instanceof Character) {
+ char val = ((Character) pValue).charValue ();
+ return coerceToPrimitiveNumber (new Short((short) val), pClass);
+ }
+ else if (pValue instanceof Boolean) {
+ if (log.isErrorEnabled()) {
+ String message = _MessageUtil.getMessageWithArgs(
+ _Constants.BOOLEAN_TO_NUMBER, pValue, pClass.getName());
+ log.error(message);
+ throw new ELException(message);
+ }
+ return coerceToPrimitiveNumber(ZERO, pClass);
+ }
+ else if (pValue.getClass () == pClass) {
+ return (Number) pValue;
+ }
+ else if (pValue instanceof Number) {
+ return coerceToPrimitiveNumber ((Number) pValue, pClass);
+ }
+ else if (pValue instanceof String) {
+ try {
+ return coerceToPrimitiveNumber ((String) pValue, pClass);
+ }
+ catch (Exception exc) {
+ if (log.isErrorEnabled()) {
+ String message = _MessageUtil.getMessageWithArgs(
+ _Constants.STRING_TO_NUMBER_EXCEPTION,
+ (String) pValue, pClass.getName());
+ log.error(message);
+ throw new ELException(message);
+ }
+ return coerceToPrimitiveNumber (ZERO, pClass);
+ }
+ }
+ else {
+ if (log.isErrorEnabled()) {
+ String message = _MessageUtil.getMessageWithArgs(
+ _Constants.COERCE_TO_NUMBER,
+ pValue.getClass().getName(),
+ pClass.getName());
+ log.error(message);
+ throw new ELException(message);
+ }
+ return coerceToPrimitiveNumber (0, pClass);
+ }
+ }
+
+ //-------------------------------------
+ /**
+ *
+ * Coerces a value to an Integer, returning null if the coercion
+ * isn't possible.
+ **/
+ public static Integer coerceToInteger (Object pValue)
+ throws ELException
+ {
+ if (pValue == null) {
+ return null;
+ }
+ else if (pValue instanceof Character) {
+ return _PrimitiveObjects.getInteger
+ ((int) (((Character) pValue).charValue ()));
+ }
+ else if (pValue instanceof Boolean) {
+ if (log.isWarnEnabled()) {
+ log.warn(
+ _MessageUtil.getMessageWithArgs(
+ _Constants.BOOLEAN_TO_NUMBER, pValue, Integer.class.getName()));
+ }
+ return _PrimitiveObjects.getInteger
+ (((Boolean) pValue).booleanValue () ? 1 : 0);
+ }
+ else if (pValue instanceof Integer) {
+ return (Integer) pValue;
+ }
+ else if (pValue instanceof Number) {
+ return _PrimitiveObjects.getInteger (((Number) pValue).intValue ());
+ }
+ else if (pValue instanceof String) {
+ try {
+ return Integer.valueOf ((String) pValue);
+ }
+ catch (Exception exc) {
+ if (log.isWarnEnabled()) {
+ log.warn(
+ _MessageUtil.getMessageWithArgs(
+ _Constants.STRING_TO_NUMBER_EXCEPTION,
+ (String) pValue,
+ Integer.class.getName()));
+ }
+ return null;
+ }
+ }
+ else {
+ if (log.isWarnEnabled()) {
+ log.warn(
+ _MessageUtil.getMessageWithArgs(
+ _Constants.COERCE_TO_NUMBER,
+ pValue.getClass().getName(),
+ Integer.class.getName()));
+ }
+ return null;
+ }
+ }
+
+ //-------------------------------------
+ /**
+ *
+ * Coerces a long to the given primitive number class
+ **/
+ static Number coerceToPrimitiveNumber (long pValue,
+ Class pClass)
+ throws ELException
+ {
+ if (pClass == Byte.class || pClass == Byte.TYPE) {
+ return _PrimitiveObjects.getByte ((byte) pValue);
+ }
+ else if (pClass == Short.class || pClass == Short.TYPE) {
+ return _PrimitiveObjects.getShort ((short) pValue);
+ }
+ else if (pClass == Integer.class || pClass == Integer.TYPE) {
+ return _PrimitiveObjects.getInteger ((int) pValue);
+ }
+ else if (pClass == Long.class || pClass == Long.TYPE) {
+ return _PrimitiveObjects.getLong (pValue);
+ }
+ else if (pClass == Float.class || pClass == Float.TYPE) {
+ return _PrimitiveObjects.getFloat ((float) pValue);
+ }
+ else if (pClass == Double.class || pClass == Double.TYPE) {
+ return _PrimitiveObjects.getDouble ((double) pValue);
+ }
+ else {
+ return _PrimitiveObjects.getInteger (0);
+ }
+ }
+
+ //-------------------------------------
+ /**
+ *
+ * Coerces a double to the given primitive number class
+ **/
+ static Number coerceToPrimitiveNumber (double pValue,
+ Class pClass)
+ throws ELException
+ {
+ if (pClass == Byte.class || pClass == Byte.TYPE) {
+ return _PrimitiveObjects.getByte ((byte) pValue);
+ }
+ else if (pClass == Short.class || pClass == Short.TYPE) {
+ return _PrimitiveObjects.getShort ((short) pValue);
+ }
+ else if (pClass == Integer.class || pClass == Integer.TYPE) {
+ return _PrimitiveObjects.getInteger ((int) pValue);
+ }
+ else if (pClass == Long.class || pClass == Long.TYPE) {
+ return _PrimitiveObjects.getLong ((long) pValue);
+ }
+ else if (pClass == Float.class || pClass == Float.TYPE) {
+ return _PrimitiveObjects.getFloat ((float) pValue);
+ }
+ else if (pClass == Double.class || pClass == Double.TYPE) {
+ return _PrimitiveObjects.getDouble (pValue);
+ }
+ else {
+ return _PrimitiveObjects.getInteger (0);
+ }
+ }
+
+ //-------------------------------------
+ /**
+ *
+ * Coerces a Number to the given primitive number class
+ **/
+ static Number coerceToPrimitiveNumber (Number pValue, Class pClass)
+ throws ELException
+ {
+ if (pClass == Byte.class || pClass == Byte.TYPE) {
+ return _PrimitiveObjects.getByte (pValue.byteValue ());
+ }
+ else if (pClass == Short.class || pClass == Short.TYPE) {
+ return _PrimitiveObjects.getShort (pValue.shortValue ());
+ }
+ else if (pClass == Integer.class || pClass == Integer.TYPE) {
+ return _PrimitiveObjects.getInteger (pValue.intValue ());
+ }
+ else if (pClass == Long.class || pClass == Long.TYPE) {
+ return _PrimitiveObjects.getLong (pValue.longValue ());
+ }
+ else if (pClass == Float.class || pClass == Float.TYPE) {
+ return _PrimitiveObjects.getFloat (pValue.floatValue ());
+ }
+ else if (pClass == Double.class || pClass == Double.TYPE) {
+ return _PrimitiveObjects.getDouble (pValue.doubleValue ());
+ }
+ else if (pClass == BigInteger.class) {
+ if (pValue instanceof BigDecimal)
+ return ((BigDecimal) pValue).toBigInteger();
+ else
+ return BigInteger.valueOf(pValue.longValue());
+ }
+ else if (pClass == BigDecimal.class) {
+ if (pValue instanceof BigInteger)
+ return new BigDecimal((BigInteger) pValue);
+ else
+ return new BigDecimal(pValue.doubleValue());
+ }
+ else {
+ return _PrimitiveObjects.getInteger (0);
+ }
+ }
+
+ //-------------------------------------
+ /**
+ *
+ * Coerces a String to the given primitive number class
+ **/
+ static Number coerceToPrimitiveNumber (String pValue, Class pClass)
+ throws ELException
+ {
+ if (pClass == Byte.class || pClass == Byte.TYPE) {
+ return Byte.valueOf (pValue);
+ }
+ else if (pClass == Short.class || pClass == Short.TYPE) {
+ return Short.valueOf (pValue);
+ }
+ else if (pClass == Integer.class || pClass == Integer.TYPE) {
+ return Integer.valueOf (pValue);
+ }
+ else if (pClass == Long.class || pClass == Long.TYPE) {
+ return Long.valueOf (pValue);
+ }
+ else if (pClass == Float.class || pClass == Float.TYPE) {
+ return Float.valueOf (pValue);
+ }
+ else if (pClass == Double.class || pClass == Double.TYPE) {
+ return Double.valueOf (pValue);
+ }
+ else if (pClass == BigInteger.class) {
+ return new BigInteger(pValue);
+ }
+ else if (pClass == BigDecimal.class) {
+ return new BigDecimal(pValue);
+ }
+ else {
+ return _PrimitiveObjects.getInteger (0);
+ }
+ }
+
+ //-------------------------------------
+ /**
+ *
+ * Coerces a value to a Character
+ **/
+ public static Character coerceToCharacter (Object pValue)
+ throws ELException
+ {
+ if (pValue == null ||
+ "".equals (pValue)) {
+ return _PrimitiveObjects.getCharacter ((char) 0);
+ }
+ else if (pValue instanceof Character) {
+ return (Character) pValue;
+ }
+ else if (pValue instanceof Boolean) {
+ if (log.isErrorEnabled()) {
+ String message = _MessageUtil.getMessageWithArgs(
+ _Constants.BOOLEAN_TO_CHARACTER, pValue);
+ log.error(message);
+ throw new ELException(message);
+ }
+ return _PrimitiveObjects.getCharacter ((char) 0);
+ }
+ else if (pValue instanceof Number) {
+ return _PrimitiveObjects.getCharacter
+ ((char) ((Number) pValue).shortValue ());
+ }
+ else if (pValue instanceof String) {
+ String str = (String) pValue;
+ return _PrimitiveObjects.getCharacter (str.charAt (0));
+ }
+ else {
+ if (log.isErrorEnabled()) {
+ String message = _MessageUtil.getMessageWithArgs(
+ _Constants.COERCE_TO_CHARACTER,
+ pValue.getClass().getName());
+ log.error(message);
+ throw new ELException(message);
+ }
+ return _PrimitiveObjects.getCharacter ((char) 0);
+ }
+ }
+
+ //-------------------------------------
+ /**
+ *
+ * Coerces a value to a Boolean
+ **/
+ public static Boolean coerceToBoolean (Object pValue)
+ throws ELException
+ {
+ if (pValue == null ||
+ "".equals (pValue)) {
+ return Boolean.FALSE;
+ }
+ else if (pValue instanceof Boolean) {
+ return (Boolean) pValue;
+ }
+ else if (pValue instanceof String) {
+ String str = (String) pValue;
+ try {
+ return Boolean.valueOf (str);
+ }
+ catch (Exception exc) {
+ if (log.isErrorEnabled()) {
+ String message = _MessageUtil.getMessageWithArgs(
+ _Constants.STRING_TO_BOOLEAN, (String) pValue);
+ log.error(message, exc);
+ throw new ELException(message, exc);
+ }
+ return Boolean.FALSE;
+ }
+ }
+ else {
+ if (log.isErrorEnabled()) {
+ String message = _MessageUtil.getMessageWithArgs(
+ _Constants.COERCE_TO_BOOLEAN,
+ pValue.getClass().getName());
+ log.error(message);
+ throw new ELException(message);
+ }
+ return Boolean.TRUE;
+ }
+ }
+
+ //-------------------------------------
+ /**
+ *
+ * Coerces a value to the specified Class that is not covered by any
+ * of the above cases
+ **/
+ public static Object coerceToObject (Object pValue, Class pClass)
+ throws ELException
+ {
+ if (pValue == null) {
+ return null;
+ }
+ else if (pClass.isAssignableFrom (pValue.getClass ())) {
+ return pValue;
+ }
+ else if (pValue instanceof String) {
+ String str = (String) pValue;
+ PropertyEditor pe = PropertyEditorManager.findEditor (pClass);
+ if (pe == null) {
+ if ("".equals (str)) {
+ return null;
+ }
+ else {
+ if (log.isErrorEnabled()) {
+ String message = _MessageUtil.getMessageWithArgs(
+ _Constants.NO_PROPERTY_EDITOR,
+ str, pClass.getName());
+ log.error(message);
+ throw new ELException(message);
+ }
+ return null;
+ }
+ }
+ try {
+ pe.setAsText (str);
+ return pe.getValue ();
+ }
+ catch (IllegalArgumentException exc) {
+ if ("".equals (str)) {
+ return null;
+ }
+ else {
+ if (log.isErrorEnabled()) {
+ String message = _MessageUtil.getMessageWithArgs(
+ _Constants.PROPERTY_EDITOR_ERROR,
+ pValue,
+ pClass.getName());
+ log.error(message, exc);
+ throw new ELException(message, exc);
+ }
+ return null;
+ }
+ }
+ }
+ else {
+ if (log.isErrorEnabled()) {
+ String message = _MessageUtil.getMessageWithArgs(
+ _Constants.COERCE_TO_OBJECT,
+ pValue.getClass().getName(),
+ pClass.getName());
+ log.error(message);
+ throw new ELException(message);
+ }
+ return null;
+ }
+ }
+
+ //-------------------------------------
+ // Applying operators
+ //-------------------------------------
+ /**
+ *
+ * Performs all of the necessary type conversions, then calls on the
+ * appropriate operator.
+ **/
+ /*
+ public static Object applyArithmeticOperator
+ (Object pLeft,
+ Object pRight,
+ ArithmeticOperator pOperator)
+ throws ELException
+ {
+ if (pLeft == null &&
+ pRight == null) {
+ if (log.isWarnEnabled()) {
+ log.warn(
+ MessageUtil.getMessageWithArgs(
+ Constants.ARITH_OP_NULL,
+ pOperator.getOperatorSymbol()));
+ }
+ return PrimitiveObjects.getInteger (0);
+ }
+
+ else if (isBigDecimal(pLeft) || isBigDecimal(pRight)) {
+ BigDecimal left = (BigDecimal)
+ coerceToPrimitiveNumber(pLeft, BigDecimal.class);
+ BigDecimal right = (BigDecimal)
+ coerceToPrimitiveNumber(pRight, BigDecimal.class);
+ return pOperator.apply(left, right);
+ }
+
+ else if (isFloatingPointType(pLeft) ||
+ isFloatingPointType(pRight) ||
+ isFloatingPointString(pLeft) ||
+ isFloatingPointString(pRight)) {
+ if (isBigInteger(pLeft) || isBigInteger(pRight)) {
+ BigDecimal left = (BigDecimal)
+ coerceToPrimitiveNumber(pLeft, BigDecimal.class);
+ BigDecimal right = (BigDecimal)
+ coerceToPrimitiveNumber(pRight, BigDecimal.class);
+ return pOperator.apply(left, right);
+ } else {
+ double left =
+ coerceToPrimitiveNumber(pLeft, Double.class).
+ doubleValue();
+ double right =
+ coerceToPrimitiveNumber(pRight, Double.class).
+ doubleValue();
+ return
+ PrimitiveObjects.getDouble(pOperator.apply(left, right));
+ }
+ }
+
+ else if (isBigInteger(pLeft) || isBigInteger(pRight)) {
+ BigInteger left = (BigInteger)
+ coerceToPrimitiveNumber(pLeft, BigInteger.class);
+ BigInteger right = (BigInteger)
+ coerceToPrimitiveNumber(pRight, BigInteger.class);
+ return pOperator.apply(left, right);
+ }
+
+ else {
+ long left =
+ coerceToPrimitiveNumber (pLeft, Long.class).
+ longValue ();
+ long right =
+ coerceToPrimitiveNumber (pRight, Long.class).
+ longValue ();
+ return
+ PrimitiveObjects.getLong (pOperator.apply (left, right));
+ }
+ }*/
+
+ //-------------------------------------
+ /**
+ *
+ * Performs all of the necessary type conversions, then calls on the
+ * appropriate operator.
+ **/
+ /*
+ public static Object applyRelationalOperator
+ (Object pLeft,
+ Object pRight,
+ RelationalOperator pOperator)
+ throws ELException
+ {
+ if (isBigDecimal(pLeft) || isBigDecimal(pRight)) {
+ BigDecimal left = (BigDecimal)
+ coerceToPrimitiveNumber(pLeft, BigDecimal.class);
+ BigDecimal right = (BigDecimal)
+ coerceToPrimitiveNumber(pRight, BigDecimal.class);
+ return PrimitiveObjects.getBoolean(pOperator.apply(left, right));
+ }
+
+ else if (isFloatingPointType (pLeft) ||
+ isFloatingPointType (pRight)) {
+ double left =
+ coerceToPrimitiveNumber (pLeft, Double.class).
+ doubleValue ();
+ double right =
+ coerceToPrimitiveNumber (pRight, Double.class).
+ doubleValue ();
+ return
+ PrimitiveObjects.getBoolean (pOperator.apply (left, right));
+ }
+
+ else if (isBigInteger(pLeft) || isBigInteger(pRight)) {
+ BigInteger left = (BigInteger)
+ coerceToPrimitiveNumber(pLeft, BigInteger.class);
+ BigInteger right = (BigInteger)
+ coerceToPrimitiveNumber(pRight, BigInteger.class);
+ return PrimitiveObjects.getBoolean(pOperator.apply(left, right));
+ }
+
+ else if (isIntegerType (pLeft) ||
+ isIntegerType (pRight)) {
+ long left =
+ coerceToPrimitiveNumber (pLeft, Long.class).
+ longValue ();
+ long right =
+ coerceToPrimitiveNumber (pRight, Long.class).
+ longValue ();
+ return
+ PrimitiveObjects.getBoolean (pOperator.apply (left, right));
+ }
+
+ else if (pLeft instanceof String ||
+ pRight instanceof String) {
+ String left = coerceToString (pLeft);
+ String right = coerceToString (pRight);
+ return
+ PrimitiveObjects.getBoolean (pOperator.apply (left, right));
+ }
+
+ else if (pLeft instanceof Comparable) {
+ try {
+ int result = ((Comparable) pLeft).compareTo (pRight);
+ return
+ PrimitiveObjects.getBoolean
+ (pOperator.apply (result, -result));
+ }
+ catch (Exception exc) {
+ if (log.isErrorEnabled()) {
+ String message = MessageUtil.getMessageWithArgs(
+ Constants.COMPARABLE_ERROR,
+ pLeft.getClass().getName(),
+ (pRight == null) ? "null" : pRight.getClass().getName(),
+ pOperator.getOperatorSymbol());
+ log.error(message, exc);
+ throw new ELException(message, exc);
+ }
+ return Boolean.FALSE;
+ }
+ }
+
+ else if (pRight instanceof Comparable) {
+ try {
+ int result = ((Comparable) pRight).compareTo (pLeft);
+ return
+ PrimitiveObjects.getBoolean
+ (pOperator.apply (-result, result));
+ }
+ catch (Exception exc) {
+ if (log.isErrorEnabled()) {
+ String message = MessageUtil.getMessageWithArgs(
+ Constants.COMPARABLE_ERROR,
+ pRight.getClass().getName(),
+ (pLeft == null) ? "null" : pLeft.getClass().getName(),
+ pOperator.getOperatorSymbol());
+ log.error(message, exc);
+ throw new ELException(message, exc);
+ }
+ return Boolean.FALSE;
+ }
+ }
+
+ else {
+ if (log.isErrorEnabled()) {
+ String message = MessageUtil.getMessageWithArgs(
+ Constants.ARITH_OP_BAD_TYPE,
+ pOperator.getOperatorSymbol(),
+ pLeft.getClass().getName(),
+ pRight.getClass().getName());
+ log.error(message);
+ throw new ELException(message);
+ }
+ return Boolean.FALSE;
+ }
+ }*/
+
+ //-------------------------------------
+ /**
+ *
+ * Performs all of the necessary type conversions, then calls on the
+ * appropriate operator.
+ **/
+ /*
+ public static Object applyEqualityOperator
+ (Object pLeft,
+ Object pRight,
+ EqualityOperator pOperator)
+ throws ELException
+ {
+ if (pLeft == pRight) {
+ return PrimitiveObjects.getBoolean (pOperator.apply (true));
+ }
+
+ else if (pLeft == null ||
+ pRight == null) {
+ return PrimitiveObjects.getBoolean (pOperator.apply (false));
+ }
+
+ else if (isBigDecimal(pLeft) || isBigDecimal(pRight)) {
+ BigDecimal left = (BigDecimal)
+ coerceToPrimitiveNumber(pLeft, BigDecimal.class);
+ BigDecimal right = (BigDecimal)
+ coerceToPrimitiveNumber(pRight, BigDecimal.class);
+ return PrimitiveObjects.getBoolean(pOperator.apply(left.equals(right)));
+ }
+
+ else if (isFloatingPointType (pLeft) ||
+ isFloatingPointType (pRight)) {
+ double left =
+ coerceToPrimitiveNumber (pLeft, Double.class).
+ doubleValue ();
+ double right =
+ coerceToPrimitiveNumber (pRight, Double.class).
+ doubleValue ();
+ return
+ PrimitiveObjects.getBoolean
+ (pOperator.apply (left == right));
+ }
+
+ else if (isBigInteger(pLeft) || isBigInteger(pRight)) {
+ BigInteger left = (BigInteger)
+ coerceToPrimitiveNumber(pLeft, BigInteger.class);
+ BigInteger right = (BigInteger)
+ coerceToPrimitiveNumber(pRight, BigInteger.class);
+ return PrimitiveObjects.getBoolean(pOperator.apply(left.equals(right)));
+ }
+
+ else if (isIntegerType (pLeft) ||
+ isIntegerType (pRight)) {
+ long left =
+ coerceToPrimitiveNumber (pLeft, Long.class).
+ longValue ();
+ long right =
+ coerceToPrimitiveNumber (pRight, Long.class).
+ longValue ();
+ return
+ PrimitiveObjects.getBoolean
+ (pOperator.apply (left == right));
+ }
+
+ else if (pLeft instanceof Boolean ||
+ pRight instanceof Boolean) {
+ boolean left = coerceToBoolean (pLeft).booleanValue ();
+ boolean right = coerceToBoolean (pRight).booleanValue ();
+ return
+ PrimitiveObjects.getBoolean
+ (pOperator.apply (left == right));
+ }
+
+ else if (pLeft instanceof String ||
+ pRight instanceof String) {
+ String left = coerceToString (pLeft);
+ String right = coerceToString (pRight);
+ return
+ PrimitiveObjects.getBoolean
+ (pOperator.apply (left.equals (right)));
+ }
+
+ else {
+ try {
+ return
+ PrimitiveObjects.getBoolean
+ (pOperator.apply (pLeft.equals (pRight)));
+ }
+ catch (Exception exc) {
+ if (log.isErrorEnabled()) {
+ String message = MessageUtil.getMessageWithArgs(
+ Constants.ERROR_IN_EQUALS,
+ pLeft.getClass().getName(),
+ pRight.getClass().getName(),
+ pOperator.getOperatorSymbol());
+ log.error(message, exc);
+ throw new ELException(message, exc);
+ }
+ return Boolean.FALSE;
+ }
+ }
+ }*/
+
+ //-------------------------------------
+ /**
+ *
+ * Returns true if the given Object is of a floating point type
+ **/
+ public static boolean isFloatingPointType (Object pObject)
+ {
+ return
+ pObject != null &&
+ isFloatingPointType (pObject.getClass ());
+ }
+
+ //-------------------------------------
+ /**
+ *
+ * Returns true if the given class is of a floating point type
+ **/
+ public static boolean isFloatingPointType (Class pClass)
+ {
+ return
+ pClass == Float.class ||
+ pClass == Float.TYPE ||
+ pClass == Double.class ||
+ pClass == Double.TYPE;
+ }
+
+ //-------------------------------------
+ /**
+ *
+ * Returns true if the given string might contain a floating point
+ * number - i.e., it contains ".", "e", or "E"
+ **/
+ 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;
+ }
+ else {
+ return false;
+ }
+ }
+
+ //-------------------------------------
+ /**
+ *
+ * Returns true if the given Object is of an integer type
+ **/
+ public static boolean isIntegerType (Object pObject)
+ {
+ return
+ pObject != null &&
+ isIntegerType (pObject.getClass ());
+ }
+
+ //-------------------------------------
+ /**
+ *
+ * Returns true if the given class is of an integer type
+ **/
+ 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;
+ }
+
+ //-------------------------------------
+
+ /**
+ * Returns true if the given object is BigInteger.
+ * @param pObject - Object to evaluate
+ * @return - true if the given object is BigInteger
+ */
+ public static boolean isBigInteger(Object pObject) {
+ return
+ pObject != null && pObject instanceof BigInteger;
+ }
+
+ /**
+ * Returns true if the given object is BigDecimal.
+ * @param pObject - Object to evaluate
+ * @return - true if the given object is BigDecimal
+ */
+ public static boolean isBigDecimal(Object pObject) {
+ return
+ pObject != null && pObject instanceof BigDecimal;
+ }
+}
Added: myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/_Constants.java
URL: http://svn.apache.org/viewvc/myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/_Constants.java?rev=925490&view=auto
==============================================================================
--- myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/_Constants.java (added)
+++ myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/_Constants.java Sat Mar 20 00:00:09 2010
@@ -0,0 +1,207 @@
+/*
+ * 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 org.apache.myfaces.shared.util;
+
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+/**
+ *
+ * <p>This contains all of the non-public constants, including
+ * messsage strings read from the resource file.
+ *
+ * This is a copy from commons-el PrimitiveObjects class
+ *
+ * @author Nathan Abramson - Art Technology Group
+ * @author Shawn Bayern
+ *
+ * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
+ **/
+
+class _Constants
+{
+ //-------------------------------------
+ // Resources
+
+ static ResourceBundle sResources =
+ ResourceBundle.getBundle ("org.apache.commons.el.Resources");
+
+ //-------------------------------------
+ // Messages from the resource bundle
+ //-------------------------------------
+
+ public static final String EXCEPTION_GETTING_BEANINFO =
+ getStringResource ("EXCEPTION_GETTING_BEANINFO");
+
+ public static final String NULL_EXPRESSION_STRING =
+ getStringResource ("NULL_EXPRESSION_STRING");
+
+ public static final String PARSE_EXCEPTION =
+ getStringResource ("PARSE_EXCEPTION");
+
+ public static final String CANT_GET_PROPERTY_OF_NULL =
+ getStringResource ("CANT_GET_PROPERTY_OF_NULL");
+
+ public static final String NO_SUCH_PROPERTY =
+ getStringResource ("NO_SUCH_PROPERTY");
+
+ public static final String NO_GETTER_METHOD =
+ getStringResource ("NO_GETTER_METHOD");
+
+ public static final String ERROR_GETTING_PROPERTY =
+ getStringResource ("ERROR_GETTING_PROPERTY");
+
+ public static final String CANT_GET_INDEXED_VALUE_OF_NULL =
+ getStringResource ("CANT_GET_INDEXED_VALUE_OF_NULL");
+
+ public static final String CANT_GET_NULL_INDEX =
+ getStringResource ("CANT_GET_NULL_INDEX");
+
+ public static final String NULL_INDEX =
+ getStringResource ("NULL_INDEX");
+
+ public static final String BAD_INDEX_VALUE =
+ getStringResource ("BAD_INDEX_VALUE");
+
+ public static final String EXCEPTION_ACCESSING_LIST =
+ getStringResource ("EXCEPTION_ACCESSING_LIST");
+
+ public static final String EXCEPTION_ACCESSING_ARRAY =
+ getStringResource ("EXCEPTION_ACCESSING_ARRAY");
+
+ public static final String CANT_FIND_INDEX =
+ getStringResource ("CANT_FIND_INDEX");
+
+ public static final String TOSTRING_EXCEPTION =
+ getStringResource ("TOSTRING_EXCEPTION");
+
+ public static final String BOOLEAN_TO_NUMBER =
+ getStringResource ("BOOLEAN_TO_NUMBER");
+
+ public static final String STRING_TO_NUMBER_EXCEPTION =
+ getStringResource ("STRING_TO_NUMBER_EXCEPTION");
+
+ public static final String COERCE_TO_NUMBER =
+ getStringResource ("COERCE_TO_NUMBER");
+
+ public static final String BOOLEAN_TO_CHARACTER =
+ getStringResource ("BOOLEAN_TO_CHARACTER");
+
+ public static final String EMPTY_STRING_TO_CHARACTER =
+ getStringResource ("EMPTY_STRING_TO_CHARACTER");
+
+ public static final String COERCE_TO_CHARACTER =
+ getStringResource ("COERCE_TO_CHARACTER");
+
+ public static final String NULL_TO_BOOLEAN =
+ getStringResource ("NULL_TO_BOOLEAN");
+
+ public static final String STRING_TO_BOOLEAN =
+ getStringResource ("STRING_TO_BOOLEAN");
+
+ public static final String COERCE_TO_BOOLEAN =
+ getStringResource ("COERCE_TO_BOOLEAN");
+
+ public static final String COERCE_TO_OBJECT =
+ getStringResource ("COERCE_TO_OBJECT");
+
+ public static final String NO_PROPERTY_EDITOR =
+ getStringResource ("NO_PROPERTY_EDITOR");
+
+ public static final String PROPERTY_EDITOR_ERROR =
+ getStringResource ("PROPERTY_EDITOR_ERROR");
+
+ public static final String ARITH_OP_NULL =
+ getStringResource ("ARITH_OP_NULL");
+
+ public static final String ARITH_OP_BAD_TYPE =
+ getStringResource ("ARITH_OP_BAD_TYPE");
+
+ public static final String ARITH_ERROR =
+ getStringResource ("ARITH_ERROR");
+
+ public static final String ERROR_IN_EQUALS =
+ getStringResource ("ERROR_IN_EQUALS");
+
+ public static final String UNARY_OP_BAD_TYPE =
+ getStringResource ("UNARY_OP_BAD_TYPE");
+
+ public static final String NAMED_VALUE_NOT_FOUND =
+ getStringResource ("NAMED_VALUE_NOT_FOUND");
+
+ public static final String CANT_GET_INDEXED_PROPERTY =
+ getStringResource ("CANT_GET_INDEXED_PROPERTY");
+
+ public static final String COMPARABLE_ERROR =
+ getStringResource ("COMPARABLE_ERROR");
+
+ public static final String BAD_IMPLICIT_OBJECT =
+ getStringResource ("BAD_IMPLICIT_OBJECT");
+
+ public static final String ATTRIBUTE_EVALUATION_EXCEPTION =
+ getStringResource ("ATTRIBUTE_EVALUATION_EXCEPTION");
+
+ public static final String ATTRIBUTE_PARSE_EXCEPTION =
+ getStringResource ("ATTRIBUTE_PARSE_EXCEPTION");
+
+ public static final String UNKNOWN_FUNCTION =
+ getStringResource ("UNKNOWN_FUNCTION");
+
+ public static final String INAPPROPRIATE_FUNCTION_ARG_COUNT =
+ getStringResource ("INAPPROPRIATE_FUNCTION_ARG_COUNT");
+
+ public static final String FUNCTION_INVOCATION_ERROR =
+ getStringResource ("FUNCTION_INVOCATION_ERROR");
+
+
+ //-------------------------------------
+ // Getting resources
+ //-------------------------------------
+ /**
+ *
+ *
+ **/
+ public static String getStringResource (String pResourceName)
+ throws MissingResourceException
+ {
+ try {
+ String ret = sResources.getString (pResourceName);
+ if (ret == null) {
+ String str = "ERROR: Unable to load resource " + pResourceName;
+ System.err.println (str);
+ throw new MissingResourceException
+ (str,
+ "org.apache.commons.el.Constants",
+ pResourceName);
+ }
+ else {
+ return ret;
+ }
+ }
+ catch (MissingResourceException exc) {
+ System.err.println ("ERROR: Unable to load resource " +
+ pResourceName +
+ ": " +
+ exc);
+ throw exc;
+ }
+ }
+
+ //-------------------------------------
+}
Added: myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/_MessageUtil.java
URL: http://svn.apache.org/viewvc/myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/_MessageUtil.java?rev=925490&view=auto
==============================================================================
--- myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/_MessageUtil.java (added)
+++ myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/_MessageUtil.java Sat Mar 20 00:00:09 2010
@@ -0,0 +1,147 @@
+/*
+ * 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 org.apache.myfaces.shared.util;
+
+import java.text.MessageFormat;
+
+/**
+ * <p>Utility class for generating parameterized messages.</p>
+ *
+ * This is a copy from commons-el MessageUtil class.
+ *
+ * @version $Id$
+ */
+
+class _MessageUtil
+{
+
+ /**
+ * <p>Returns a formatted message based on the provided template and
+ * a single parameter.</p>
+ * @param pTemplate the base message
+ * @param pArg0 parameter
+ * @return Returns a formatted message based on the provided template and
+ * a single parameter.
+ */
+ public static String getMessageWithArgs(String pTemplate, Object pArg0) {
+ return MessageFormat.format(pTemplate, new Object[]{ "" + pArg0 });
+ }
+
+ /**
+ * <p>Returns a formatted message based on the provided template and
+ * provided parameter.</p>
+ * @param pTemplate the base message
+ * @param pArg0 parameter 1
+ * @param pArg1 parameter 2
+ * @return Returns a formatted message based on the provided template and
+ * provided parameter
+ */
+ public static String getMessageWithArgs(String pTemplate, Object pArg0, Object pArg1) {
+ return MessageFormat.format(pTemplate, new Object[]{"" + pArg0, "" + pArg1 });
+ }
+
+ /**
+ * <p>Returns a formatted message based on the provided template and
+ * provided parameter.</p>
+ * @param pTemplate the base message
+ * @param pArg0 parameter 1
+ * @param pArg1 parameter 2
+ * @param pArg2 parameter 3
+ * @return Returns a formatted message based on the provided template and
+ * provided parameter
+ */
+ public static String getMessageWithArgs(String pTemplate, Object pArg0, Object pArg1, Object pArg2) {
+ return MessageFormat.format(pTemplate, new Object[]{
+ "" + pArg0,
+ "" + pArg1,
+ "" + pArg2
+ });
+ }
+
+ /**
+ * <p>Returns a formatted message based on the provided template and
+ * provided parameter.</p>
+ * @param pTemplate the base message
+ * @param pArg0 parameter 1
+ * @param pArg1 parameter 2
+ * @param pArg2 parameter 3
+ * @param pArg3 parameter 4
+ * @return Returns a formatted message based on the provided template and
+ * provided parameter
+ */
+ public static String getMessageWithArgs(String pTemplate, Object pArg0, Object pArg1, Object pArg2, Object pArg3) {
+ return MessageFormat.format(
+ pTemplate, new Object[]{
+ "" + pArg0,
+ "" + pArg1,
+ "" + pArg2,
+ "" + pArg3
+ });
+ }
+
+ /**
+ * <p>Returns a formatted message based on the provided template and
+ * provided parameter.</p>
+ * @param pTemplate the base message
+ * @param pArg0 parameter 1
+ * @param pArg1 parameter 2
+ * @param pArg2 parameter 3
+ * @param pArg3 parameter 4
+ * @param pArg4 parameter 5
+ * @return Returns a formatted message based on the provided template and
+ * provided parameter
+ */
+ public static String getMessageWithArgs(String pTemplate, Object pArg0, Object pArg1, Object pArg2, Object pArg3, Object pArg4) {
+ return MessageFormat.format(
+ pTemplate, new Object[]{
+ "" + pArg0,
+ "" + pArg1,
+ "" + pArg2,
+ "" + pArg3,
+ "" + pArg4
+ });
+ }
+
+ /**
+ * <p>Returns a formatted message based on the provided template and
+ * provided parameter.</p>
+ * @param pTemplate the base message
+ * @param pArg0 parameter 1
+ * @param pArg1 parameter 2
+ * @param pArg2 parameter 3
+ * @param pArg3 parameter 4
+ * @param pArg4 parameter 5
+ * @param pArg5 parameter 6
+ * @return Returns a formatted message based on the provided template and
+ * provided parameter
+ */
+ public static String getMessageWithArgs(
+ String pTemplate, Object pArg0, Object pArg1, Object pArg2, Object pArg3,
+ Object pArg4, Object pArg5) {
+ return MessageFormat.format(
+ pTemplate, new Object[]{
+ "" + pArg0,
+ "" + pArg1,
+ "" + pArg2,
+ "" + pArg3,
+ "" + pArg4,
+ "" + pArg5
+ });
+ }
+}
Added: myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/_PrimitiveObjects.java
URL: http://svn.apache.org/viewvc/myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/_PrimitiveObjects.java?rev=925490&view=auto
==============================================================================
--- myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/_PrimitiveObjects.java (added)
+++ myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/_PrimitiveObjects.java Sat Mar 20 00:00:09 2010
@@ -0,0 +1,246 @@
+/*
+ * 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 org.apache.myfaces.shared.util;
+
+/**
+ *
+ * <p>This converts primitive values to their Object counterparts.
+ * For bytes and chars, values from 0 to 255 are cached. For shorts,
+ * ints, and longs, values -1000 to 1000 are cached.
+ *
+ * This is a copy from commons-el PrimitiveObjects class.
+ *
+ * @author Nathan Abramson - Art Technology Group
+ * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
+ **/
+
+class _PrimitiveObjects
+{
+ //-------------------------------------
+ // Constants
+ //-------------------------------------
+
+ static int BYTE_LOWER_BOUND = 0;
+ static int BYTE_UPPER_BOUND = 255;
+ static int CHARACTER_LOWER_BOUND = 0;
+ static int CHARACTER_UPPER_BOUND = 255;
+ static int SHORT_LOWER_BOUND = -1000;
+ static int SHORT_UPPER_BOUND = 1000;
+ static int INTEGER_LOWER_BOUND = -1000;
+ static int INTEGER_UPPER_BOUND = 1000;
+ static int LONG_LOWER_BOUND = -1000;
+ static int LONG_UPPER_BOUND = 1000;
+
+ //-------------------------------------
+ // Member variables
+ //-------------------------------------
+
+ static Byte [] mBytes = createBytes ();
+ static Character [] mCharacters = createCharacters ();
+ static Short [] mShorts = createShorts ();
+ static Integer [] mIntegers = createIntegers ();
+ static Long [] mLongs = createLongs ();
+
+ //-------------------------------------
+ // Getting primitive values
+ //-------------------------------------
+ public static Boolean getBoolean (boolean pValue)
+ {
+ return
+ pValue ?
+ Boolean.TRUE :
+ Boolean.FALSE;
+ }
+
+ //-------------------------------------
+ public static Byte getByte (byte pValue)
+ {
+ if (pValue >= BYTE_LOWER_BOUND &&
+ pValue <= BYTE_UPPER_BOUND) {
+ return mBytes [((int) pValue) - BYTE_LOWER_BOUND];
+ }
+ else {
+ return new Byte (pValue);
+ }
+ }
+
+ //-------------------------------------
+ public static Character getCharacter (char pValue)
+ {
+ if (pValue >= CHARACTER_LOWER_BOUND &&
+ pValue <= CHARACTER_UPPER_BOUND) {
+ return mCharacters [((int) pValue) - CHARACTER_LOWER_BOUND];
+ }
+ else {
+ return new Character (pValue);
+ }
+ }
+
+ //-------------------------------------
+ public static Short getShort (short pValue)
+ {
+ if (pValue >= SHORT_LOWER_BOUND &&
+ pValue <= SHORT_UPPER_BOUND) {
+ return mShorts [((int) pValue) - SHORT_LOWER_BOUND];
+ }
+ else {
+ return new Short (pValue);
+ }
+ }
+
+ //-------------------------------------
+ public static Integer getInteger (int pValue)
+ {
+ if (pValue >= INTEGER_LOWER_BOUND &&
+ pValue <= INTEGER_UPPER_BOUND) {
+ return mIntegers [((int) pValue) - INTEGER_LOWER_BOUND];
+ }
+ else {
+ return new Integer (pValue);
+ }
+ }
+
+ //-------------------------------------
+ public static Long getLong (long pValue)
+ {
+ if (pValue >= LONG_LOWER_BOUND &&
+ pValue <= LONG_UPPER_BOUND) {
+ return mLongs [((int) pValue) - LONG_LOWER_BOUND];
+ }
+ else {
+ return new Long (pValue);
+ }
+ }
+
+ //-------------------------------------
+ public static Float getFloat (float pValue)
+ {
+ return new Float (pValue);
+ }
+
+ //-------------------------------------
+ public static Double getDouble (double pValue)
+ {
+ return new Double (pValue);
+ }
+
+ //-------------------------------------
+ // Object class equivalents of primitive classes
+ //-------------------------------------
+ /**
+ *
+ * If the given class is a primitive class, returns the object
+ * version of that class. Otherwise, the class is just returned.
+ **/
+ public static Class getPrimitiveObjectClass (Class pClass)
+ {
+ if (pClass == Boolean.TYPE) {
+ return Boolean.class;
+ }
+ else if (pClass == Byte.TYPE) {
+ return Byte.class;
+ }
+ else if (pClass == Short.TYPE) {
+ return Short.class;
+ }
+ else if (pClass == Character.TYPE) {
+ return Character.class;
+ }
+ else if (pClass == Integer.TYPE) {
+ return Integer.class;
+ }
+ else if (pClass == Long.TYPE) {
+ return Long.class;
+ }
+ else if (pClass == Float.TYPE) {
+ return Float.class;
+ }
+ else if (pClass == Double.TYPE) {
+ return Double.class;
+ }
+ else {
+ return pClass;
+ }
+ }
+
+ //-------------------------------------
+ // Initializing the cached values
+ //-------------------------------------
+ static Byte [] createBytes ()
+ {
+ int len = BYTE_UPPER_BOUND - BYTE_LOWER_BOUND + 1;
+ Byte [] ret = new Byte [len];
+ byte val = (byte) BYTE_LOWER_BOUND;
+ for (int i = 0; i < len; i++, val++) {
+ ret [i] = new Byte (val);
+ }
+ return ret;
+ }
+
+ //-------------------------------------
+ static Character [] createCharacters ()
+ {
+ int len = CHARACTER_UPPER_BOUND - CHARACTER_LOWER_BOUND + 1;
+ Character [] ret = new Character [len];
+ char val = (char) CHARACTER_LOWER_BOUND;
+ for (int i = 0; i < len; i++, val++) {
+ ret [i] = new Character (val);
+ }
+ return ret;
+ }
+
+ //-------------------------------------
+ static Short [] createShorts ()
+ {
+ int len = SHORT_UPPER_BOUND - SHORT_LOWER_BOUND + 1;
+ Short [] ret = new Short [len];
+ short val = (short) SHORT_LOWER_BOUND;
+ for (int i = 0; i < len; i++, val++) {
+ ret [i] = new Short (val);
+ }
+ return ret;
+ }
+
+ //-------------------------------------
+ static Integer [] createIntegers ()
+ {
+ int len = INTEGER_UPPER_BOUND - INTEGER_LOWER_BOUND + 1;
+ Integer [] ret = new Integer [len];
+ int val = (int) INTEGER_LOWER_BOUND;
+ for (int i = 0; i < len; i++, val++) {
+ ret [i] = new Integer (val);
+ }
+ return ret;
+ }
+
+ //-------------------------------------
+ static Long [] createLongs ()
+ {
+ int len = LONG_UPPER_BOUND - LONG_LOWER_BOUND + 1;
+ Long [] ret = new Long [len];
+ long val = (long) LONG_LOWER_BOUND;
+ for (int i = 0; i < len; i++, val++) {
+ ret [i] = new Long (val);
+ }
+ return ret;
+ }
+
+ //-------------------------------------
+
+}
Modified: myfaces/shared/trunk/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/shared/trunk/pom.xml?rev=925490&r1=925489&r2=925490&view=diff
==============================================================================
--- myfaces/shared/trunk/pom.xml (original)
+++ myfaces/shared/trunk/pom.xml Sat Mar 20 00:00:09 2010
@@ -113,14 +113,14 @@
<version>1.0</version>
<scope>provided</scope>
</dependency>
-
+<!--
<dependency>
<groupId>commons-el</groupId>
<artifactId>commons-el</artifactId>
<version>1.0</version>
<scope>compile</scope>
</dependency>
-
+ -->
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>