Package: ValueExpressionLiteral
ValueExpressionLiteral
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ValueExpressionLiteral() |
|
|
|
|
|
||||||||||||||||||||
ValueExpressionLiteral(Object, Class) |
|
|
|
|
|
||||||||||||||||||||
equals(Object) |
|
|
|
|
|
||||||||||||||||||||
equals(ValueExpressionLiteral) |
|
|
|
|
|
||||||||||||||||||||
getExpectedType() |
|
|
|
|
|
||||||||||||||||||||
getExpressionString() |
|
|
|
|
|
||||||||||||||||||||
getType(ELContext) |
|
|
|
|
|
||||||||||||||||||||
getValue(ELContext) |
|
|
|
|
|
||||||||||||||||||||
hashCode() |
|
|
|
|
|
||||||||||||||||||||
isLiteralText() |
|
|
|
|
|
||||||||||||||||||||
isReadOnly(ELContext) |
|
|
|
|
|
||||||||||||||||||||
readExternal(ObjectInput) |
|
|
|
|
|
||||||||||||||||||||
setValue(ELContext, Object) |
|
|
|
|
|
||||||||||||||||||||
writeExternal(ObjectOutput) |
|
|
|
|
|
Coverage
1: /*
2: * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
3: *
4: * This program and the accompanying materials are made available under the
5: * terms of the Eclipse Public License v. 2.0, which is available at
6: * http://www.eclipse.org/legal/epl-2.0.
7: *
8: * This Source Code may also be made available under the following Secondary
9: * Licenses when the conditions for such availability set forth in the
10: * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11: * version 2 with the GNU Classpath Exception, which is available at
12: * https://www.gnu.org/software/classpath/license.html.
13: *
14: * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15: */
16:
17: package com.sun.el;
18:
19: import static com.sun.el.util.ReflectionUtil.forName;
20:
21: import java.io.Externalizable;
22: import java.io.IOException;
23: import java.io.ObjectInput;
24: import java.io.ObjectOutput;
25:
26: import jakarta.el.ELContext;
27: import jakarta.el.ELException;
28: import jakarta.el.PropertyNotWritableException;
29: import jakarta.el.ValueExpression;
30:
31: import com.sun.el.util.MessageFactory;
32:
33: public final class ValueExpressionLiteral extends ValueExpression implements Externalizable {
34:
35: private static final long serialVersionUID = 1L;
36:
37: private Object value;
38: private Class<?> expectedType;
39:
40: public ValueExpressionLiteral() {
41: super();
42: }
43:
44: public ValueExpressionLiteral(Object value, Class<?> expectedType) {
45: this.value = value;
46: this.expectedType = expectedType;
47: }
48:
49: @Override
50: public Object getValue(ELContext context) {
51:• if (expectedType != null) {
52: try {
53: return context.convertToType(value, expectedType);
54: } catch (IllegalArgumentException ex) {
55: throw new ELException(ex);
56: }
57: }
58:
59: return value;
60: }
61:
62: @Override
63: public void setValue(ELContext context, Object value) {
64: throw new PropertyNotWritableException(MessageFactory.get("error.value.literal.write", value));
65: }
66:
67: @Override
68: public boolean isReadOnly(ELContext context) {
69: return true;
70: }
71:
72: @Override
73: public Class<?> getType(ELContext context) {
74:• return value != null ? value.getClass() : null;
75: }
76:
77: @Override
78: public Class<?> getExpectedType() {
79: return expectedType;
80: }
81:
82: @Override
83: public String getExpressionString() {
84:• return value != null ? value.toString() : null;
85: }
86:
87: @Override
88: public boolean equals(Object obj) {
89:• return obj instanceof ValueExpressionLiteral && this.equals((ValueExpressionLiteral) obj);
90: }
91:
92: public boolean equals(ValueExpressionLiteral ve) {
93:• return (ve != null && (this.value != null && ve.value != null && (this.value == ve.value || this.value.equals(ve.value))));
94: }
95:
96: @Override
97: public int hashCode() {
98:• return value != null ? value.hashCode() : 0;
99: }
100:
101: @Override
102: public boolean isLiteralText() {
103: return true;
104: }
105:
106: @Override
107: public void writeExternal(ObjectOutput out) throws IOException {
108: out.writeObject(value);
109:• out.writeUTF(expectedType != null ? expectedType.getName() : "");
110: }
111:
112: @Override
113: public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
114: value = in.readObject();
115: String type = in.readUTF();
116:• if (!"".equals(type)) {
117: expectedType = forName(type);
118: }
119: }
120: }