Skip to content

Package: FunctionMapperImpl$Function

FunctionMapperImpl$Function

nameinstructionbranchcomplexitylinemethod
FunctionMapperImpl.Function()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
FunctionMapperImpl.Function(String, String, Method)
M: 26 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
equals(Object)
M: 14 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getMethod()
M: 28 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
hashCode()
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
matches(String, String)
M: 19 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
readExternal(ObjectInput)
M: 30 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
writeExternal(ObjectOutput)
M: 55 C: 0
0%
M: 8 C: 0
0%
M: 5 C: 0
0%
M: 12 C: 0
0%
M: 1 C: 0
0%

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.lang;
18:
19: import java.io.Externalizable;
20: import java.io.IOException;
21: import java.io.ObjectInput;
22: import java.io.ObjectOutput;
23: import java.lang.reflect.Method;
24: import java.util.HashMap;
25: import java.util.Map;
26:
27: import jakarta.el.FunctionMapper;
28:
29: import com.sun.el.util.ReflectionUtil;
30:
31: /**
32: * @author Jacob Hookom [jacob@hookom.net]
33: * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author: kchung $
34: */
35: public class FunctionMapperImpl extends FunctionMapper implements Externalizable {
36:
37: private static final long serialVersionUID = 1L;
38:
39: protected Map<String, Function> functions = null;
40:
41: /*
42: * (non-Javadoc)
43: *
44: * @see FunctionMapper#resolveFunction(java.lang.String, java.lang.String)
45: */
46: @Override
47: public Method resolveFunction(String prefix, String localName) {
48: if (this.functions != null) {
49: Function f = this.functions.get(prefix + ":" + localName);
50: return f.getMethod();
51: }
52: return null;
53: }
54:
55: public void addFunction(String prefix, String localName, Method m) {
56: if (this.functions == null) {
57: this.functions = new HashMap<String, Function>();
58: }
59: Function f = new Function(prefix, localName, m);
60: synchronized (this) {
61: this.functions.put(prefix + ":" + localName, f);
62: }
63: }
64:
65: /*
66: * (non-Javadoc)
67: *
68: * @see java.io.Externalizable#writeExternal(java.io.ObjectOutput)
69: */
70: @Override
71: public void writeExternal(ObjectOutput out) throws IOException {
72: out.writeObject(this.functions);
73: }
74:
75: /*
76: * (non-Javadoc)
77: *
78: * @see java.io.Externalizable#readExternal(java.io.ObjectInput)
79: */
80: // Safe cast
81: @Override
82: @SuppressWarnings("unchecked")
83: public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
84: this.functions = (Map<String, Function>) in.readObject();
85: }
86:
87: public static class Function implements Externalizable {
88:
89: protected transient Method m;
90: protected String owner;
91: protected String name;
92: protected String[] types;
93: protected String prefix;
94: protected String localName;
95:
96: /**
97: *
98: */
99: public Function(String prefix, String localName, Method m) {
100:• if (localName == null) {
101: throw new NullPointerException("LocalName cannot be null");
102: }
103:• if (m == null) {
104: throw new NullPointerException("Method cannot be null");
105: }
106: this.prefix = prefix;
107: this.localName = localName;
108: this.m = m;
109: }
110:
111: public Function() {
112: // for serialization
113: }
114:
115: /*
116: * (non-Javadoc)
117: *
118: * @see java.io.Externalizable#writeExternal(java.io.ObjectOutput)
119: */
120: @Override
121: public void writeExternal(ObjectOutput out) throws IOException {
122:
123:• out.writeUTF((this.prefix != null) ? this.prefix : "");
124: out.writeUTF(this.localName);
125:
126:• if (this.owner != null) {
127: out.writeUTF(this.owner);
128: } else {
129: out.writeUTF(this.m.getDeclaringClass().getName());
130: }
131:• if (this.name != null) {
132: out.writeUTF(this.name);
133: } else {
134: out.writeUTF(this.m.getName());
135: }
136:• if (this.types != null) {
137: out.writeObject(this.types);
138: } else {
139: out.writeObject(ReflectionUtil.toTypeNameArray(this.m.getParameterTypes()));
140: }
141: }
142:
143: /*
144: * (non-Javadoc)
145: *
146: * @see java.io.Externalizable#readExternal(java.io.ObjectInput)
147: */
148: @Override
149: public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
150:
151: this.prefix = in.readUTF();
152:• if ("".equals(this.prefix)) {
153: this.prefix = null;
154: }
155: this.localName = in.readUTF();
156: this.owner = in.readUTF();
157: this.name = in.readUTF();
158: this.types = (String[]) in.readObject();
159: }
160:
161: public Method getMethod() {
162:• if (this.m == null) {
163: try {
164: Class<?> t = Class.forName(this.owner, false, Thread.currentThread().getContextClassLoader());
165: Class[] p = ReflectionUtil.toTypeArray(this.types);
166: this.m = t.getMethod(this.name, p);
167: } catch (Exception e) {
168: e.printStackTrace();
169: }
170: }
171: return this.m;
172: }
173:
174: public boolean matches(String prefix, String localName) {
175:• if (this.prefix != null) {
176:• if (prefix == null) {
177: return false;
178: }
179:• if (!this.prefix.equals(prefix)) {
180: return false;
181: }
182: }
183: return this.localName.equals(localName);
184: }
185:
186: /*
187: * (non-Javadoc)
188: *
189: * @see java.lang.Object#equals(java.lang.Object)
190: */
191: @Override
192: public boolean equals(Object obj) {
193:• if (obj instanceof Function) {
194:• return this.hashCode() == obj.hashCode();
195: }
196: return false;
197: }
198:
199: /*
200: * (non-Javadoc)
201: *
202: * @see java.lang.Object#hashCode()
203: */
204: @Override
205: public int hashCode() {
206: return (this.prefix + this.localName).hashCode();
207: }
208: }
209:
210: }