Index: framework/src/java/org/apache/hivemind/Registry.java =================================================================== RCS file: /home/cvspublic/jakarta-hivemind/framework/src/java/org/apache/hivemind/Registry.java,v retrieving revision 1.6 diff -u -r1.6 Registry.java --- framework/src/java/org/apache/hivemind/Registry.java 17 Jul 2004 23:50:39 -0000 1.6 +++ framework/src/java/org/apache/hivemind/Registry.java 4 Aug 2004 13:27:23 -0000 @@ -32,6 +32,35 @@ public interface Registry extends SymbolSource { /** + * Returns true if a configuration for the specified id exists. + * + * @param configurationId + * @return true if a configuration for the specified id exists + */ + public boolean containsConfiguration(String configurationId); + + /** + * Returns true if a single service for the specified service interface + * class exists. + * + * @param serviceInterface + * @return true if a single service for the specified service interface + * exists + */ + public boolean containsService(Class serviceInterface); + + /** + * Returns true if a service for the specified service id and service + * interface exists. + * + * @param serviceId + * @param serviceInterface + * @return true if a service for the specified service id and service + * interface exists + */ + public boolean containsService(String serviceId, Class serviceInterface); + + /** * Returns a configuration as a List of elements (as defined by the schema * for the configuration point, or as {@link Element}s if no configuration point * does not define a schema. Index: framework/src/java/org/apache/hivemind/impl/RegistryImpl.java =================================================================== RCS file: /home/cvspublic/jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/RegistryImpl.java,v retrieving revision 1.15 diff -u -r1.15 RegistryImpl.java --- framework/src/java/org/apache/hivemind/impl/RegistryImpl.java 29 Jul 2004 13:18:49 -0000 1.15 +++ framework/src/java/org/apache/hivemind/impl/RegistryImpl.java 4 Aug 2004 13:27:24 -0000 @@ -519,6 +519,43 @@ _threadEventNotifier.fireThreadCleanup(); } + public boolean containsConfiguration(String configurationId) + { + checkShutdown(); + + return _configurationPoints.containsKey(configurationId); + } + + public boolean containsService(Class serviceInterface) + { + boolean contains = false; + + List servicePoints = (List) _servicePointsByInterface.get(serviceInterface); + + if ((servicePoints != null) && (servicePoints.size() == 1)) + { + contains = true; + } + + return contains; + } + + public boolean containsService(String serviceId, Class serviceInterface) + { + checkShutdown(); + + boolean contains = false; + + ServicePoint point = (ServicePoint) _servicePoints.get(serviceId); + + if ((point != null) && (point.getServiceInterface().equals(serviceInterface))) + { + contains = true; + } + + return contains; + } + public void setLocale(Locale locale) { _locale = locale; Index: framework/src/test/hivemind/test/TestContains.java =================================================================== RCS file: framework/src/test/hivemind/test/TestContains.java diff -N framework/src/test/hivemind/test/TestContains.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ framework/src/test/hivemind/test/TestContains.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,68 @@ +//Copyright 2004 The Apache Software Foundation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package hivemind.test; + +import org.apache.hivemind.Registry; + +/** + * Tests Registry.contains functionality. + * + * @author Naresh Sikha + */ +public class TestContains extends FrameworkTestCase +{ + private Registry registry; + + protected void setUp() throws Exception + { + registry = buildFrameworkRegistry("contains.xml"); + } + + protected void tearDown() throws Exception + { + registry.shutdown(); + } + + public void testConfiguration() + { + assertTrue(registry.containsConfiguration("hivemind.tests.contains.Simple")); + } + + public void testConfigurationFailure() + { + assertTrue(!registry.containsConfiguration("xhivemind.tests.contains.Simple")); + } + + public void testService() + { + assertTrue(registry.containsService("hivemind.tests.contains.multipleServiceOne", IMultipleService.class)); + } + + public void testServiceFailure() + { + assertTrue(!registry.containsService("hivemind.tests.contains.multipleServiceOne", IUniqueService.class)); + assertTrue(!registry.containsService("xhivemind.tests.contains.multipleServiceOne", IMultipleService.class)); + } + + public void testUniqueService() + { + assertTrue(registry.containsService(IUniqueService.class)); + } + + public void testUniqueServiceFailure() + { + assertTrue(!registry.containsService(IMultipleService.class)); + } + +} Index: framework/src/test/hivemind/test/contains.xml =================================================================== RCS file: framework/src/test/hivemind/test/contains.xml diff -N framework/src/test/hivemind/test/contains.xml --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ framework/src/test/hivemind/test/contains.xml 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +