Skip to content

Package: TypeConverter

TypeConverter

nameinstructionbranchcomplexitylinemethod
TypeConverter()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getCommonPropertyType(ELContext, Object)
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getType(ELContext, Object, Object)
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getValue(ELContext, Object, Object)
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
isReadOnly(ELContext, Object, Object)
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
setValue(ELContext, Object, Object, Object)
M: 1 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * Copyright (c) 2012, 2022 Oracle and/or its affiliates and others.
3: * All rights reserved.
4: *
5: * This program and the accompanying materials are made available under the
6: * terms of the Eclipse Public License v. 2.0, which is available at
7: * http://www.eclipse.org/legal/epl-2.0.
8: *
9: * This Source Code may also be made available under the following Secondary
10: * Licenses when the conditions for such availability set forth in the
11: * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
12: * version 2 with the GNU Classpath Exception, which is available at
13: * https://www.gnu.org/software/classpath/license.html.
14: *
15: * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16: */
17:
18: package jakarta.el;
19:
20: /**
21: * A convenient class for writing an ELResolver to do custom type conversions.
22: *
23: * <p>
24: * For example, to convert a String to an instance of MyDate, one can write
25: *
26: * <pre>
27: * <code>
28: * ELProcessor elp = new ELProcessor();
29: * elp.getELManager().addELResolver(new TypeConverter() {
30: * Object convertToType(ELContext context, Object obj, Class<?> type) {
31: * if ((obj instanceof String) && type == MyDate.class) {
32: * context.setPropertyResolved(obj, type);
33: * return (obj == null)? null: new MyDate(obj.toString());
34: * }
35: * return null;
36: * }
37: * };
38: * </code>
39: * </pre>
40: *
41: * @since Jakarta Expression Language 3.0
42: */
43: public abstract class TypeConverter extends ELResolver {
44:
45: @Override
46: public Object getValue(ELContext context, Object base, Object property) {
47: return null;
48: }
49:
50: @Override
51: public Class<?> getType(ELContext context, Object base, Object property) {
52: return null;
53: }
54:
55: @Override
56: public void setValue(ELContext context, Object base, Object property, Object value) {
57: }
58:
59: @Override
60: public boolean isReadOnly(ELContext context, Object base, Object property) {
61: return false;
62: }
63:
64: @Override
65: public Class<?> getCommonPropertyType(ELContext context, Object base) {
66: return null;
67: }
68:
69: /**
70: * Converts an object to a specific type.
71: *
72: * <p>
73: * An <code>ELException</code> is thrown if an error occurs during the conversion.
74: * </p>
75: *
76: * @param context The context of this evaluation.
77: * @param obj The object to convert.
78: * @param targetType The target type for the conversion.
79: * @throws ELException thrown if errors occur.
80: */
81: @Override
82: abstract public <T> T convertToType(ELContext context, Object obj, Class<T> targetType);
83: }