You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hivemind.apache.org by hl...@apache.org on 2004/11/09 21:58:20 UTC
cvs commit: jakarta-hivemind/framework/src/test/org/apache/hivemind/impl TestMethodIterator.java
hlship 2004/11/09 12:58:20
Modified: library/src/java/org/apache/hivemind/lib/impl
EJBProxyFactory.java ServicePropertyFactory.java
DefaultImplementationBuilderImpl.java
framework/src/java/org/apache/hivemind/impl
ProxyBuilder.java
library/src/test/org/apache/hivemind/lib/adapter
TestAdapterRegistryFactory.java
library/src/java/org/apache/hivemind/lib/adapter
AdapterRegistryFactory.java
framework/src/java/org/apache/hivemind/service
MethodIterator.java MethodSignature.java
ClassFabUtils.java
. status.xml
framework/src/java/org/apache/hivemind/service/impl
LoggingInterceptorFactory.java
framework/src/test/hivemind/test/services
TestMethodSignature.java
framework/src/test/org/apache/hivemind/service/impl
TestClassFabUtils.java
library/src/java/org/apache/hivemind/lib/pipeline
BridgeBuilder.java
framework/src/test/org/apache/hivemind/impl
TestMethodIterator.java
Log:
HIVEMIND-76: Improve MethodSignature and MethodIterator to filter out duplicate methods that differ only in terms of thrown exceptions.
Revision Changes Path
1.12 +1 -1 jakarta-hivemind/library/src/java/org/apache/hivemind/lib/impl/EJBProxyFactory.java
Index: EJBProxyFactory.java
===================================================================
RCS file: /home/cvs/jakarta-hivemind/library/src/java/org/apache/hivemind/lib/impl/EJBProxyFactory.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- EJBProxyFactory.java 8 Nov 2004 14:14:25 -0000 1.11
+++ EJBProxyFactory.java 9 Nov 2004 20:58:19 -0000 1.12
@@ -62,7 +62,7 @@
Class homeInterface = module.getClassResolver().findClass(homeInterfaceClassName);
- String proxyClassName = ClassFabUtils.generateClassName("EJBProxy");
+ String proxyClassName = ClassFabUtils.generateClassName(serviceInterface);
ClassFab classFab =
_classFactory.newClass(
1.9 +8 -11 jakarta-hivemind/library/src/java/org/apache/hivemind/lib/impl/ServicePropertyFactory.java
Index: ServicePropertyFactory.java
===================================================================
RCS file: /home/cvs/jakarta-hivemind/library/src/java/org/apache/hivemind/lib/impl/ServicePropertyFactory.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- ServicePropertyFactory.java 8 Nov 2004 14:14:25 -0000 1.8
+++ ServicePropertyFactory.java 9 Nov 2004 20:58:19 -0000 1.9
@@ -27,6 +27,7 @@
import org.apache.hivemind.service.ClassFab;
import org.apache.hivemind.service.ClassFabUtils;
import org.apache.hivemind.service.ClassFactory;
+import org.apache.hivemind.service.MethodIterator;
import org.apache.hivemind.service.MethodSignature;
import org.apache.hivemind.util.ConstructorUtils;
import org.apache.hivemind.util.PropertyAdaptor;
@@ -71,7 +72,7 @@
// Now we're good to go.
- String name = ClassFabUtils.generateClassName("ServicePropertyProxy");
+ String name = ClassFabUtils.generateClassName(serviceInterface);
ClassFab cf = _classFactory.newClass(name, Object.class);
@@ -134,22 +135,18 @@
private void addMethods(ClassFab cf, String serviceId, Class serviceInterface,
String propertyName, Object targetService)
{
- boolean toString = false;
+ MethodIterator mi = new MethodIterator(serviceInterface);
- Method[] methods = serviceInterface.getMethods();
-
- for (int i = 0; i < methods.length; i++)
+ while (mi.hasNext())
{
- Method method = methods[i];
-
- toString |= ClassFabUtils.isToString(method);
+ MethodSignature sig = mi.next();
- String body = "return ($r) _targetServiceProperty()." + method.getName() + "($$);";
+ String body = "return ($r) _targetServiceProperty()." + sig.getName() + "($$);";
- cf.addMethod(Modifier.PUBLIC, new MethodSignature(method), body);
+ cf.addMethod(Modifier.PUBLIC, sig, body);
}
- if (!toString)
+ if (!mi.getToString())
ClassFabUtils.addToStringMethod(cf, ImplMessages.servicePropertyToString(
serviceId,
serviceInterface,
1.7 +1 -1 jakarta-hivemind/library/src/java/org/apache/hivemind/lib/impl/DefaultImplementationBuilderImpl.java
Index: DefaultImplementationBuilderImpl.java
===================================================================
RCS file: /home/cvs/jakarta-hivemind/library/src/java/org/apache/hivemind/lib/impl/DefaultImplementationBuilderImpl.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- DefaultImplementationBuilderImpl.java 8 Nov 2004 14:14:25 -0000 1.6
+++ DefaultImplementationBuilderImpl.java 9 Nov 2004 20:58:19 -0000 1.7
@@ -73,7 +73,7 @@
if (!interfaceType.isInterface())
throw new ApplicationRuntimeException(ImplMessages.notAnInterface(interfaceType));
- String name = ClassFabUtils.generateClassName("DefaultImpl");
+ String name = ClassFabUtils.generateClassName(interfaceType);
ClassFab cf = _classFactory.newClass(name, Object.class);
1.8 +20 -23 jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/ProxyBuilder.java
Index: ProxyBuilder.java
===================================================================
RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/ProxyBuilder.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- ProxyBuilder.java 8 Nov 2004 14:14:25 -0000 1.7
+++ ProxyBuilder.java 9 Nov 2004 20:58:20 -0000 1.8
@@ -27,21 +27,23 @@
/**
* Class used to assist service extension points in creating proxies.
- *
+ *
* @author Howard Lewis Ship
*/
public final class ProxyBuilder
{
private ServicePoint _point;
+
private Class _serviceInterface;
+
private ClassFab _classFab;
+
private String _type;
/**
- * Constructs a new builder. The type will be incorporated
- * into the class name and the <code>toString()</code> method.
- * The service extension point is used to identify the service interface
- * and service id.
+ * Constructs a new builder. The type will be incorporated into value returned by the
+ * <code>toString()</code> method. The service extension point is used to identify the service
+ * interface and service id.
*/
public ProxyBuilder(String type, ServicePoint point)
{
@@ -50,12 +52,12 @@
_serviceInterface = point.getServiceInterface();
Module module = point.getModule();
- ClassFactory factory =
- (ClassFactory) module.getService("hivemind.ClassFactory", ClassFactory.class);
+ ClassFactory factory = (ClassFactory) module.getService(
+ "hivemind.ClassFactory",
+ ClassFactory.class);
- _classFab =
- factory.newClass(
- ClassFabUtils.generateClassName(type),
+ _classFab = factory.newClass(
+ ClassFabUtils.generateClassName(_serviceInterface),
Object.class);
_classFab.addInterface(_serviceInterface);
@@ -67,9 +69,11 @@
}
/**
- * Creates the service methods for the class.
- * @param indirection the name of a variable, or a method invocation snippet,
- * used to redirect the invocation on the proxy to the actual service implementation.
+ * Creates the service methods for the class.
+ *
+ * @param indirection
+ * the name of a variable, or a method invocation snippet, used to redirect the
+ * invocation on the proxy to the actual service implementation.
*/
public void addServiceMethods(String indirection)
{
@@ -94,14 +98,7 @@
}
if (!mi.getToString())
- ClassFabUtils.addToStringMethod(
- _classFab,
- "<"
- + _type
- + " for "
- + _point.getExtensionPointId()
- + "("
- + _serviceInterface.getName()
- + ")>");
+ ClassFabUtils.addToStringMethod(_classFab, "<" + _type + " for "
+ + _point.getExtensionPointId() + "(" + _serviceInterface.getName() + ")>");
}
-}
+}
\ No newline at end of file
1.3 +2 -10 jakarta-hivemind/library/src/test/org/apache/hivemind/lib/adapter/TestAdapterRegistryFactory.java
Index: TestAdapterRegistryFactory.java
===================================================================
RCS file: /home/cvs/jakarta-hivemind/library/src/test/org/apache/hivemind/lib/adapter/TestAdapterRegistryFactory.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TestAdapterRegistryFactory.java 8 Nov 2004 14:14:25 -0000 1.2
+++ TestAdapterRegistryFactory.java 9 Nov 2004 20:58:20 -0000 1.3
@@ -22,10 +22,6 @@
import org.apache.hivemind.Location;
import org.apache.hivemind.Registry;
import org.apache.hivemind.ServiceImplementationFactoryParameters;
-import org.apache.hivemind.lib.adapter.AdapterMessages;
-import org.apache.hivemind.lib.adapter.AdapterRegistryContribution;
-import org.apache.hivemind.lib.adapter.AdapterRegistryFactory;
-import org.apache.hivemind.lib.adapter.AdapterRegistryParameter;
import org.apache.hivemind.lib.util.AdapterRegistry;
import org.apache.hivemind.service.ClassFab;
import org.apache.hivemind.service.ClassFabUtils;
@@ -150,8 +146,6 @@
MethodFab mf = (MethodFab) newMock(MethodFab.class);
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
-
MockControl fpc = newControl(ServiceImplementationFactoryParameters.class);
ServiceImplementationFactoryParameters fp = (ServiceImplementationFactoryParameters) fpc
.getMock();
@@ -197,7 +191,7 @@
AdapterRegistryFactory f = new AdapterRegistryFactory();
f.setClassFactory(factory);
- f.buildImplementationClass(fp, "NewClass", loader);
+ f.buildImplementationClass(fp, "NewClass");
verifyControls();
}
@@ -214,8 +208,6 @@
MethodFab mf = (MethodFab) newMock(MethodFab.class);
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
-
MockControl fpc = newControl(ServiceImplementationFactoryParameters.class);
ServiceImplementationFactoryParameters fp = (ServiceImplementationFactoryParameters) fpc
.getMock();
@@ -272,7 +264,7 @@
AdapterRegistryFactory f = new AdapterRegistryFactory();
f.setClassFactory(factory);
- f.buildImplementationClass(fp, "NewClass", loader);
+ f.buildImplementationClass(fp, "NewClass");
verifyControls();
}
1.3 +3 -5 jakarta-hivemind/library/src/java/org/apache/hivemind/lib/adapter/AdapterRegistryFactory.java
Index: AdapterRegistryFactory.java
===================================================================
RCS file: /home/cvs/jakarta-hivemind/library/src/java/org/apache/hivemind/lib/adapter/AdapterRegistryFactory.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AdapterRegistryFactory.java 8 Nov 2004 14:14:25 -0000 1.2
+++ AdapterRegistryFactory.java 9 Nov 2004 20:58:20 -0000 1.3
@@ -112,17 +112,15 @@
private Class buildImplementationClass(ServiceImplementationFactoryParameters factoryParameters)
{
- String name = ClassFabUtils.generateClassName("AdapterRegistry");
- ClassLoader loader = factoryParameters.getInvokingModule().getClassResolver()
- .getClassLoader();
+ String name = ClassFabUtils.generateClassName(factoryParameters.getServiceInterface());
- return buildImplementationClass(factoryParameters, name, loader);
+ return buildImplementationClass(factoryParameters, name);
}
// package private for testing purposes
Class buildImplementationClass(ServiceImplementationFactoryParameters factoryParameters,
- String name, ClassLoader loader)
+ String name)
{
Class serviceInterface = factoryParameters.getServiceInterface();
1.3 +51 -46 jakarta-hivemind/framework/src/java/org/apache/hivemind/service/MethodIterator.java
Index: MethodIterator.java
===================================================================
RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/service/MethodIterator.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- MethodIterator.java 13 Sep 2004 14:48:16 -0000 1.2
+++ MethodIterator.java 9 Nov 2004 20:58:20 -0000 1.3
@@ -15,82 +15,87 @@
package org.apache.hivemind.service;
import java.lang.reflect.Method;
-import java.util.HashSet;
-import java.util.Set;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.NoSuchElementException;
+
+import org.apache.hivemind.Defense;
/**
* Utility used to iterate over the visible methods of a class.
- *
+ *
* @author Howard Lewis Ship
*/
public class MethodIterator
{
- private Set _seen = new HashSet();
private boolean _toString;
private int _index = 0;
- private Method[] _methods;
- private MethodSignature _next;
+
+ /** @since 1.1 */
+ private int _count;
+
+ /** @since 1.1 */
+ private List _signatures;
public MethodIterator(Class subjectClass)
{
- _methods = subjectClass.getMethods();
- }
+ Defense.notNull(subjectClass, "subjectClass");
- public boolean hasNext()
- {
- if (_next != null)
- return true;
+ Method[] methods = subjectClass.getMethods();
+
+ Map map = new HashMap();
- _next = next();
+ for (int i = 0; i < methods.length; i++)
+ processMethod(methods[i], map);
- return _next != null;
+ _signatures = new ArrayList(map.values());
+ _count = _signatures.size();
}
- /**
- * Returns the next method (as a {@link MethodSignature}, returning null
- * when all are exhausted. Each method signature is returned exactly once
- * (even if the same method signature is defined in multiple inherited
- * classes or interfaces).
- */
- public MethodSignature next()
+ /** @since 1.1 */
+ private void processMethod(Method m, Map map)
{
- if (_next != null)
- {
- MethodSignature result = _next;
- _next = null;
+ _toString |= ClassFabUtils.isToString(m);
- return result;
- }
+ MethodSignature sig = new MethodSignature(m);
+ String uid = sig.getUniqueId();
- while (true)
- {
- if (_index >= _methods.length)
- return null;
+ MethodSignature existing = (MethodSignature) map.get(uid);
- Method m = _methods[_index++];
-
- _toString |= ClassFabUtils.isToString(m);
-
- MethodSignature result = new MethodSignature(m);
+ if (existing == null || sig.isOverridingSignatureOf(existing))
+ map.put(uid, sig);
+ }
- if (_seen.contains(result))
- continue;
+ public boolean hasNext()
+ {
+ return _index < _count;
+ }
- _seen.add(result);
+ /**
+ * Returns the next method (as a {@link MethodSignature}, returning null when all are
+ * exhausted. Each method signature is returned exactly once (even if the same method signature
+ * is defined in multiple inherited classes or interfaces). The order in which method signatures
+ * are returned is not specified.
+ *
+ * @throws NoSuchElementException
+ * if there are no more signatures
+ */
+ public MethodSignature next()
+ {
+ if (_index >= _count)
+ throw new NoSuchElementException();
- return result;
- }
+ return (MethodSignature) _signatures.get(_index++);
}
/**
- * Returns true if the method <code>public String toString()</code> was returned by
- * <em>any</em> previous call to {@link #next()}.
- * This is typically used to avoid overloading <code>toString()</code> if it is
- * part of a service interface.
+ * Returns true if the method <code>public String toString()</code> is part of the interface.
*/
public boolean getToString()
{
return _toString;
}
-}
+}
\ No newline at end of file
1.2 +117 -26 jakarta-hivemind/framework/src/java/org/apache/hivemind/service/MethodSignature.java
Index: MethodSignature.java
===================================================================
RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/service/MethodSignature.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- MethodSignature.java 12 Jun 2004 18:43:41 -0000 1.1
+++ MethodSignature.java 9 Nov 2004 20:58:20 -0000 1.2
@@ -17,32 +17,32 @@
import java.lang.reflect.Method;
/**
- * A representation of a {@link java.lang.reflect.Method}, identifying the name,
- * return type, parameter types and exception types. Actual Method objects are tied to
- * a particular class, and don't compare well with other otherwise identical Methods from
- * other classes or interface; MethodSignatures are distinct from classes and compare well.
- *
+ * A representation of a {@link java.lang.reflect.Method}, identifying the name, return type,
+ * parameter types and exception types. Actual Method objects are tied to a particular class, and
+ * don't compare well with other otherwise identical Methods from other classes or interface;
+ * MethodSignatures are distinct from classes and compare well.
* <p>
- * Because the intended purpose is to compare methods from interfaces (which are always
- * public and abstract) we don't bother to actually track the modifiers. In addition,
- * at this time, MethodSignature <em>does not distinguish between instance and static
+ * Because the intended purpose is to compare methods from interfaces (which are always public and
+ * abstract) we don't bother to actually track the modifiers. In addition, at this time,
+ * MethodSignature <em>does not distinguish between instance and static
* methods</em>.
- *
+ *
* @author Howard Lewis Ship
*/
public class MethodSignature
{
private int _hashCode = -1;
+
private Class _returnType;
+
private String _name;
+
private Class[] _parameterTypes;
+
private Class[] _exceptionTypes;
- public MethodSignature(
- Class returnType,
- String name,
- Class[] parameterTypes,
- Class[] exceptionTypes)
+ public MethodSignature(Class returnType, String name, Class[] parameterTypes,
+ Class[] exceptionTypes)
{
_returnType = returnType;
_name = name;
@@ -55,10 +55,10 @@
this(m.getReturnType(), m.getName(), m.getParameterTypes(), m.getExceptionTypes());
}
- /**
- * Returns the exceptions for this method. Caution: do not modify the returned array.
- * May return null.
- */
+ /**
+ * Returns the exceptions for this method. Caution: do not modify the returned array. May return
+ * null.
+ */
public Class[] getExceptionTypes()
{
return _exceptionTypes;
@@ -69,10 +69,10 @@
return _name;
}
- /**
- * Returns the parameter types for this method. May return null. Caution: do
- * not modify the returned array.
- */
+ /**
+ * Returns the parameter types for this method. May return null. Caution: do not modify the
+ * returned array.
+ */
public Class[] getParameterTypes()
{
return _parameterTypes;
@@ -112,8 +112,8 @@
}
/**
- * Returns true if the other object is an instance of MethodSignature with
- * identical values for return type, name, parameter types and exception types.
+ * Returns true if the other object is an instance of MethodSignature with identical values for
+ * return type, name, parameter types and exception types.
*/
public boolean equals(Object o)
{
@@ -142,7 +142,7 @@
if (a1Count != a2Count)
return true;
- // Hm. What if order is important (for exceptions)? We're really saying here that they
+ // Hm. What if order is important (for exceptions)? We're really saying here that they
// were derived from the name Method.
for (int i = 0; i < a1Count; i++)
@@ -186,4 +186,95 @@
return buffer.toString();
}
-}
+ /**
+ * Returns a string consisting of the name of the method and its parameter values. This is
+ * similar to {@link #toString()}, but omits the return type and information about thrown
+ * exceptions. A unique id is used by {@link MethodIterator}to identify overlapping methods
+ * (methods with the same name but different thrown exceptions).
+ *
+ * @since 1.1
+ */
+ public String getUniqueId()
+ {
+ StringBuffer buffer = new StringBuffer(_name);
+ buffer.append("(");
+
+ for (int i = 0; i < count(_parameterTypes); i++)
+ {
+ if (i > 0)
+ buffer.append(",");
+
+ buffer.append(ClassFabUtils.getJavaClassName(_parameterTypes[i]));
+ }
+
+ buffer.append(")");
+
+ return buffer.toString();
+ }
+
+ /**
+ * Returns true if this signature has the same return type, name and parameters types as the
+ * method signature passed in, and this signatures exceptions "trump" (are the same as, or
+ * super-implementations of, all exceptions thrown by the other method signature).
+ *
+ * @since 1.1
+ */
+
+ public boolean isOverridingSignatureOf(MethodSignature ms)
+ {
+ if (_returnType != ms._returnType)
+ return false;
+
+ if (!_name.equals(ms._name))
+ return false;
+
+ if (mismatch(_parameterTypes, ms._parameterTypes))
+ return false;
+
+ return exceptionsEncompass(ms._exceptionTypes);
+ }
+
+ /**
+ * The nuts and bolts of checking that another method signature's exceptions are a subset of
+ * this signature's.
+ *
+ * @since 1.1
+ */
+
+ private boolean exceptionsEncompass(Class[] otherExceptions)
+ {
+ int ourCount = count(_exceptionTypes);
+ int otherCount = count(otherExceptions);
+
+ // If we have no exceptions, then ours encompass theirs only if they
+ // have no exceptions, either.
+
+ if (ourCount == 0)
+ return otherCount == 0;
+
+ boolean[] matched = new boolean[otherCount];
+ int unmatched = otherCount;
+
+ for (int i = 0; i < ourCount && unmatched > 0; i++)
+ {
+ for (int j = 0; j < otherCount; j++)
+ {
+ // Ignore exceptions that have already been matched
+
+ if (matched[j])
+ continue;
+
+ // When one of our exceptions is a super-class of one of their exceptions,
+ // then their exceptions is matched.
+
+ if (_exceptionTypes[i].isAssignableFrom(otherExceptions[j]))
+ {
+ matched[j] = true;
+ unmatched--;
+ }
+ }
+ }
+
+ return unmatched == 0;
+ }
+}
\ No newline at end of file
1.6 +18 -2 jakarta-hivemind/framework/src/java/org/apache/hivemind/service/ClassFabUtils.java
Index: ClassFabUtils.java
===================================================================
RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/service/ClassFabUtils.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ClassFabUtils.java 5 Nov 2004 15:58:35 -0000 1.5
+++ ClassFabUtils.java 9 Nov 2004 20:58:20 -0000 1.6
@@ -25,7 +25,7 @@
*/
public class ClassFabUtils
{
- private static int _uid = 0;
+ private static long _uid = System.currentTimeMillis();
private static final char QUOTE = '"';
@@ -39,7 +39,23 @@
public static synchronized String generateClassName(String baseName)
{
- return "$" + baseName + "_" + Long.toHexString(System.currentTimeMillis()) + "_" + _uid++;
+ return "$" + baseName + "_" + Long.toHexString(_uid++);
+ }
+
+ /**
+ * Returns a class name derived from the provided interfaceClass. The package part of the
+ * interface name is stripped out, and the result passed to {@link #generateClassName(String)}.
+ *
+ * @since 1.1
+ */
+
+ public static synchronized String generateClassName(Class interfaceClass)
+ {
+ String name = interfaceClass.getName();
+
+ int dotx = name.lastIndexOf('.');
+
+ return generateClassName(name.substring(dotx + 1));
}
/**
1.80 +4 -0 jakarta-hivemind/status.xml
Index: status.xml
===================================================================
RCS file: /home/cvs/jakarta-hivemind/status.xml,v
retrieving revision 1.79
retrieving revision 1.80
diff -u -r1.79 -r1.80
--- status.xml 9 Nov 2004 17:26:11 -0000 1.79
+++ status.xml 9 Nov 2004 20:58:20 -0000 1.80
@@ -96,6 +96,10 @@
<action type="fix" dev="HLS" fixes-bug="HIVEMIND-75">
Add ability to set default value for non-matches in MethodMatcher.
</action>
+ <action type="fix" dev="HLS" fixes-bug="HIVEMIND-76">
+ Improve MethodSignature and MethodIterator to filter out duplicate methods that differ
+ only in terms of thrown exceptions.
+ </action>
</release>
<release version="1.0" date="Sep 22 2004">
1.12 +1 -1 jakarta-hivemind/framework/src/java/org/apache/hivemind/service/impl/LoggingInterceptorFactory.java
Index: LoggingInterceptorFactory.java
===================================================================
RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/service/impl/LoggingInterceptorFactory.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- LoggingInterceptorFactory.java 8 Nov 2004 14:14:24 -0000 1.11
+++ LoggingInterceptorFactory.java 9 Nov 2004 20:58:20 -0000 1.12
@@ -203,7 +203,7 @@
{
Class serviceInterfaceClass = stack.getServiceInterface();
- String name = ClassFabUtils.generateClassName("Interceptor");
+ String name = ClassFabUtils.generateClassName(serviceInterfaceClass);
ClassFab classFab = _factory.newClass(name, Object.class);
1.5 +133 -5 jakarta-hivemind/framework/src/test/hivemind/test/services/TestMethodSignature.java
Index: TestMethodSignature.java
===================================================================
RCS file: /home/cvs/jakarta-hivemind/framework/src/test/hivemind/test/services/TestMethodSignature.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- TestMethodSignature.java 27 Sep 2004 14:37:14 -0000 1.4
+++ TestMethodSignature.java 9 Nov 2004 20:58:20 -0000 1.5
@@ -14,16 +14,18 @@
package hivemind.test.services;
+import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectInputStream;
import java.lang.reflect.Method;
+import java.sql.SQLException;
import org.apache.hivemind.service.MethodSignature;
import org.apache.hivemind.test.HiveMindTestCase;
/**
- * Tests for the {@link org.apache.hivemind.service.impl.MethodSignature} class.
- *
+ * Tests for the {@link org.apache.hivemind.service.impl.MethodSignature}class.
+ *
* @author Howard Lewis Ship
*/
public class TestMethodSignature extends HiveMindTestCase
@@ -76,6 +78,45 @@
assertEquals(m1.hashCode(), m2.hashCode());
}
+ /** @since 1.1 */
+
+ public void testEqualsNameMismatch()
+ {
+ MethodSignature m1 = new MethodSignature(void.class, "foo", null, null);
+ MethodSignature m2 = new MethodSignature(void.class, "bar", null, null);
+
+ assertEquals(false, m1.equals(m2));
+ }
+
+ /** @since 1.1 */
+ public void testParametersMismatch()
+ {
+ MethodSignature m1 = new MethodSignature(void.class, "foo", new Class[]
+ { String.class }, null);
+ MethodSignature m2 = new MethodSignature(void.class, "foo", new Class[]
+ { Boolean.class }, null);
+
+ assertEquals(false, m1.equals(m2));
+ }
+
+ /** @since 1.1 */
+
+ public void testEqualsNull()
+ {
+ MethodSignature m1 = new MethodSignature(void.class, "foo", null, null);
+
+ assertEquals(false, m1.equals(null));
+ }
+
+ /** @since 1.1 */
+
+ public void testEqualsNonMethodSignature()
+ {
+ MethodSignature m1 = new MethodSignature(void.class, "foo", null, null);
+
+ assertEquals(false, m1.equals("Method Signature"));
+ }
+
public void testToString()
{
MethodSignature m = find(String.class, "getChars");
@@ -85,7 +126,94 @@
m = find(Class.class, "newInstance");
assertEquals(
- "java.lang.Object newInstance() throws java.lang.InstantiationException, java.lang.IllegalAccessException",
- m.toString());
+ "java.lang.Object newInstance() throws java.lang.InstantiationException, java.lang.IllegalAccessException",
+ m.toString());
+ }
+
+ /** @since 1.1 */
+ public void testGetUniqueId()
+ {
+ MethodSignature m = find(String.class, "getChars");
+
+ assertEquals("getChars(int,int,char[],int)", m.getUniqueId());
+
+ m = find(Class.class, "newInstance");
+
+ assertEquals("newInstance()", m.getUniqueId());
+ }
+
+ /** @since 1.1 */
+
+ public void testOverridingSigTypeMismatch()
+ {
+ MethodSignature m1 = new MethodSignature(void.class, "foo", null, null);
+ MethodSignature m2 = new MethodSignature(int.class, "foo", null, null);
+
+ assertEquals(false, m1.isOverridingSignatureOf(m2));
+ }
+
+ /** @since 1.1 */
+
+ public void testOverridingSigNameMismatch()
+ {
+ MethodSignature m1 = new MethodSignature(void.class, "foo", null, null);
+ MethodSignature m2 = new MethodSignature(void.class, "bar", null, null);
+
+ assertEquals(false, m1.isOverridingSignatureOf(m2));
+ }
+
+ /** @since 1.1 */
+
+ public void testOverridingSigParametersMismatch()
+ {
+ MethodSignature m1 = new MethodSignature(void.class, "foo", null, null);
+ MethodSignature m2 = new MethodSignature(void.class, "foo", new Class[]
+ { String.class }, null);
+
+ assertEquals(false, m1.isOverridingSignatureOf(m2));
+ }
+
+ /** @since 1.1 */
+
+ public void testOverridingSig()
+ {
+ MethodSignature m1 = new MethodSignature(void.class, "close", null, new Class[]
+ { Exception.class });
+ MethodSignature m2 = new MethodSignature(void.class, "close", null, new Class[]
+ { RuntimeException.class });
+
+ assertEquals(true, m1.isOverridingSignatureOf(m2));
+ assertEquals(false, m2.isOverridingSignatureOf(m1));
+ }
+
+ /**
+ * Tests a shorcut used when one signature has zero exceptions.
+ *
+ * @since 1.1
+ */
+ public void testOverridingSigShortcut()
+ {
+ MethodSignature m1 = new MethodSignature(void.class, "close", null, null);
+ MethodSignature m2 = new MethodSignature(void.class, "close", null, new Class[]
+ { RuntimeException.class });
+
+ assertEquals(false, m1.isOverridingSignatureOf(m2));
+ assertEquals(true, m2.isOverridingSignatureOf(m1));
+ }
+
+ /**
+ * Fill in code coverage for multiple matchd signatures.
+ *
+ * @since 1.1
+ */
+ public void testMultipleExceptionsToMatch()
+ {
+ MethodSignature m1 = new MethodSignature(void.class, "close", null, new Class[]
+ { SQLException.class, NumberFormatException.class });
+ MethodSignature m2 = new MethodSignature(void.class, "close", null, new Class[]
+ { SQLException.class, IOException.class });
+
+ assertEquals(false, m1.isOverridingSignatureOf(m2));
+ assertEquals(false, m2.isOverridingSignatureOf(m1));
}
-}
+}
\ No newline at end of file
1.4 +9 -0 jakarta-hivemind/framework/src/test/org/apache/hivemind/service/impl/TestClassFabUtils.java
Index: TestClassFabUtils.java
===================================================================
RCS file: /home/cvs/jakarta-hivemind/framework/src/test/org/apache/hivemind/service/impl/TestClassFabUtils.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- TestClassFabUtils.java 5 Nov 2004 15:58:35 -0000 1.3
+++ TestClassFabUtils.java 9 Nov 2004 20:58:20 -0000 1.4
@@ -73,4 +73,13 @@
verifyControls();
}
+
+ /** @since 1.1 */
+
+ public void testGenerateClassName() throws Exception
+ {
+ String name = ClassFabUtils.generateClassName(Runnable.class);
+
+ assertRegexp("\\$Runnable_([0-9|a-f])+", name);
+ }
}
1.6 +1 -1 jakarta-hivemind/library/src/java/org/apache/hivemind/lib/pipeline/BridgeBuilder.java
Index: BridgeBuilder.java
===================================================================
RCS file: /home/cvs/jakarta-hivemind/library/src/java/org/apache/hivemind/lib/pipeline/BridgeBuilder.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- BridgeBuilder.java 8 Nov 2004 14:14:25 -0000 1.5
+++ BridgeBuilder.java 9 Nov 2004 20:58:20 -0000 1.6
@@ -61,7 +61,7 @@
_serviceInterface = serviceInterface;
_filterInterface = filterInterface;
- String name = ClassFabUtils.generateClassName("PipelineBridge");
+ String name = ClassFabUtils.generateClassName(_serviceInterface);
_classFab = classFactory.newClass(name, Object.class);
1.3 +44 -10 jakarta-hivemind/framework/src/test/org/apache/hivemind/impl/TestMethodIterator.java
Index: TestMethodIterator.java
===================================================================
RCS file: /home/cvs/jakarta-hivemind/framework/src/test/org/apache/hivemind/impl/TestMethodIterator.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TestMethodIterator.java 13 Sep 2004 14:48:16 -0000 1.2
+++ TestMethodIterator.java 9 Nov 2004 20:58:20 -0000 1.3
@@ -14,15 +14,18 @@
package org.apache.hivemind.impl;
+import java.io.IOException;
+import java.util.NoSuchElementException;
+
import org.apache.hivemind.service.MethodIterator;
import org.apache.hivemind.service.MethodSignature;
import org.apache.hivemind.test.HiveMindTestCase;
/**
* Tests for {@link org.apache.hivemind.service.MethodIterator}.
- *
+ *
* @author Howard Lewis Ship
- * @since 3.1
+ * @since 1.0
*/
public class TestMethodIterator extends HiveMindTestCase
{
@@ -45,6 +48,23 @@
public String toString();
}
+ /** @since 1.1 */
+ static interface Openable
+ {
+ public void open();
+ }
+
+ /** @since 1.1 */
+ static interface OpenableWithError
+ {
+ public void open() throws IOException;
+ }
+
+ /** @since 1.1 */
+ static interface CombinedOpeneable extends Openable, OpenableWithError
+ {
+ }
+
public void testNormal()
{
MethodIterator mi = new MethodIterator(Runnable.class);
@@ -57,7 +77,14 @@
assertFalse(mi.hasNext());
- assertNull(mi.next());
+ try
+ {
+ mi.next();
+ }
+ catch (NoSuchElementException ex)
+ {
+ //
+ }
assertEquals(false, mi.getToString());
}
@@ -83,8 +110,6 @@
assertFalse(mi.hasNext());
- assertNull(mi.next());
-
assertEquals(false, mi.getToString());
}
@@ -96,8 +121,6 @@
assertEquals(new MethodSignature(void.class, "run", null, null), actual);
- assertNull(mi.next());
-
assertEquals(false, mi.getToString());
}
@@ -109,8 +132,19 @@
assertEquals(new MethodSignature(String.class, "toString", null, null), actual);
- assertNull(mi.next());
-
assertEquals(true, mi.getToString());
}
-}
+
+ /** @since 1.1 */
+ public void testFilterInheritedMethods()
+ {
+ MethodIterator mi = new MethodIterator(CombinedOpeneable.class);
+
+ MethodSignature actual = mi.next();
+
+ assertEquals(new MethodSignature(void.class, "open", null, new Class[]
+ { IOException.class }), actual);
+
+ assertEquals(false, mi.hasNext());
+ }
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-cvs-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-cvs-help@jakarta.apache.org