Skip to contentMethod: equals(Object)
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.toTypeArray;
20: import static com.sun.el.util.ReflectionUtil.toTypeNameArray;
21:
22: import java.io.Externalizable;
23: import java.io.IOException;
24: import java.io.ObjectInput;
25: import java.io.ObjectOutput;
26:
27: import jakarta.el.ELContext;
28: import jakarta.el.ELException;
29: import jakarta.el.MethodExpression;
30: import jakarta.el.MethodInfo;
31:
32: import com.sun.el.util.ReflectionUtil;
33:
34: public class MethodExpressionLiteral extends MethodExpression implements Externalizable {
35:
36: private Class<?> expectedType;
37: private String expr;
38: private Class<?>[] paramTypes;
39:
40: public MethodExpressionLiteral() {
41: // do nothing
42: }
43:
44: public MethodExpressionLiteral(String expr, Class<?> expectedType, Class<?>[] paramTypes) {
45: this.expr = expr;
46: this.expectedType = expectedType;
47: this.paramTypes = paramTypes;
48: }
49:
50: @Override
51: public MethodInfo getMethodInfo(ELContext context) throws ELException {
52: return new MethodInfo(expr, expectedType, paramTypes);
53: }
54:
55: @Override
56: public Object invoke(ELContext context, Object[] params) throws ELException {
57: if (expectedType == null) {
58: return expr;
59: }
60:
61: try {
62: return context.convertToType(expr, expectedType);
63: } catch (Exception ex) {
64: throw new ELException(ex);
65: }
66: }
67:
68: @Override
69: public String getExpressionString() {
70: return expr;
71: }
72:
73: @Override
74: public boolean equals(Object obj) {
75:• return obj instanceof MethodExpressionLiteral && this.hashCode() == obj.hashCode();
76: }
77:
78: @Override
79: public int hashCode() {
80: return expr.hashCode();
81: }
82:
83: @Override
84: public boolean isLiteralText() {
85: return true;
86: }
87:
88: @Override
89: public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
90: expr = in.readUTF();
91: String type = in.readUTF();
92:
93: if (!"".equals(type)) {
94: expectedType = ReflectionUtil.forName(type);
95: }
96:
97: paramTypes = toTypeArray(((String[]) in.readObject()));
98: }
99:
100: @Override
101: public void writeExternal(ObjectOutput out) throws IOException {
102: out.writeUTF(expr);
103: out.writeUTF(expectedType != null ? expectedType.getName() : "");
104: out.writeObject(toTypeNameArray(paramTypes));
105: }
106: }