jcarman 2005/04/27 07:19:46
Modified: framework/src/java/org/apache/hivemind/impl
ImplStrings.properties
RegistryInfrastructureImpl.java ImplMessages.java
framework/src/test/org/apache/hivemind/impl
TestRegistryInfrastructure.java
Log:
More helpful message when serviceId is not fully qualified.
Revision Changes Path
1.19 +1 -0
jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/ImplStrings.properties
Index: ImplStrings.properties
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/ImplStrings.properties,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- ImplStrings.properties 17 Feb 2005 19:46:44 -0000 1.18
+++ ImplStrings.properties 27 Apr 2005 14:19:46 -0000 1.19
@@ -21,6 +21,7 @@
translator-instantiation-failure=Unable to instantiate translator class {0}:
{1}
registry-shutdown=The HiveMind Registry has been shutdown.
no-such-service-point=Service point {0} does not exist.
+unqualified-service-point=The service id specified ("{0}") is not fully
qualified. Perhaps you meant one of {1}.
no-service-point-for-interface=There is no service point for interface {0}.
multiple-service-points-for-interface=There are multiple service points for
interface {0}: {1}.
unable-to-load-class=Could not load class {0} from {1}: {2}
1.12 +37 -2
jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/RegistryInfrastructureImpl.java
Index: RegistryInfrastructureImpl.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/RegistryInfrastructureImpl.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- RegistryInfrastructureImpl.java 31 Mar 2005 16:07:03 -0000 1.11
+++ RegistryInfrastructureImpl.java 27 Apr 2005 14:19:46 -0000 1.12
@@ -151,11 +151,32 @@
public ServicePoint getServicePoint(String serviceId, Module module)
{
checkShutdown();
-
ServicePoint result = (ServicePoint) _servicePoints.get(serviceId);
-
if (result == null)
+ {
+ if( serviceId.indexOf( '.' ) == -1 )
+ {
+ final List possibleMatches =
getMatchingServiceIds(serviceId);
+ if( !possibleMatches.isEmpty() )
+ {
+ final StringBuffer sb = new StringBuffer();
+ for( Iterator i = possibleMatches.iterator();
i.hasNext(); )
+ {
+ final String matching = ( String )i.next();
+ sb.append( '\"' );
+ sb.append( matching );
+ sb.append( '\"' );
+ if( i.hasNext() )
+ {
+ sb.append( ", " );
+ }
+ }
+ throw new
ApplicationRuntimeException(ImplMessages.unqualifiedServicePoint(serviceId,
sb.toString() ));
+ }
+ }
throw new
ApplicationRuntimeException(ImplMessages.noSuchServicePoint(serviceId));
+ }
+
if (!result.visibleToModule(module))
throw new
ApplicationRuntimeException(ImplMessages.serviceNotVisible(serviceId, module));
@@ -163,6 +184,20 @@
return result;
}
+ private List getMatchingServiceIds(String serviceId)
+ {
+ final List possibleMatches = new LinkedList();
+ for( Iterator i = _servicePoints.values().iterator(); i.hasNext(); )
+ {
+ final ServicePoint servicePoint = ( ServicePoint )i.next();
+ if( servicePoint.getExtensionPointId().equals(
servicePoint.getModule().getModuleId() + "." + serviceId ) )
+ {
+ possibleMatches.add( servicePoint.getExtensionPointId() );
+ }
+ }
+ return possibleMatches;
+ }
+
public Object getService(String serviceId, Class serviceInterface,
Module module)
{
ServicePoint point = getServicePoint(serviceId, module);
1.27 +5 -0
jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/ImplMessages.java
Index: ImplMessages.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/ImplMessages.java,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- ImplMessages.java 17 Feb 2005 19:46:44 -0000 1.26
+++ ImplMessages.java 27 Apr 2005 14:19:46 -0000 1.27
@@ -84,6 +84,11 @@
cause);
}
+ public static String unqualifiedServicePoint( String serviceId, String
matchingIds )
+ {
+ return _formatter.format( "unqualified-service-point", serviceId,
matchingIds );
+ }
+
public static String noSuchServicePoint(String serviceId)
{
return _formatter.format("no-such-service-point", serviceId);
1.4 +39 -0
jakarta-hivemind/framework/src/test/org/apache/hivemind/impl/TestRegistryInfrastructure.java
Index: TestRegistryInfrastructure.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/framework/src/test/org/apache/hivemind/impl/TestRegistryInfrastructure.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- TestRegistryInfrastructure.java 5 Jan 2005 18:04:51 -0000 1.3
+++ TestRegistryInfrastructure.java 27 Apr 2005 14:19:46 -0000 1.4
@@ -20,6 +20,7 @@
import org.apache.hivemind.internal.ConfigurationPoint;
import org.apache.hivemind.internal.RegistryInfrastructure;
import org.apache.hivemind.internal.ServicePoint;
+import org.apache.hivemind.internal.Visibility;
import org.apache.hivemind.test.HiveMindTestCase;
import org.easymock.MockControl;
@@ -48,6 +49,44 @@
}
}
+ public void testGetUnqualifiedServicePoint()
+ {
+
+ RegistryInfrastructureImpl r = new RegistryInfrastructureImpl(null,
null);
+ final ModuleImpl module1 = new ModuleImpl();
+ module1.setModuleId( "module1" );
+ final ServicePointImpl servicePoint1 = new ServicePointImpl();
+ servicePoint1.setModule( module1 );
+ servicePoint1.setExtensionPointId( "module1.foo" );
+ servicePoint1.setVisibility( Visibility.PUBLIC );
+ r.addServicePoint( servicePoint1 );
+ try
+ {
+ r.getServicePoint("foo", null);
+ unreachable();
+ }
+ catch (ApplicationRuntimeException ex)
+ {
+ assertEquals(ImplMessages.unqualifiedServicePoint( "foo",
"\"module1.foo\""), ex.getMessage());
+ }
+ final ModuleImpl module2 = new ModuleImpl();
+ module2.setModuleId( "module2" );
+ final ServicePointImpl servicePoint2 = new ServicePointImpl();
+ servicePoint2.setModule( module2 );
+ servicePoint2.setExtensionPointId( "module2.foo" );
+ servicePoint2.setVisibility( Visibility.PUBLIC );
+ r.addServicePoint( servicePoint2 );
+ try
+ {
+ r.getServicePoint("foo", null);
+ unreachable();
+ }
+ catch (ApplicationRuntimeException ex)
+ {
+ assertEquals(ImplMessages.unqualifiedServicePoint( "foo",
"\"module1.foo\", \"module2.foo\""), ex.getMessage());
+ }
+ }
+
/**
* Ensure that the Registry "locks down" after being started up.
*
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]