Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVioleta Georgieva2012-05-03 15:49:33 -0400
committerVioleta Georgieva2012-05-03 15:49:33 -0400
commit5eb2c4b43d2d07c54d00e7eaa7e9394ecab6644b (patch)
tree1151ca900ac593a517bed28b7f07f71b93e7c2bb
parentefeb54f60e0c012bde5eab899848a72fc6ce62d3 (diff)
downloadorg.eclipse.gemini.naming-1.0.0.RC1.tar.gz
org.eclipse.gemini.naming-1.0.0.RC1.tar.xz
org.eclipse.gemini.naming-1.0.0.RC1.zip
Created tag 1.0.0.RC1.1.0.0.RC1
-rw-r--r--framework/META-INF/MANIFEST.MF2
-rw-r--r--framework/pom.xml4
-rw-r--r--framework/src/main/java/org/eclipse/gemini/naming/Activator.java553
-rw-r--r--framework/src/main/java/org/eclipse/gemini/naming/ContextWrapperImpl.java500
-rw-r--r--integration-testing/pom.xml2
-rw-r--r--integration-testing/src/test/java/org/eclipse/gemini/naming/test/FactoryResolutionTestCase.java57
-rw-r--r--integration-testing/src/test/java/org/eclipse/gemini/naming/test/NamingTestCase.java2
-rw-r--r--org.eclipse.gemini.naming.feature/feature.xml2
-rw-r--r--org.eclipse.gemini.naming.feature/pom.xml2
-rw-r--r--org.eclipse.gemini.naming.repository/category.xml2
-rw-r--r--org.eclipse.gemini.naming.repository/pom.xml2
-rw-r--r--org.eclipse.gemini.naming.target/pom.xml2
-rw-r--r--org.eclipse.gemini.naming.utests/pom.xml2
-rw-r--r--org.eclipse.gemini.naming.utests/src/test/java/org/eclipse/gemini/naming/ActivatorTestCase.java516
-rw-r--r--pom.xml2
15 files changed, 866 insertions, 784 deletions
diff --git a/framework/META-INF/MANIFEST.MF b/framework/META-INF/MANIFEST.MF
index f870fdd..481190a 100644
--- a/framework/META-INF/MANIFEST.MF
+++ b/framework/META-INF/MANIFEST.MF
@@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2
Bundle-Name: Gemini Naming
Bundle-SymbolicName: org.eclipse.gemini.naming
Bundle-Vendor: Eclipse.org
-Bundle-Version: 1.0.0.qualifier
+Bundle-Version: 1.0.0.RC1
Bundle-Activator: org.eclipse.gemini.naming.Activator
Bundle-Description: Gemini Naming bundle
Bundle-Category: jndi
diff --git a/framework/pom.xml b/framework/pom.xml
index 4541b0a..3ecd710 100644
--- a/framework/pom.xml
+++ b/framework/pom.xml
@@ -4,14 +4,14 @@
<groupId>org.eclipse.gemini.naming</groupId>
<artifactId>org.eclipse.gemini.naming</artifactId>
<packaging>eclipse-plugin</packaging>
- <version>1.0.0-SNAPSHOT</version>
+ <version>1.0.0.RC1</version>
<name>Gemini Naming Bundle</name>
<url>http://maven.apache.org</url>
<parent>
<groupId>org.eclipse.gemini.naming</groupId>
<artifactId>org.eclipse.gemini.naming.parent</artifactId>
- <version>1.0.0-SNAPSHOT</version>
+ <version>1.0.0.RC1</version>
</parent>
<build>
diff --git a/framework/src/main/java/org/eclipse/gemini/naming/Activator.java b/framework/src/main/java/org/eclipse/gemini/naming/Activator.java
index 357f100..1efdc77 100644
--- a/framework/src/main/java/org/eclipse/gemini/naming/Activator.java
+++ b/framework/src/main/java/org/eclipse/gemini/naming/Activator.java
@@ -1,267 +1,288 @@
-/*******************************************************************************
- * Copyright (c) 2010, 2012 Oracle.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * and Apache License v2.0 which accompanies this distribution.
- * The Eclipse Public License is available at
- * http://www.eclipse.org/legal/epl-v10.html
- * and the Apache License v2.0 is available at
- * http://www.opensource.org/licenses/apache2.0.php.
- * You may elect to redistribute this code under either of these licenses.
- *
- * Contributors:
- * Bob Nettleton (Oracle) - Initial Reference Implementation
- ******************************************************************************/
-
-package org.eclipse.gemini.naming;
-
-import java.lang.reflect.Field;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.naming.NamingException;
-import javax.naming.spi.InitialContextFactoryBuilder;
-import javax.naming.spi.NamingManager;
-import javax.naming.spi.ObjectFactory;
-import javax.naming.spi.ObjectFactoryBuilder;
-
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceRegistration;
-import org.osgi.service.jndi.JNDIConstants;
-import org.osgi.service.jndi.JNDIContextManager;
-import org.osgi.service.jndi.JNDIProviderAdmin;
-
-/**
- * Activator implementation for the Gemini Naming Bundle.
- *
- * This activator's main purpose is to register the JNDI Builder singleton
- * implementations that allow the Factory Manager to override the default JNDI
- * framework.
- *
- *
- */
-public class Activator implements BundleActivator {
-
- private static final String OSGI_URL_SCHEME = "osgi";
-
- private static Logger logger = Logger.getLogger(Activator.class.getName());
-
- private BundleContext m_bundleContext = null;
- private final List m_listOfServiceRegistrations = new LinkedList();
-
- private CloseableProviderAdmin m_providerAdminService;
- private ContextManagerServiceFactoryImpl m_contextManagerServiceFactory;
-
- /*
- * Create the Factory Manager's builder implementation, and register it with
- * the JNDI NamingManager.
- *
- * @see
- * org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext
- * )
- */
- public void start(BundleContext context) throws Exception {
- logger.info("Initializing Gemini Naming Factory Manager Bundle");
-
- m_bundleContext = context;
-
- // register static singletons with the JNDI framework
- logger.info("Installing Static Singletons");
- registerInitialContextFactoryBuilderSingleton();
- registerObjectFactoryBuilderSingleton();
-
- logger.info("Registering URL Context Factory for 'osgi' URL scheme");
- registerOSGiURLContextFactory();
-
- logger.info("Registering Default Runtime Builder for JRE-provided factories");
- registerDefaultRuntimeBuilder();
-
- logger.info("Registering ContextManager service");
- // register the JNDIContextManager service once all Factory
- // Manager initialization is complete
- registerContextManager();
-
- logger.info("Registering ProviderAdmin service");
- // register the JNDIProviderAdmin interface, used by OSGi-aware
- // context implementations to resolve JNDI references
- registerProviderAdmin();
- }
-
-
- /*
- * Allow the Builder implementation to clean up any
- * ServiceListener/ServiceTracker instances.
- *
- * @see
- * org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
- */
- public void stop(BundleContext context) throws Exception {
- logger.info("Shutting down Gemini Naming Factory Manager Bundle");
-
- // close all known Contexts associated with the JNDIContextManager service
- m_contextManagerServiceFactory.closeAll();
-
- // close the JNDIProviderAdmin service
- m_providerAdminService.close();
-
- // unregister all the JNDI services registered by this Activator
- Iterator iterator = m_listOfServiceRegistrations.iterator();
- while(iterator.hasNext()) {
- ServiceRegistration serviceRegistration =
- (ServiceRegistration)iterator.next();
- serviceRegistration.unregister();
- }
-
- unregisterSingletons();
- }
-
-
- /**
- * Registers the InitialContextFactoryBuilder static singleton
- * @throws NamingException on any error that occurs during the setting
- * of the builder.
- */
- private static void registerInitialContextFactoryBuilderSingleton() throws NamingException {
- try {
- NamingManager.setInitialContextFactoryBuilder(new TraditionalInitialContextFactoryBuilder());
- }
- catch (IllegalStateException illegalStateException) {
- logger.log(Level.SEVERE,
- "Gemini Naming Implementation cannot set the InitialContextFactoryBuilder - another builder was already installed",
- illegalStateException);
- NamingException namingException =
- new NamingException("Error occurred while attempting to set the IntialContextFactoryBuilder.");
- namingException.setRootCause(illegalStateException);
- throw namingException;
- }
- catch(SecurityException securityException) {
- logger.log(Level.SEVERE,
- "Gemini Naming Implementation did not have the proper security permissions to install the InitialContextFactoryBuilder",
- securityException);
- NamingException namingException =
- new NamingException("Error occurred while attempting to set the IntialContextFactoryBuilder.");
- namingException.setRootCause(securityException);
- throw namingException;
- }
- }
-
-
- /**
- * Registers the ObjectFactoryBuilder static singleton
- * @throws NamingException on any error that occurs during the setting
- * of the builder.
- */
- private static void registerObjectFactoryBuilderSingleton() throws NamingException {
- try {
- NamingManager.setObjectFactoryBuilder(new TraditionalObjectFactoryBuilder());
- }
- catch (IllegalStateException illegalStateException) {
- logger.log(Level.SEVERE,
- "Gemini Naming Implementation cannot set the ObjectFactoryBuilder - another builder was already installed",
- illegalStateException);
- NamingException namingException =
- new NamingException("Error occurred while attempting to set the ObjectFactoryBuilder.");
- namingException.setRootCause(illegalStateException);
- throw namingException;
- }
- catch(SecurityException securityException) {
- logger.log(Level.SEVERE,
- "Gemini Naming Implementation did not have the proper security permissions to install the ObjectFactoryBuilder",
- securityException);
- NamingException namingException =
- new NamingException("Error occurred while attempting to set the ObjectFactoryBuilder.");
- namingException.setRootCause(securityException);
- throw namingException;
- }
- }
-
- /**
- * Unregisters the InitialContextFactoryBuilder static singleton
- * and the ObjectFactoryBuilder static singleton.
- */
- private static void unregisterSingletons() {
- Field[] fields = NamingManager.class.getDeclaredFields();
- if (fields != null && fields.length > 0) {
- for (Field field: fields) {
- if (InitialContextFactoryBuilder.class.equals(field.getType())
- || ObjectFactoryBuilder.class.equals(field.getType())){
- field.setAccessible(true);
- try {
- field.set(null, null);
- } catch (IllegalArgumentException e) {
- logger.log(Level.SEVERE,
- "Unable to reset NamingManager static singleton " + field.getType(),
- e);
- } catch (IllegalAccessException e) {
- logger.log(Level.SEVERE,
- "Unable to reset NamingManager static singleton " + field.getType(),
- e);
- }
- }
- }
- }
- }
-
-
-
-
- /**
- * Registers the OSGi URL Context Factory.
- *
- */
- private void registerOSGiURLContextFactory() {
- Hashtable serviceProperties = new Hashtable();
- serviceProperties.put(JNDIConstants.JNDI_URLSCHEME, OSGI_URL_SCHEME);
-
- ServiceRegistration serviceRegistration =
- m_bundleContext.registerService(ObjectFactory.class.getName(),
- new OSGiURLContextFactoryServiceFactory(),
- serviceProperties);
- m_listOfServiceRegistrations.add(serviceRegistration);
- }
-
-
- /**
- * Registers the InitialContextFactoryBuilder implementation that
- * is responsible for loading the JDK-defined providers that must be
- * loaded from the boot classpath.
- *
- */
- private void registerDefaultRuntimeBuilder() {
- ServiceRegistration serviceRegistration =
- m_bundleContext.registerService(InitialContextFactoryBuilder.class.getName(),
- new DefaultRuntimeInitialContextFactoryBuilder(),
- null);
- m_listOfServiceRegistrations.add(serviceRegistration);
- }
-
-
- private void registerContextManager() {
- m_contextManagerServiceFactory =
- new ContextManagerServiceFactoryImpl(m_bundleContext);
- ServiceRegistration serviceRegistration =
- m_bundleContext.registerService(JNDIContextManager.class.getName(),
- m_contextManagerServiceFactory,
- null);
- m_listOfServiceRegistrations.add(serviceRegistration);
- }
-
-
- private void registerProviderAdmin() {
- m_providerAdminService =
- new SecurityAwareProviderAdminImpl(new ProviderAdminImpl(m_bundleContext));
-
-
- ServiceRegistration serviceRegistration =
- m_bundleContext.registerService(JNDIProviderAdmin.class.getName(),
- m_providerAdminService,
- null);
- m_listOfServiceRegistrations.add(serviceRegistration);
- }
-
+/*******************************************************************************
+ * Copyright (c) 2010, 2012 Oracle.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and Apache License v2.0 which accompanies this distribution.
+ * The Eclipse Public License is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * and the Apache License v2.0 is available at
+ * http://www.opensource.org/licenses/apache2.0.php.
+ * You may elect to redistribute this code under either of these licenses.
+ *
+ * Contributors:
+ * Bob Nettleton (Oracle) - Initial Reference Implementation
+ ******************************************************************************/
+
+package org.eclipse.gemini.naming;
+
+import java.lang.reflect.Field;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.naming.NamingException;
+import javax.naming.spi.InitialContextFactoryBuilder;
+import javax.naming.spi.NamingManager;
+import javax.naming.spi.ObjectFactory;
+import javax.naming.spi.ObjectFactoryBuilder;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.jndi.JNDIConstants;
+import org.osgi.service.jndi.JNDIContextManager;
+import org.osgi.service.jndi.JNDIProviderAdmin;
+
+/**
+ * Activator implementation for the Gemini Naming Bundle.
+ *
+ * This activator's main purpose is to register the JNDI Builder singleton
+ * implementations that allow the Factory Manager to override the default JNDI
+ * framework.
+ *
+ *
+ */
+public class Activator implements BundleActivator {
+
+ private static final String OSGI_URL_SCHEME = "osgi";
+ private static final String RMI_URL_SCHEME = "rmi";
+ private static final String RMI_URL_CONTEXT_FACTORY = "com.sun.jndi.url.rmi.rmiURLContextFactory";
+
+ private static Logger logger = Logger.getLogger(Activator.class.getName());
+
+ private BundleContext m_bundleContext = null;
+ private final List<ServiceRegistration> m_listOfServiceRegistrations = new LinkedList<ServiceRegistration>();
+
+ private CloseableProviderAdmin m_providerAdminService;
+ private ContextManagerServiceFactoryImpl m_contextManagerServiceFactory;
+
+ /*
+ * Create the Factory Manager's builder implementation, and register it with
+ * the JNDI NamingManager.
+ *
+ * @see
+ * org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext
+ * )
+ */
+ public void start(BundleContext context) throws Exception {
+ logger.info("Initializing Gemini Naming Factory Manager Bundle");
+
+ m_bundleContext = context;
+
+ // register static singletons with the JNDI framework
+ logger.info("Installing Static Singletons");
+ registerInitialContextFactoryBuilderSingleton();
+ registerObjectFactoryBuilderSingleton();
+
+ logger.info("Registering URL Context Factory for 'osgi' URL scheme");
+ registerOSGiURLContextFactory();
+
+ logger.info("Registering Default Runtime Builder for JRE-provided factories");
+ registerDefaultRuntimeBuilder();
+
+ logger.info("Registering ContextManager service");
+ // register the JNDIContextManager service once all Factory
+ // Manager initialization is complete
+ registerContextManager();
+
+ logger.info("Registering ProviderAdmin service");
+ // register the JNDIProviderAdmin interface, used by OSGi-aware
+ // context implementations to resolve JNDI references
+ registerProviderAdmin();
+ }
+
+
+ /*
+ * Allow the Builder implementation to clean up any
+ * ServiceListener/ServiceTracker instances.
+ *
+ * @see
+ * org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ logger.info("Shutting down Gemini Naming Factory Manager Bundle");
+
+ // close all known Contexts associated with the JNDIContextManager service
+ m_contextManagerServiceFactory.closeAll();
+
+ // close the JNDIProviderAdmin service
+ m_providerAdminService.close();
+
+ // unregister all the JNDI services registered by this Activator
+ Iterator<ServiceRegistration> iterator = m_listOfServiceRegistrations.iterator();
+ while(iterator.hasNext()) {
+ ServiceRegistration serviceRegistration =
+ (ServiceRegistration)iterator.next();
+ serviceRegistration.unregister();
+ }
+
+ unregisterSingletons();
+ }
+
+
+ /**
+ * Registers the InitialContextFactoryBuilder static singleton
+ * @throws NamingException on any error that occurs during the setting
+ * of the builder.
+ */
+ private static void registerInitialContextFactoryBuilderSingleton() throws NamingException {
+ try {
+ NamingManager.setInitialContextFactoryBuilder(new TraditionalInitialContextFactoryBuilder());
+ }
+ catch (IllegalStateException illegalStateException) {
+ logger.log(Level.SEVERE,
+ "Gemini Naming Implementation cannot set the InitialContextFactoryBuilder - another builder was already installed",
+ illegalStateException);
+ NamingException namingException =
+ new NamingException("Error occurred while attempting to set the IntialContextFactoryBuilder.");
+ namingException.setRootCause(illegalStateException);
+ throw namingException;
+ }
+ catch(SecurityException securityException) {
+ logger.log(Level.SEVERE,
+ "Gemini Naming Implementation did not have the proper security permissions to install the InitialContextFactoryBuilder",
+ securityException);
+ NamingException namingException =
+ new NamingException("Error occurred while attempting to set the IntialContextFactoryBuilder.");
+ namingException.setRootCause(securityException);
+ throw namingException;
+ }
+ }
+
+
+ /**
+ * Registers the ObjectFactoryBuilder static singleton
+ * @throws NamingException on any error that occurs during the setting
+ * of the builder.
+ */
+ private static void registerObjectFactoryBuilderSingleton() throws NamingException {
+ try {
+ NamingManager.setObjectFactoryBuilder(new TraditionalObjectFactoryBuilder());
+ }
+ catch (IllegalStateException illegalStateException) {
+ logger.log(Level.SEVERE,
+ "Gemini Naming Implementation cannot set the ObjectFactoryBuilder - another builder was already installed",
+ illegalStateException);
+ NamingException namingException =
+ new NamingException("Error occurred while attempting to set the ObjectFactoryBuilder.");
+ namingException.setRootCause(illegalStateException);
+ throw namingException;
+ }
+ catch(SecurityException securityException) {
+ logger.log(Level.SEVERE,
+ "Gemini Naming Implementation did not have the proper security permissions to install the ObjectFactoryBuilder",
+ securityException);
+ NamingException namingException =
+ new NamingException("Error occurred while attempting to set the ObjectFactoryBuilder.");
+ namingException.setRootCause(securityException);
+ throw namingException;
+ }
+ }
+
+ /**
+ * Unregisters the InitialContextFactoryBuilder static singleton
+ * and the ObjectFactoryBuilder static singleton.
+ */
+ private static void unregisterSingletons() {
+ Field[] fields = NamingManager.class.getDeclaredFields();
+ if (fields != null && fields.length > 0) {
+ for (Field field: fields) {
+ if (InitialContextFactoryBuilder.class.equals(field.getType())
+ || ObjectFactoryBuilder.class.equals(field.getType())){
+ field.setAccessible(true);
+ try {
+ field.set(null, null);
+ } catch (IllegalArgumentException e) {
+ logger.log(Level.SEVERE,
+ "Unable to reset NamingManager static singleton " + field.getType(),
+ e);
+ } catch (IllegalAccessException e) {
+ logger.log(Level.SEVERE,
+ "Unable to reset NamingManager static singleton " + field.getType(),
+ e);
+ }
+ }
+ }
+ }
+ }
+
+
+
+
+ /**
+ * Registers the OSGi URL Context Factory.
+ *
+ */
+ private void registerOSGiURLContextFactory() {
+ Hashtable<Object, Object> serviceProperties = new Hashtable<Object, Object>();
+ serviceProperties.put(JNDIConstants.JNDI_URLSCHEME, OSGI_URL_SCHEME);
+
+ ServiceRegistration serviceRegistration =
+ m_bundleContext.registerService(ObjectFactory.class.getName(),
+ new OSGiURLContextFactoryServiceFactory(),
+ serviceProperties);
+ m_listOfServiceRegistrations.add(serviceRegistration);
+ }
+
+
+ /**
+ * Registers the InitialContextFactoryBuilder implementation that
+ * is responsible for loading the JDK-defined providers that must be
+ * loaded from the boot classpath.
+ *
+ */
+ private void registerDefaultRuntimeBuilder() {
+ ServiceRegistration serviceRegistration =
+ m_bundleContext.registerService(InitialContextFactoryBuilder.class.getName(),
+ new DefaultRuntimeInitialContextFactoryBuilder(),
+ null);
+ m_listOfServiceRegistrations.add(serviceRegistration);
+
+ Hashtable<Object, Object> props = new Hashtable<Object, Object>();
+ props.put(JNDIConstants.JNDI_URLSCHEME, RMI_URL_SCHEME);
+ try {
+ ServiceRegistration rmiRegistration =
+ m_bundleContext.registerService(ObjectFactory.class.getName(),
+ ClassLoader.getSystemClassLoader().loadClass(RMI_URL_CONTEXT_FACTORY).newInstance(),
+ props);
+ m_listOfServiceRegistrations.add(rmiRegistration);
+ }
+ catch(ClassNotFoundException e) {
+ logger.log(Level.SEVERE, RMI_URL_CONTEXT_FACTORY + " cannot be found through the system classloader.", e);
+ }
+ catch(InstantiationException e) {
+ logger.log(Level.SEVERE, "Exception occurred while instantiating " + RMI_URL_CONTEXT_FACTORY, e);
+ }
+ catch(IllegalAccessException e) {
+ logger.log(Level.SEVERE, "Exception occured while instantiating " + RMI_URL_CONTEXT_FACTORY, e);
+ }
+ }
+
+
+ private void registerContextManager() {
+ m_contextManagerServiceFactory =
+ new ContextManagerServiceFactoryImpl(m_bundleContext);
+ ServiceRegistration serviceRegistration =
+ m_bundleContext.registerService(JNDIContextManager.class.getName(),
+ m_contextManagerServiceFactory,
+ null);
+ m_listOfServiceRegistrations.add(serviceRegistration);
+ }
+
+
+ private void registerProviderAdmin() {
+ m_providerAdminService =
+ new SecurityAwareProviderAdminImpl(new ProviderAdminImpl(m_bundleContext));
+
+
+ ServiceRegistration serviceRegistration =
+ m_bundleContext.registerService(JNDIProviderAdmin.class.getName(),
+ m_providerAdminService,
+ null);
+ m_listOfServiceRegistrations.add(serviceRegistration);
+ }
+
} \ No newline at end of file
diff --git a/framework/src/main/java/org/eclipse/gemini/naming/ContextWrapperImpl.java b/framework/src/main/java/org/eclipse/gemini/naming/ContextWrapperImpl.java
index af2683e..2af7d76 100644
--- a/framework/src/main/java/org/eclipse/gemini/naming/ContextWrapperImpl.java
+++ b/framework/src/main/java/org/eclipse/gemini/naming/ContextWrapperImpl.java
@@ -1,250 +1,250 @@
-/*******************************************************************************
- * Copyright (c) 2010 Oracle.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * and Apache License v2.0 which accompanies this distribution.
- * The Eclipse Public License is available at
- * http://www.eclipse.org/legal/epl-v10.html
- * and the Apache License v2.0 is available at
- * http://www.opensource.org/licenses/apache2.0.php.
- * You may elect to redistribute this code under either of these licenses.
- *
- * Contributors:
- * Bob Nettleton (Oracle) - Initial Reference Implementation
- ******************************************************************************/
-
-package org.eclipse.gemini.naming;
-
-import javax.naming.*;
-import javax.naming.spi.ObjectFactory;
-
-import java.security.PrivilegedExceptionAction;
-import java.util.Hashtable;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * A Decorated Context class that will allow the Gemini Naming Framework to handle
- * requests for URL context factory lookups.
- *
- */
-class ContextWrapperImpl implements Context {
-
- private static Logger logger = Logger.getLogger(ContextWrapperImpl.class.getName());
-
- private final Context m_context;
- private final FactoryManager m_factoryManager;
-
- public ContextWrapperImpl(Context context, FactoryManager factoryManager) {
- m_context = context;
- m_factoryManager = factoryManager;
- }
-
-
- public Object lookup(Name name) throws NamingException {
- return m_context.lookup(name);
- }
-
- public Object lookup(String name) throws NamingException {
- if (isURLRequest(name)) {
- // attempt to find a URL Context Factory to satisfy this lookup
- // request
- ObjectFactory objectFactory = null;
- try {
- // obtain URL Context Factory in a doPrivilieged() block
- objectFactory = (ObjectFactory)SecurityUtils.invokePrivilegedAction(new GetObjectFactoryAction(m_factoryManager, name));
- } catch (Exception e) {
- logger.log(Level.FINE,
- "Exception occurred while trying to obtain a reference to a URL Context Factory.",
- e);
- }
-
- if (objectFactory == null) {
- throw new NameNotFoundException(
- "Name: "
- + name
- + " was not found. A URL Context Factory was not registered to handle "
- + "this URL scheme");
- }
-
- try {
- Context context =
- (Context) objectFactory.getObjectInstance(null, null,
- null, m_context.getEnvironment());
- if (context != null) {
- return context.lookup(name);
- }
- else {
- throw new NamingException("Name = " + name
- + "was not found using the URL Context factory.");
- }
- }
- catch (Exception e) {
- if (e instanceof NamingException) {
- // re-throw naming exceptions
- throw (NamingException) e;
- }
-
- NamingException namingException =
- new NameNotFoundException("Exception occurred during URL Context Factory Resolution for name = "
- + name);
- namingException.initCause(e);
- throw namingException;
- }
- }
- else {
- // treat this lookup as a normal lookup
- return m_context.lookup(name);
- }
-
- }
-
-
-
-
- public void bind(Name name, Object obj) throws NamingException {
- m_context.bind(name, obj);
- }
-
- public void bind(String name, Object obj) throws NamingException {
- m_context.bind(name, obj);
- }
-
- public void rebind(Name name, Object obj) throws NamingException {
- m_context.rebind(name, obj);
- }
-
- public void rebind(String name, Object obj) throws NamingException {
- m_context.rebind(name, obj);
- }
-
- public void unbind(Name name) throws NamingException {
- m_context.unbind(name);
- }
-
- public void unbind(String name) throws NamingException {
- m_context.unbind(name);
- }
-
- public void rename(Name oldName, Name newName) throws NamingException {
- m_context.rename(oldName, newName);
- }
-
- public void rename(String oldName, String newName) throws NamingException {
- m_context.rename(oldName, newName);
- }
-
- public NamingEnumeration list(Name name) throws NamingException {
- return m_context.list(name);
- }
-
- public NamingEnumeration list(String name) throws NamingException {
- return m_context.list(name);
- }
-
- public NamingEnumeration listBindings(Name name) throws NamingException {
- return m_context.listBindings(name);
- }
-
- public NamingEnumeration listBindings(String name) throws NamingException {
- return m_context.listBindings(name);
- }
-
- public void destroySubcontext(Name name) throws NamingException {
- m_context.destroySubcontext(name);
- }
-
- public void destroySubcontext(String name) throws NamingException {
- m_context.destroySubcontext(name);
- }
-
- public Context createSubcontext(Name name) throws NamingException {
- return m_context.createSubcontext(name);
- }
-
- public Context createSubcontext(String name) throws NamingException {
- return m_context.createSubcontext(name);
- }
-
- public Object lookupLink(Name name) throws NamingException {
- return m_context.lookupLink(name);
- }
-
- public Object lookupLink(String name) throws NamingException {
- return m_context.lookupLink(name);
- }
-
- public NameParser getNameParser(Name name) throws NamingException {
- return m_context.getNameParser(name);
- }
-
- public NameParser getNameParser(String name) throws NamingException {
- return m_context.getNameParser(name);
- }
-
- public Name composeName(Name name, Name prefix) throws NamingException {
- return m_context.composeName(name, prefix);
- }
-
- public String composeName(String name, String prefix)
- throws NamingException {
- return m_context.composeName(name, prefix);
- }
-
- public Object addToEnvironment(String propName, Object propVal)
- throws NamingException {
- return m_context.addToEnvironment(propName, propVal);
- }
-
- public Object removeFromEnvironment(String propName) throws NamingException {
- return m_context.removeFromEnvironment(propName);
- }
-
- public Hashtable getEnvironment() throws NamingException {
- return m_context.getEnvironment();
- }
-
- public void close() throws NamingException {
- m_context.close();
- }
-
- public String getNameInNamespace() throws NamingException {
- return m_context.getNameInNamespace();
- }
-
- private static boolean isURLRequest(String name) {
- int indexOfColon = name.indexOf(":");
- return (indexOfColon != -1);
- }
-
- private static String getScheme(String name) {
- int indexOfColon = name.indexOf(":");
- if (indexOfColon != -1) {
- return name.substring(0, indexOfColon);
- }
-
- return null;
- }
-
- private static class GetObjectFactoryAction implements PrivilegedExceptionAction {
- private final FactoryManager m_factoryManager;
- private final String m_name;
-
- GetObjectFactoryAction(FactoryManager factoryManager, String name) {
- m_factoryManager = factoryManager;
- m_name = name;
- }
-
- public Object run() throws Exception {
- return obtainObjectFactory(m_name);
- }
-
- private ObjectFactory obtainObjectFactory(String name) {
- ObjectFactory objectFactory;
- synchronized (m_factoryManager) {
- objectFactory = m_factoryManager.getURLContextFactory(getScheme(name));
- }
- return objectFactory;
- }
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2010, 2012 Oracle.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and Apache License v2.0 which accompanies this distribution.
+ * The Eclipse Public License is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * and the Apache License v2.0 is available at
+ * http://www.opensource.org/licenses/apache2.0.php.
+ * You may elect to redistribute this code under either of these licenses.
+ *
+ * Contributors:
+ * Bob Nettleton (Oracle) - Initial Reference Implementation
+ ******************************************************************************/
+
+package org.eclipse.gemini.naming;
+
+import javax.naming.*;
+import javax.naming.spi.ObjectFactory;
+
+import java.security.PrivilegedExceptionAction;
+import java.util.Hashtable;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * A Decorated Context class that will allow the Gemini Naming Framework to handle
+ * requests for URL context factory lookups.
+ *
+ */
+class ContextWrapperImpl implements Context {
+
+ private static Logger logger = Logger.getLogger(ContextWrapperImpl.class.getName());
+
+ private final Context m_context;
+ private final FactoryManager m_factoryManager;
+
+ public ContextWrapperImpl(Context context, FactoryManager factoryManager) {
+ m_context = context;
+ m_factoryManager = factoryManager;
+ }
+
+
+ public Object lookup(Name name) throws NamingException {
+ return getURLContextOrDefaultContext(name.toString()).lookup(name);
+ }
+
+ public Object lookup(String name) throws NamingException {
+ return getURLContextOrDefaultContext(name).lookup(name);
+ }
+
+ public void bind(Name name, Object obj) throws NamingException {
+ getURLContextOrDefaultContext(name.toString()).bind(name, obj);
+ }
+
+ public void bind(String name, Object obj) throws NamingException {
+ getURLContextOrDefaultContext(name).bind(name, obj);
+ }
+
+ public void rebind(Name name, Object obj) throws NamingException {
+ getURLContextOrDefaultContext(name.toString()).rebind(name, obj);
+ }
+
+ public void rebind(String name, Object obj) throws NamingException {
+ getURLContextOrDefaultContext(name).rebind(name, obj);
+ }
+
+ public void unbind(Name name) throws NamingException {
+ getURLContextOrDefaultContext(name.toString()).unbind(name);
+ }
+
+ public void unbind(String name) throws NamingException {
+ getURLContextOrDefaultContext(name).unbind(name);
+ }
+
+ public void rename(Name oldName, Name newName) throws NamingException {
+ getURLContextOrDefaultContext(oldName.toString()).rename(oldName, newName);
+ }
+
+ public void rename(String oldName, String newName) throws NamingException {
+ getURLContextOrDefaultContext(oldName).rename(oldName, newName);
+ }
+
+ public NamingEnumeration list(Name name) throws NamingException {
+ return getURLContextOrDefaultContext(name.toString()).list(name);
+ }
+
+ public NamingEnumeration list(String name) throws NamingException {
+ return getURLContextOrDefaultContext(name).list(name);
+ }
+
+ public NamingEnumeration listBindings(Name name) throws NamingException {
+ return getURLContextOrDefaultContext(name.toString()).listBindings(name);
+ }
+
+ public NamingEnumeration listBindings(String name) throws NamingException {
+ return getURLContextOrDefaultContext(name).listBindings(name);
+ }
+
+ public void destroySubcontext(Name name) throws NamingException {
+ getURLContextOrDefaultContext(name.toString()).destroySubcontext(name);
+ }
+
+ public void destroySubcontext(String name) throws NamingException {
+ getURLContextOrDefaultContext(name).destroySubcontext(name);
+ }
+
+ public Context createSubcontext(Name name) throws NamingException {
+ return getURLContextOrDefaultContext(name.toString()).createSubcontext(name);
+ }
+
+ public Context createSubcontext(String name) throws NamingException {
+ return getURLContextOrDefaultContext(name).createSubcontext(name);
+ }
+
+ public Object lookupLink(Name name) throws NamingException {
+ return getURLContextOrDefaultContext(name.toString()).lookupLink(name);
+ }
+
+ public Object lookupLink(String name) throws NamingException {
+ return getURLContextOrDefaultContext(name).lookupLink(name);
+ }
+
+ public NameParser getNameParser(Name name) throws NamingException {
+ return getURLContextOrDefaultContext(name.toString()).getNameParser(name);
+ }
+
+ public NameParser getNameParser(String name) throws NamingException {
+ return getURLContextOrDefaultContext(name).getNameParser(name);
+ }
+
+ public Name composeName(Name name, Name prefix) throws NamingException {
+ return getURLContextOrDefaultContext(name.toString()).composeName(name, prefix);
+ }
+
+ public String composeName(String name, String prefix)
+ throws NamingException {
+ return getURLContextOrDefaultContext(name).composeName(name, prefix);
+ }
+
+ public Object addToEnvironment(String propName, Object propVal)
+ throws NamingException {
+ return m_context.addToEnvironment(propName, propVal);
+ }
+
+ public Object removeFromEnvironment(String propName) throws NamingException {
+ return m_context.removeFromEnvironment(propName);
+ }
+
+ public Hashtable getEnvironment() throws NamingException {
+ return m_context.getEnvironment();
+ }
+
+ public void close() throws NamingException {
+ m_context.close();
+ }
+
+ public String getNameInNamespace() throws NamingException {
+ return m_context.getNameInNamespace();
+ }
+
+ private static boolean isURLRequest(String name) {
+ int indexOfColon = name.indexOf(":");
+ return (indexOfColon != -1);
+ }
+
+ private static String getScheme(String name) {
+ int indexOfColon = name.indexOf(":");
+ if (indexOfColon != -1) {
+ return name.substring(0, indexOfColon);
+ }
+
+ return null;
+ }
+
+ private Context getURLContextOrDefaultContext(String name)
+ throws NameNotFoundException, NamingException {
+ if (isURLRequest(name)) {
+ // attempt to find a URL Context Factory to satisfy this request
+ ObjectFactory objectFactory = null;
+ try {
+ // obtain URL Context Factory in a doPrivilieged() block
+ objectFactory = (ObjectFactory)SecurityUtils.invokePrivilegedAction(new GetObjectFactoryAction(m_factoryManager, name));
+ } catch (Exception e) {
+ logger.log(Level.FINE,
+ "Exception occurred while trying to obtain a reference to a URL Context Factory.",
+ e);
+ }
+
+ if (objectFactory == null) {
+ throw new NameNotFoundException(
+ "Name: "
+ + name
+ + " was not found. A URL Context Factory was not registered to handle "
+ + "this URL scheme");
+ }
+
+ try {
+ Context context =
+ (Context) objectFactory.getObjectInstance(null, null,
+ null, m_context.getEnvironment());
+ if (context != null) {
+ return context;
+ }
+ else {
+ throw new NamingException("Name = " + name
+ + "was not found using the URL Context factory = " + objectFactory);
+ }
+ }
+ catch (Exception e) {
+ if (e instanceof NamingException) {
+ // re-throw naming exceptions
+ throw (NamingException) e;
+ }
+
+ NamingException namingException =
+ new NameNotFoundException("Exception occurred during URL Context Factory Resolution for name = "
+ + name);
+ namingException.initCause(e);
+ throw namingException;
+ }
+ }
+ else {
+ // treat this lookup as a normal lookup
+ return m_context;
+ }
+ }
+
+ private static class GetObjectFactoryAction implements PrivilegedExceptionAction {
+ private final FactoryManager m_factoryManager;
+ private final String m_name;
+
+ GetObjectFactoryAction(FactoryManager factoryManager, String name) {
+ m_factoryManager = factoryManager;
+ m_name = name;
+ }
+
+ public Object run() throws Exception {
+ return obtainObjectFactory(m_name);
+ }
+
+ private ObjectFactory obtainObjectFactory(String name) {
+ ObjectFactory objectFactory;
+ synchronized (m_factoryManager) {
+ objectFactory = m_factoryManager.getURLContextFactory(getScheme(name));
+ }
+ return objectFactory;
+ }
+ }
+}
diff --git a/integration-testing/pom.xml b/integration-testing/pom.xml
index 53ac7c7..fd5a9f2 100644
--- a/integration-testing/pom.xml
+++ b/integration-testing/pom.xml
@@ -6,7 +6,7 @@
<parent>
<groupId>org.eclipse.gemini.naming</groupId>
<artifactId>org.eclipse.gemini.naming.parent</artifactId>
- <version>1.0.0-SNAPSHOT</version>
+ <version>1.0.0.RC1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
diff --git a/integration-testing/src/test/java/org/eclipse/gemini/naming/test/FactoryResolutionTestCase.java b/integration-testing/src/test/java/org/eclipse/gemini/naming/test/FactoryResolutionTestCase.java
index 457de82..05253bb 100644
--- a/integration-testing/src/test/java/org/eclipse/gemini/naming/test/FactoryResolutionTestCase.java
+++ b/integration-testing/src/test/java/org/eclipse/gemini/naming/test/FactoryResolutionTestCase.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 Oracle.
+ * Copyright (c) 2012 Oracle.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Apache License v2.0 which accompanies this distribution.
@@ -19,16 +19,25 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.lang.management.ManagementFactory;
import java.net.ConnectException;
+import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler;
+import java.rmi.RemoteException;
+import java.rmi.registry.LocateRegistry;
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.Hashtable;
+import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
+import javax.management.MBeanServer;
+import javax.management.remote.JMXConnectorServer;
+import javax.management.remote.JMXConnectorServerFactory;
+import javax.management.remote.JMXServiceURL;
import javax.naming.CommunicationException;
import javax.naming.Context;
import javax.naming.InitialContext;
@@ -383,6 +392,52 @@ public class FactoryResolutionTestCase extends NamingTestCase {
sysProperties.remove(Context.INITIAL_CONTEXT_FACTORY);
}
}
+
+ /**
+ * Verify that RMI URL Context Factory can be used by default.
+ */
+ public void testRMIURLContextFactory() throws Exception {
+ MBeanServer theMBeanServer = ManagementFactory.getPlatformMBeanServer();
+ // Create the RMI registry
+ try {
+ LocateRegistry.createRegistry(1515);
+ } catch (RemoteException e) {
+ fail("Can't create registry: " + e.toString());
+ }
+
+ // Build the connection string with fixed ports
+ StringBuilder url = new StringBuilder();
+ url.append("service:jmx:rmi://localhost:");
+ url.append(1516);
+ url.append("/jndi/rmi://localhost:");
+ url.append(1515);
+ url.append("/jmxrmi");
+
+ JMXServiceURL serviceUrl = null;
+ try {
+ serviceUrl = new JMXServiceURL(url.toString());
+ } catch (MalformedURLException e) {
+ fail("Can't create registry: " + e.toString());
+ }
+
+ Map<String, Object> env = new HashMap<String, Object>();
+ ClassLoader currentTCCL = Thread.currentThread().getContextClassLoader();
+ JMXConnectorServer cs = null;
+ try {
+ Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+ cs = JMXConnectorServerFactory.newJMXConnectorServer(serviceUrl, env, theMBeanServer);
+ cs.start();
+ System.out.println("Start MBean JMX registry with ports: registry=" + 1515 + ", server=" + 1516);
+ assertTrue(cs.isActive());
+ } catch (IOException e) {
+ fail("Can't create registry: " + e.toString());
+ } finally {
+ Thread.currentThread().setContextClassLoader(currentTCCL);
+ if (cs != null) {
+ cs.stop();
+ }
+ }
+ }
// Stub implementations of JNDI factories used for simpler unit testing
static class TestContextFactoryBuilder implements InitialContextFactoryBuilder {
diff --git a/integration-testing/src/test/java/org/eclipse/gemini/naming/test/NamingTestCase.java b/integration-testing/src/test/java/org/eclipse/gemini/naming/test/NamingTestCase.java
index e0d17c6..b718edb 100644
--- a/integration-testing/src/test/java/org/eclipse/gemini/naming/test/NamingTestCase.java
+++ b/integration-testing/src/test/java/org/eclipse/gemini/naming/test/NamingTestCase.java
@@ -33,7 +33,7 @@ import org.springframework.osgi.test.AbstractConfigurableBundleCreatorTests;
public abstract class NamingTestCase extends AbstractConfigurableBundleCreatorTests {
- private static String VERSION = "1.0.0-SNAPSHOT";
+ private static String VERSION = "1.0.0.RC1";
private Map m_mapOfServicesToRegistrations =
new HashMap();
diff --git a/org.eclipse.gemini.naming.feature/feature.xml b/org.eclipse.gemini.naming.feature/feature.xml
index ca3ae71..4463a96 100644
--- a/org.eclipse.gemini.naming.feature/feature.xml
+++ b/org.eclipse.gemini.naming.feature/feature.xml
@@ -2,7 +2,7 @@
<feature
id="org.eclipse.gemini.naming.feature"
label="%featureName"
- version="1.0.0.qualifier"
+ version="1.0.0.RC1"
provider-name="%providerName"
image="eclipse_update_120.jpg">
diff --git a/org.eclipse.gemini.naming.feature/pom.xml b/org.eclipse.gemini.naming.feature/pom.xml
index ee90e17..9606e28 100644
--- a/org.eclipse.gemini.naming.feature/pom.xml
+++ b/org.eclipse.gemini.naming.feature/pom.xml
@@ -4,7 +4,7 @@
<parent>
<groupId>org.eclipse.gemini.naming</groupId>
<artifactId>org.eclipse.gemini.naming.parent</artifactId>
- <version>1.0.0-SNAPSHOT</version>
+ <version>1.0.0.RC1</version>
</parent>
<artifactId>org.eclipse.gemini.naming.feature</artifactId>
diff --git a/org.eclipse.gemini.naming.repository/category.xml b/org.eclipse.gemini.naming.repository/category.xml
index d7f65b0..6ad7014 100644
--- a/org.eclipse.gemini.naming.repository/category.xml
+++ b/org.eclipse.gemini.naming.repository/category.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<site>
- <feature url="features/org.eclipse.gemini.naming.feature_1.0.0.qualifier.jar" id="org.eclipse.gemini.naming.feature" version="1.0.0.qualifier">
+ <feature url="features/org.eclipse.gemini.naming.feature_1.0.0.RC1.jar" id="org.eclipse.gemini.naming.feature" version="1.0.0.RC1">
<category name="gemini.naming"/>
</feature>
<category-def name="gemini.naming" label="Gemini Naming"/>
diff --git a/org.eclipse.gemini.naming.repository/pom.xml b/org.eclipse.gemini.naming.repository/pom.xml
index 4dd2f24..3085f45 100644
--- a/org.eclipse.gemini.naming.repository/pom.xml
+++ b/org.eclipse.gemini.naming.repository/pom.xml
@@ -4,7 +4,7 @@
<parent>
<groupId>org.eclipse.gemini.naming</groupId>
<artifactId>org.eclipse.gemini.naming.parent</artifactId>
- <version>1.0.0-SNAPSHOT</version>
+ <version>1.0.0.RC1</version>
</parent>
<artifactId>org.eclipse.gemini.naming.repository</artifactId>
diff --git a/org.eclipse.gemini.naming.target/pom.xml b/org.eclipse.gemini.naming.target/pom.xml
index 44b0770..e72bc03 100644
--- a/org.eclipse.gemini.naming.target/pom.xml
+++ b/org.eclipse.gemini.naming.target/pom.xml
@@ -5,7 +5,7 @@
<parent>
<groupId>org.eclipse.gemini.naming</groupId>
<artifactId>org.eclipse.gemini.naming.parent</artifactId>
- <version>1.0.0-SNAPSHOT</version>
+ <version>1.0.0.RC1</version>
</parent>
<artifactId>target-platform</artifactId>
diff --git a/org.eclipse.gemini.naming.utests/pom.xml b/org.eclipse.gemini.naming.utests/pom.xml
index 19b77a8..dbd6f01 100644
--- a/org.eclipse.gemini.naming.utests/pom.xml
+++ b/org.eclipse.gemini.naming.utests/pom.xml
@@ -4,7 +4,7 @@
<parent>
<groupId>org.eclipse.gemini.naming</groupId>
<artifactId>org.eclipse.gemini.naming.parent</artifactId>
- <version>1.0.0-SNAPSHOT</version>
+ <version>1.0.0.RC1</version>
</parent>
<artifactId>org.eclipse.gemini.naming.utests</artifactId>
diff --git a/org.eclipse.gemini.naming.utests/src/test/java/org/eclipse/gemini/naming/ActivatorTestCase.java b/org.eclipse.gemini.naming.utests/src/test/java/org/eclipse/gemini/naming/ActivatorTestCase.java
index 4f1c6fd..9bc20d9 100644
--- a/org.eclipse.gemini.naming.utests/src/test/java/org/eclipse/gemini/naming/ActivatorTestCase.java
+++ b/org.eclipse.gemini.naming.utests/src/test/java/org/eclipse/gemini/naming/ActivatorTestCase.java
@@ -1,255 +1,261 @@
-/*******************************************************************************
- * Copyright (c) 2010 Oracle.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * and Apache License v2.0 which accompanies this distribution.
- * The Eclipse Public License is available at
- * http://www.eclipse.org/legal/epl-v10.html
- * and the Apache License v2.0 is available at
- * http://www.opensource.org/licenses/apache2.0.php.
- * You may elect to redistribute this code under either of these licenses.
- *
- * Contributors:
- * Bob Nettleton (Oracle) - Initial Reference Implementation Unit Tests
- ******************************************************************************/
-
-package org.eclipse.gemini.naming;
-
-import java.lang.reflect.Field;
-import java.util.Dictionary;
-import java.util.Hashtable;
-
-import javax.naming.NamingException;
-import javax.naming.spi.DirObjectFactory;
-import javax.naming.spi.InitialContextFactory;
-import javax.naming.spi.InitialContextFactoryBuilder;
-import javax.naming.spi.NamingManager;
-import javax.naming.spi.ObjectFactory;
-import javax.naming.spi.ObjectFactoryBuilder;
-
-import org.easymock.EasyMockSupport;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Filter;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceListener;
-import org.osgi.framework.ServiceReference;
-import org.osgi.framework.ServiceRegistration;
-import org.osgi.service.jndi.JNDIConstants;
-import org.osgi.service.jndi.JNDIContextManager;
-import org.osgi.service.jndi.JNDIProviderAdmin;
-
-import static org.easymock.EasyMock.*;
-
-import junit.framework.TestCase;
-
-public class ActivatorTestCase extends TestCase {
-
- public void setUp() {
- setNamingManagerStaticFieldToNull("initctx_factory_builder");
- setNamingManagerStaticFieldToNull("object_factory_builder");
- }
-
- public void tearDown() {
- setNamingManagerStaticFieldToNull("initctx_factory_builder");
- setNamingManagerStaticFieldToNull("object_factory_builder");
- }
-
-
- /**
- * Verify the basic startup of the Gemini Naming Activator.
- *
- * This test method verifies that all the expected services are
- * registered using the correct interface, actual type, and service
- * properties.
- */
- public void testStart() throws Exception {
- EasyMockSupport mockSupport = new EasyMockSupport();
- BundleContext bundleContextMock =
- mockSupport.createMock(BundleContext.class);
-
- setupBundleContextMock(mockSupport, bundleContextMock);
- // expect OSGi URLContextFactory
- Hashtable<String, Object> serviceProperties = new Hashtable<String, Object>();
- serviceProperties.put(JNDIConstants.JNDI_URLSCHEME, "osgi");
- setServiceRegistrationExpectation(mockSupport, bundleContextMock,
- ObjectFactory.class.getName(),
- OSGiURLContextFactoryServiceFactory.class,
- serviceProperties);
-
- // expect the "default" InitialContextFactoryBuilder
- setServiceRegistrationExpectation(mockSupport, bundleContextMock,
- InitialContextFactoryBuilder.class.getName(),
- DefaultRuntimeInitialContextFactoryBuilder.class,
- null);
-
- // expect the JNDIContextManager service registration
- setServiceRegistrationExpectation(mockSupport, bundleContextMock,
- JNDIContextManager.class.getName(),
- ContextManagerServiceFactoryImpl.class,
- null);
- // expect the JNDIProviderAdmin service registration
- setServiceRegistrationExpectation(mockSupport, bundleContextMock,
- JNDIProviderAdmin.class.getName(),
- SecurityAwareProviderAdminImpl.class,
- null);
-
-
- mockSupport.replayAll();
-
- // begin test
- Activator activator = new Activator();
- activator.start(bundleContextMock);
-
- // verify that the static singletons are set as expected
- assertTrue("Activator did not set the InitialContextFactoryBuilder singleton correctly",
- getPrivateStaticField(NamingManager.class, "initctx_factory_builder") instanceof TraditionalInitialContextFactoryBuilder);
- assertTrue("Activator did not set the ObjectFactoryBuilder singleton correctly",
- getPrivateStaticField(NamingManager.class, "object_factory_builder") instanceof TraditionalObjectFactoryBuilder);
-
- // stop() should complete without any exceptions
- activator.stop(bundleContextMock);
-
- mockSupport.verifyAll();
- }
-
- public void testRegistrationOfContextBuilderError() throws Exception {
- // setup test mocks
- EasyMockSupport mockSupport = new EasyMockSupport();
- InitialContextFactoryBuilder builderMock =
- mockSupport.createMock(InitialContextFactoryBuilder.class);
- if(!NamingManager.hasInitialContextFactoryBuilder()) {
- NamingManager.setInitialContextFactoryBuilder(builderMock);
- }
-
- BundleContext bundleContextMock =
- mockSupport.createMock(BundleContext.class);
- mockSupport.replayAll();
-
- // begin test
- Activator activator = new Activator();
- try {
- activator.start(bundleContextMock);
- fail("NamingException should have been thrown");
- } catch (NamingException namingException) {
- // expected exception
- }
-
- mockSupport.verifyAll();
-
- }
-
-
- public void testRegistrationOfObjectFactoryBuilderError() throws Exception {
- // setup test mocks
- EasyMockSupport mockSupport = new EasyMockSupport();
- ObjectFactoryBuilder builderMock =
- mockSupport.createMock(ObjectFactoryBuilder.class);
-
- try {
- // try to set builder, to guarantee
- // that Activator's attempt to set this will fail
- NamingManager.setObjectFactoryBuilder(builderMock);
- } catch (Throwable throwable) {
- // if already set, test can continue
- }
-
- BundleContext bundleContextMock =
- mockSupport.createMock(BundleContext.class);
- mockSupport.replayAll();
-
- // begin test
- Activator activator = new Activator();
- try {
- activator.start(bundleContextMock);
- fail("NamingException should have been thrown");
- } catch (NamingException namingException) {
- // expected exception
- }
-
- mockSupport.verifyAll();
-
- }
-
- /* test utility methods/classes */
-
- private static void setupBundleContextMock(EasyMockSupport mockSupport, BundleContext bundleContextMock) throws InvalidSyntaxException {
- Filter filterMock =
- mockSupport.createMock(Filter.class);
- expect(bundleContextMock.createFilter("(objectClass=" + InitialContextFactory.class.getName() + ")")).andReturn(filterMock);
- expect(bundleContextMock.createFilter("(objectClass=" + InitialContextFactoryBuilder.class.getName() + ")")).andReturn(filterMock);
- expect(bundleContextMock.createFilter("(objectClass=" + ObjectFactory.class.getName() + ")")).andReturn(filterMock).anyTimes();
- expect(bundleContextMock.createFilter("(objectClass=" + DirObjectFactory.class.getName() + ")")).andReturn(filterMock);
- expect(bundleContextMock.createFilter("(objectClass=" + ObjectFactoryBuilder.class.getName() + ")")).andReturn(filterMock);
-
- bundleContextMock.addServiceListener(isA(ServiceListener.class), isA(String.class));
- expectLastCall().anyTimes();
-
- bundleContextMock.removeServiceListener(isA(ServiceListener.class));
- expectLastCall().anyTimes();
-
- expect(bundleContextMock.getServiceReferences(isA(String.class), isA(String.class))).andReturn(new ServiceReference[0]).anyTimes();
- expect(bundleContextMock.getServiceReferences(isA(String.class), (String)isNull())).andReturn(new ServiceReference[0]).anyTimes();
- }
-
- private static <T> void setServiceRegistrationExpectation(EasyMockSupport mockSupport, BundleContext bundleContextMock, String serviceName, Class<T> serviceType, Dictionary<String, Object> serviceProperties) {
- ServiceRegistration serviceRegistrationMock =
- mockSupport.createMock(ServiceRegistration.class);
- // required for stop() method
- serviceRegistrationMock.unregister();
- if(serviceProperties != null) {
- expect(bundleContextMock.registerService(eq(serviceName),
- isA(serviceType), eq(serviceProperties))).andReturn(serviceRegistrationMock);
- } else {
- expect(bundleContextMock.registerService(eq(serviceName),
- isA(serviceType), (Dictionary)isNull())).andReturn(serviceRegistrationMock);
- }
-
- }
-
- /**
- * This method should be used only for unit testing the Gemini Naming Activator.
- *
- * This method sets the static singleton fields on the NamingManger class to null. This facilitates
- * simpler unit-testing of the Activator, which attempts to set these singletons. The NamingManager usually
- * throws and Exception on the set() methods for these singletons after they've been set once.
- *
- * This utility method is meant to make unit testing simpler, but should not be used in production code.
- *
- * This utility method will probably not work properly if a security manager is enabled.
- *
- * @param fieldName the name of the static field to set to null.
- */
- private static void setNamingManagerStaticFieldToNull(String fieldName) {
- try {
- final Field field = NamingManager.class.getDeclaredField(fieldName);
- if(field != null) {
- field.setAccessible(true);
- // reset this static field to null
- field.set(null, null);
- }
- } catch (Throwable throwable) {
- throwable.printStackTrace();
- }
- }
-
- /*
- * Utility method used to access the private static singletons on the NamingManager class.
- *
- * This method should only be used for unit-testing the Gemini Naming code.
- *
- * This utility method will probably not work properly if a security manager is enabled.
- *
- * @param type the Class type that contains the field
- * @param fieldName a String name that identifies the field
- */
- private static Object getPrivateStaticField(Class type, String fieldName) throws Exception {
- Field field = type.getDeclaredField(fieldName);
- if(field != null) {
- field.setAccessible(true);
- return field.get(null);
- }
-
- return null;
- }
-
-}
+/*******************************************************************************
+ * Copyright (c) 2010 Oracle.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and Apache License v2.0 which accompanies this distribution.
+ * The Eclipse Public License is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * and the Apache License v2.0 is available at
+ * http://www.opensource.org/licenses/apache2.0.php.
+ * You may elect to redistribute this code under either of these licenses.
+ *
+ * Contributors:
+ * Bob Nettleton (Oracle) - Initial Reference Implementation Unit Tests
+ ******************************************************************************/
+
+package org.eclipse.gemini.naming;
+
+import java.lang.reflect.Field;
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import javax.naming.NamingException;
+import javax.naming.spi.DirObjectFactory;
+import javax.naming.spi.InitialContextFactory;
+import javax.naming.spi.InitialContextFactoryBuilder;
+import javax.naming.spi.NamingManager;
+import javax.naming.spi.ObjectFactory;
+import javax.naming.spi.ObjectFactoryBuilder;
+
+import org.easymock.EasyMockSupport;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Filter;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceListener;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.jndi.JNDIConstants;
+import org.osgi.service.jndi.JNDIContextManager;
+import org.osgi.service.jndi.JNDIProviderAdmin;
+
+import static org.easymock.EasyMock.*;
+
+import junit.framework.TestCase;
+
+public class ActivatorTestCase extends TestCase {
+
+ public void setUp() {
+ setNamingManagerStaticFieldToNull("initctx_factory_builder");
+ setNamingManagerStaticFieldToNull("object_factory_builder");
+ }
+
+ public void tearDown() {
+ setNamingManagerStaticFieldToNull("initctx_factory_builder");
+ setNamingManagerStaticFieldToNull("object_factory_builder");
+ }
+
+
+ /**
+ * Verify the basic startup of the Gemini Naming Activator.
+ *
+ * This test method verifies that all the expected services are
+ * registered using the correct interface, actual type, and service
+ * properties.
+ */
+ public void testStart() throws Exception {
+ EasyMockSupport mockSupport = new EasyMockSupport();
+ BundleContext bundleContextMock =
+ mockSupport.createMock(BundleContext.class);
+
+ setupBundleContextMock(mockSupport, bundleContextMock);
+ // expect OSGi URLContextFactory
+ Hashtable<String, Object> serviceProperties = new Hashtable<String, Object>();
+ serviceProperties.put(JNDIConstants.JNDI_URLSCHEME, "osgi");
+ setServiceRegistrationExpectation(mockSupport, bundleContextMock,
+ ObjectFactory.class.getName(),
+ OSGiURLContextFactoryServiceFactory.class,
+ serviceProperties);
+
+ // expect the "default" InitialContextFactoryBuilder
+ setServiceRegistrationExpectation(mockSupport, bundleContextMock,
+ InitialContextFactoryBuilder.class.getName(),
+ DefaultRuntimeInitialContextFactoryBuilder.class,
+ null);
+
+ // expect the JNDIContextManager service registration
+ setServiceRegistrationExpectation(mockSupport, bundleContextMock,
+ JNDIContextManager.class.getName(),
+ ContextManagerServiceFactoryImpl.class,
+ null);
+ // expect the JNDIProviderAdmin service registration
+ setServiceRegistrationExpectation(mockSupport, bundleContextMock,
+ JNDIProviderAdmin.class.getName(),
+ SecurityAwareProviderAdminImpl.class,
+ null);
+ // expect the rmiURLContextFactory service registration
+ Hashtable<String, Object> props = new Hashtable<String, Object>();
+ props.put(JNDIConstants.JNDI_URLSCHEME, "rmi");
+ setServiceRegistrationExpectation(mockSupport, bundleContextMock,
+ ObjectFactory.class.getName(),
+ ClassLoader.getSystemClassLoader().loadClass("com.sun.jndi.url.rmi.rmiURLContextFactory"),
+ props);
+
+ mockSupport.replayAll();
+
+ // begin test
+ Activator activator = new Activator();
+ activator.start(bundleContextMock);
+
+ // verify that the static singletons are set as expected
+ assertTrue("Activator did not set the InitialContextFactoryBuilder singleton correctly",
+ getPrivateStaticField(NamingManager.class, "initctx_factory_builder") instanceof TraditionalInitialContextFactoryBuilder);
+ assertTrue("Activator did not set the ObjectFactoryBuilder singleton correctly",
+ getPrivateStaticField(NamingManager.class, "object_factory_builder") instanceof TraditionalObjectFactoryBuilder);
+
+ // stop() should complete without any exceptions
+ activator.stop(bundleContextMock);
+
+ mockSupport.verifyAll();
+ }
+
+ public void testRegistrationOfContextBuilderError() throws Exception {
+ // setup test mocks
+ EasyMockSupport mockSupport = new EasyMockSupport();
+ InitialContextFactoryBuilder builderMock =
+ mockSupport.createMock(InitialContextFactoryBuilder.class);
+ if(!NamingManager.hasInitialContextFactoryBuilder()) {
+ NamingManager.setInitialContextFactoryBuilder(builderMock);
+ }
+
+ BundleContext bundleContextMock =
+ mockSupport.createMock(BundleContext.class);
+ mockSupport.replayAll();
+
+ // begin test
+ Activator activator = new Activator();
+ try {
+ activator.start(bundleContextMock);
+ fail("NamingException should have been thrown");
+ } catch (NamingException namingException) {
+ // expected exception
+ }
+
+ mockSupport.verifyAll();
+
+ }
+
+
+ public void testRegistrationOfObjectFactoryBuilderError() throws Exception {
+ // setup test mocks
+ EasyMockSupport mockSupport = new EasyMockSupport();
+ ObjectFactoryBuilder builderMock =
+ mockSupport.createMock(ObjectFactoryBuilder.class);
+
+ try {
+ // try to set builder, to guarantee
+ // that Activator's attempt to set this will fail
+ NamingManager.setObjectFactoryBuilder(builderMock);
+ } catch (Throwable throwable) {
+ // if already set, test can continue
+ }
+
+ BundleContext bundleContextMock =
+ mockSupport.createMock(BundleContext.class);
+ mockSupport.replayAll();
+
+ // begin test
+ Activator activator = new Activator();
+ try {
+ activator.start(bundleContextMock);
+ fail("NamingException should have been thrown");
+ } catch (NamingException namingException) {
+ // expected exception
+ }
+
+ mockSupport.verifyAll();
+
+ }
+
+ /* test utility methods/classes */
+
+ private static void setupBundleContextMock(EasyMockSupport mockSupport, BundleContext bundleContextMock) throws InvalidSyntaxException {
+ Filter filterMock =
+ mockSupport.createMock(Filter.class);
+ expect(bundleContextMock.createFilter("(objectClass=" + InitialContextFactory.class.getName() + ")")).andReturn(filterMock);
+ expect(bundleContextMock.createFilter("(objectClass=" + InitialContextFactoryBuilder.class.getName() + ")")).andReturn(filterMock);
+ expect(bundleContextMock.createFilter("(objectClass=" + ObjectFactory.class.getName() + ")")).andReturn(filterMock).anyTimes();
+ expect(bundleContextMock.createFilter("(objectClass=" + DirObjectFactory.class.getName() + ")")).andReturn(filterMock);
+ expect(bundleContextMock.createFilter("(objectClass=" + ObjectFactoryBuilder.class.getName() + ")")).andReturn(filterMock);
+
+ bundleContextMock.addServiceListener(isA(ServiceListener.class), isA(String.class));
+ expectLastCall().anyTimes();
+
+ bundleContextMock.removeServiceListener(isA(ServiceListener.class));
+ expectLastCall().anyTimes();
+
+ expect(bundleContextMock.getServiceReferences(isA(String.class), isA(String.class))).andReturn(new ServiceReference[0]).anyTimes();
+ expect(bundleContextMock.getServiceReferences(isA(String.class), (String)isNull())).andReturn(new ServiceReference[0]).anyTimes();
+ }
+
+ private static <T> void setServiceRegistrationExpectation(EasyMockSupport mockSupport, BundleContext bundleContextMock, String serviceName, Class<T> serviceType, Dictionary<String, Object> serviceProperties) {
+ ServiceRegistration serviceRegistrationMock =
+ mockSupport.createMock(ServiceRegistration.class);
+ // required for stop() method
+ serviceRegistrationMock.unregister();
+ if(serviceProperties != null) {
+ expect(bundleContextMock.registerService(eq(serviceName),
+ isA(serviceType), eq(serviceProperties))).andReturn(serviceRegistrationMock);
+ } else {
+ expect(bundleContextMock.registerService(eq(serviceName),
+ isA(serviceType), (Dictionary)isNull())).andReturn(serviceRegistrationMock);
+ }
+
+ }
+
+ /**
+ * This method should be used only for unit testing the Gemini Naming Activator.
+ *
+ * This method sets the static singleton fields on the NamingManger class to null. This facilitates
+ * simpler unit-testing of the Activator, which attempts to set these singletons. The NamingManager usually
+ * throws and Exception on the set() methods for these singletons after they've been set once.
+ *
+ * This utility method is meant to make unit testing simpler, but should not be used in production code.
+ *
+ * This utility method will probably not work properly if a security manager is enabled.
+ *
+ * @param fieldName the name of the static field to set to null.
+ */
+ private static void setNamingManagerStaticFieldToNull(String fieldName) {
+ try {
+ final Field field = NamingManager.class.getDeclaredField(fieldName);
+ if(field != null) {
+ field.setAccessible(true);
+ // reset this static field to null
+ field.set(null, null);
+ }
+ } catch (Throwable throwable) {
+ throwable.printStackTrace();
+ }
+ }
+
+ /*
+ * Utility method used to access the private static singletons on the NamingManager class.
+ *
+ * This method should only be used for unit-testing the Gemini Naming code.
+ *
+ * This utility method will probably not work properly if a security manager is enabled.
+ *
+ * @param type the Class type that contains the field
+ * @param fieldName a String name that identifies the field
+ */
+ private static Object getPrivateStaticField(Class type, String fieldName) throws Exception {
+ Field field = type.getDeclaredField(fieldName);
+ if(field != null) {
+ field.setAccessible(true);
+ return field.get(null);
+ }
+
+ return null;
+ }
+
+}
diff --git a/pom.xml b/pom.xml
index 8ff0d20..3b1d66b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -13,7 +13,7 @@
<groupId>org.eclipse.gemini.naming</groupId>
<artifactId>org.eclipse.gemini.naming.parent</artifactId>
<packaging>pom</packaging>
- <version>1.0.0-SNAPSHOT</version>
+ <version>1.0.0.RC1</version>
<name>Gemini Naming parent project</name>
<url>http://maven.apache.org</url>

Back to the top