(final ELContext ctx, final Object obj)
| 274 | } |
| 275 | |
| 276 | private static Character coerceToCharacter(final ELContext ctx, final Object obj) throws ELException { |
| 277 | |
| 278 | if (ctx != null) { |
| 279 | boolean originalIsPropertyResolved = ctx.isPropertyResolved(); |
| 280 | try { |
| 281 | Character result = ctx.getELResolver().convertToType(ctx, obj, Character.class); |
| 282 | if (ctx.isPropertyResolved()) { |
| 283 | return result; |
| 284 | } |
| 285 | } finally { |
| 286 | ctx.setPropertyResolved(originalIsPropertyResolved); |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | if (obj == null || "".equals(obj)) { |
| 291 | return Character.valueOf((char) 0); |
| 292 | } |
| 293 | if (obj instanceof String) { |
| 294 | return Character.valueOf(((String) obj).charAt(0)); |
| 295 | } |
| 296 | if (ELArithmetic.isNumber(obj)) { |
| 297 | return Character.valueOf((char) ((Number) obj).shortValue()); |
| 298 | } |
| 299 | Class<?> objType = obj.getClass(); |
| 300 | if (obj instanceof Character) { |
| 301 | return (Character) obj; |
| 302 | } |
| 303 | |
| 304 | throw new ELException(MessageFactory.get("error.convert", obj, objType, Character.class)); |
| 305 | } |
| 306 | |
| 307 | /** |
| 308 | * Coerces a Number to the specified numeric type. |
no test coverage detected