1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.component.wiki.internal

File ObjectMethodsProxy.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart0.png
83% of files have more coverage

Code metrics

8
12
5
1
100
36
10
0.83
2.4
5
2

Classes

Class Line # Actions
ObjectMethodsProxy 30 12 0% 10 25
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.component.wiki.internal;
21   
22    import java.lang.reflect.Method;
23   
24    /**
25    * Handles calls to method from the {@link Object} class on a Proxy object that doesn't implement them.
26    *
27    * @version $Id: 68fd6ed935933bdc0d3f4e27e54579aa29d80576 $
28    * @since 4.3M2
29    */
 
30    public final class ObjectMethodsProxy
31    {
32    /**
33    * Default constructor.
34    */
 
35  0 toggle private ObjectMethodsProxy()
36    {
37    // Nothing to do here.
38    }
39   
40    /**
41    * Proxies a method of the {@link Object} class.
42    *
43    * @param proxy the proxy instance
44    * @param method the method to proxy
45    * @param args possible arguments to the method invocation
46    * @return the result of the proxied call
47    */
 
48  0 toggle public static Object invoke(Object proxy, Method method, Object[] args)
49    {
50  0 try {
51  0 if (method.equals(Object.class.getMethod("hashCode"))) {
52  0 return proxyHashCode(proxy);
53  0 } else if (method.equals(Object.class.getMethod("equals", new Class[] {Object.class}))) {
54  0 return proxyEquals(proxy, args[0]);
55  0 } else if (method.equals(Object.class.getMethod("toString"))) {
56  0 return proxyToString(proxy);
57    } else {
58  0 throw new InternalError("unexpected Object method dispatched: " + method);
59    }
60    } catch (NoSuchMethodException e) {
61  0 throw new NoSuchMethodError(e.getMessage());
62    }
63    }
64   
65    /**
66    * Default behavior for {@link Object#hashCode()} when not overridden in the wiki component definition.
67    *
68    * @param proxy the proxy object
69    * @return a hash code for the proxy object, as if using standard {Object{@link #hashCode()}.
70    */
 
71  0 toggle private static Integer proxyHashCode(Object proxy)
72    {
73  0 return System.identityHashCode(proxy);
74    }
75   
76    /**
77    * Default behavior for {@link Object#equals(Object)} when not overridden in the wiki component definition.
78    *
79    * @param proxy the proxy object
80    * @param other the other object of the comparison
81    * @return the result of the equality comparison between the passed proxy and other object
82    */
 
83  0 toggle private static Boolean proxyEquals(Object proxy, Object other)
84    {
85  0 return (proxy == other ? Boolean.TRUE : Boolean.FALSE);
86    }
87   
88    /**
89    * Default behavior for {@link Object#toString()} when not overridden in the wiki component definition.
90    *
91    * @param proxy the proxy object
92    * @return the String representation of the passed proxy object
93    */
 
94  0 toggle private static String proxyToString(Object proxy)
95    {
96  0 return proxy.getClass().getName() + '@' + Integer.toHexString(proxy.hashCode());
97    }
98   
99   
100    }