[jboss-osgi-commits] JBoss-OSGI SVN: r88194 - in projects/jboss-osgi/trunk/bundle: blueprint/.settings and 11 other directories.

jboss-osgi-commits at lists.jboss.org jboss-osgi-commits at lists.jboss.org
Tue May 5 02:51:44 EDT 2009


Author: thomas.diesler at jboss.com
Date: 2009-05-05 02:51:43 -0400 (Tue, 05 May 2009)
New Revision: 88194

Added:
   projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/jndi/
   projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/jndi/JNDITestCase.java
   projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/jndi/bundle/
   projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/jndi/bundle/ServiceActivator.java
   projects/jboss-osgi/trunk/bundle/blueprint/src/test/resources/jndi/
   projects/jboss-osgi/trunk/bundle/blueprint/src/test/resources/jndi/jndi-test.bnd
   projects/jboss-osgi/trunk/bundle/jndi/src/main/java/org/jboss/osgi/jndi/NamingService.java
   projects/jboss-osgi/trunk/bundle/jndi/src/main/java/org/jboss/osgi/jndi/internal/NamingServiceImpl.java
   projects/jboss-osgi/trunk/bundle/jndi/src/main/java/org/jboss/osgi/jndi/internal/ServiceActivator.java
   projects/jboss-osgi/trunk/bundle/jndi/src/main/resources/
   projects/jboss-osgi/trunk/bundle/jndi/src/main/resources/jnp.properties
Removed:
   projects/jboss-osgi/trunk/bundle/jndi/src/main/java/org/jboss/osgi/jndi/ServiceActivator.java
Modified:
   projects/jboss-osgi/trunk/bundle/blueprint/.classpath
   projects/jboss-osgi/trunk/bundle/blueprint/.project
   projects/jboss-osgi/trunk/bundle/blueprint/.settings/org.maven.ide.eclipse.prefs
   projects/jboss-osgi/trunk/bundle/blueprint/scripts/antrun-test-jars.xml
   projects/jboss-osgi/trunk/bundle/jndi/pom.xml
   projects/jboss-osgi/trunk/bundle/jndi/src/main/java/org/jboss/osgi/jndi/internal/JNPServer.java
Log:
Add a JNDI bundle test

Modified: projects/jboss-osgi/trunk/bundle/blueprint/.classpath
===================================================================
--- projects/jboss-osgi/trunk/bundle/blueprint/.classpath	2009-05-05 06:29:39 UTC (rev 88193)
+++ projects/jboss-osgi/trunk/bundle/blueprint/.classpath	2009-05-05 06:51:43 UTC (rev 88194)
@@ -2,6 +2,7 @@
 <classpath>
 	<classpathentry kind="src" output="target/classes" path="src/main/java"/>
 	<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
+	<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
 	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
 	<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
 	<classpathentry kind="output" path="target/classes"/>

Modified: projects/jboss-osgi/trunk/bundle/blueprint/.project
===================================================================
--- projects/jboss-osgi/trunk/bundle/blueprint/.project	2009-05-05 06:29:39 UTC (rev 88193)
+++ projects/jboss-osgi/trunk/bundle/blueprint/.project	2009-05-05 06:51:43 UTC (rev 88194)
@@ -17,7 +17,7 @@
 		</buildCommand>
 	</buildSpec>
 	<natures>
+		<nature>org.maven.ide.eclipse.maven2Nature</nature>
 		<nature>org.eclipse.jdt.core.javanature</nature>
-		<nature>org.maven.ide.eclipse.maven2Nature</nature>
 	</natures>
 </projectDescription>

Modified: projects/jboss-osgi/trunk/bundle/blueprint/.settings/org.maven.ide.eclipse.prefs
===================================================================
--- projects/jboss-osgi/trunk/bundle/blueprint/.settings/org.maven.ide.eclipse.prefs	2009-05-05 06:29:39 UTC (rev 88193)
+++ projects/jboss-osgi/trunk/bundle/blueprint/.settings/org.maven.ide.eclipse.prefs	2009-05-05 06:51:43 UTC (rev 88194)
@@ -1,4 +1,4 @@
-#Tue Apr 14 17:48:48 CEST 2009
+#Tue May 05 08:38:16 CEST 2009
 activeProfiles=
 eclipse.preferences.version=1
 fullBuildGoals=process-test-resources

Modified: projects/jboss-osgi/trunk/bundle/blueprint/scripts/antrun-test-jars.xml
===================================================================
--- projects/jboss-osgi/trunk/bundle/blueprint/scripts/antrun-test-jars.xml	2009-05-05 06:29:39 UTC (rev 88193)
+++ projects/jboss-osgi/trunk/bundle/blueprint/scripts/antrun-test-jars.xml	2009-05-05 06:51:43 UTC (rev 88194)
@@ -46,6 +46,9 @@
     <!-- jmx -->
     <bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/jmx-test.jar" files="${tests.resources.dir}/jmx/jmx-test.bnd" />
 
+    <!-- jndi -->
+    <bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/jndi-test.jar" files="${tests.resources.dir}/jndi/jndi-test.bnd" />
+
     <!-- mcservice -->
     <bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/mcservice-bundleA.jar" files="${tests.resources.dir}/mcservice/mcservice-bundleA.bnd" />
     <bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/mcservice-bundleB.jar" files="${tests.resources.dir}/mcservice/mcservice-bundleB.bnd" />

Added: projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/jndi/JNDITestCase.java
===================================================================
--- projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/jndi/JNDITestCase.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/jndi/JNDITestCase.java	2009-05-05 06:51:43 UTC (rev 88194)
@@ -0,0 +1,74 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.osgi.blueprint.jndi;
+
+//$Id$
+
+import javax.naming.InitialContext;
+import javax.naming.NameNotFoundException;
+
+import org.jboss.osgi.spi.framework.OSGiFramework;
+import org.jboss.test.osgi.blueprint.BlueprintTest;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+
+/**
+ * A test that deployes a bundle that binds a String to JNDI
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 05-May-2009
+ */
+public class JNDITestCase extends BlueprintTest
+{
+   public void testJNDIAccess() throws Exception
+   {
+      OSGiFramework framework = getBootstrapProvider().getFramework();
+      BundleContext sysContext = framework.getSystemBundleContext();
+      
+      try
+      {
+         Bundle bundle = installBundle(sysContext, "jndi-test.jar", true);
+         assertEquals("Test bundle ACTIVE", Bundle.ACTIVE, bundle.getState());
+         
+         InitialContext iniCtx = new InitialContext();
+         String lookup = (String)iniCtx.lookup("test/Foo");
+         assertEquals("JNDI bound String expected", "Bar", lookup);
+         
+         // Uninstall should unbind the object
+         bundle.uninstall();
+         
+         try
+         {
+            iniCtx.lookup("test/Foo");
+            fail("NameNotFoundException expected");
+         }
+         catch (NameNotFoundException ex) 
+         {
+            // expected
+         }
+      }
+      finally
+      {
+         framework.stop();
+      }
+   }
+}
\ No newline at end of file


Property changes on: projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/jndi/JNDITestCase.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/jndi/bundle/ServiceActivator.java
===================================================================
--- projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/jndi/bundle/ServiceActivator.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/jndi/bundle/ServiceActivator.java	2009-05-05 06:51:43 UTC (rev 88194)
@@ -0,0 +1,79 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.osgi.blueprint.jndi.bundle;
+
+//$Id$
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import org.jboss.osgi.jndi.NamingService;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * A Service Activator
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 05-May-2009
+ */
+public class ServiceActivator implements BundleActivator
+{
+   public void start(BundleContext context)
+   {
+      NamingService service = getNamingService(context);
+      try
+      {
+         InitialContext iniCtx = service.getInitialContext();
+         iniCtx.createSubcontext("test").bind("Foo", new String("Bar"));
+      }
+      catch (NamingException ex)
+      {
+         throw new IllegalStateException("Cannot bind to JNDI", ex);
+      }
+   }
+
+   public void stop(BundleContext context)
+   {
+      NamingService service = getNamingService(context);
+      try
+      {
+         InitialContext iniCtx = service.getInitialContext();
+         iniCtx.unbind("test/Foo");
+      }
+      catch (NamingException ex)
+      {
+         throw new IllegalStateException("Cannot unbind from JNDI", ex);
+      }
+   }
+
+   private NamingService getNamingService(BundleContext context)
+   {
+      ServiceReference sref = context.getServiceReference(NamingService.class.getName());
+      if (sref == null)
+         throw new IllegalStateException("NamingService not available");
+      
+      NamingService service = (NamingService)context.getService(sref);
+      return service;
+   }
+}
\ No newline at end of file


Property changes on: projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/jndi/bundle/ServiceActivator.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: projects/jboss-osgi/trunk/bundle/blueprint/src/test/resources/jndi/jndi-test.bnd
===================================================================
--- projects/jboss-osgi/trunk/bundle/blueprint/src/test/resources/jndi/jndi-test.bnd	                        (rev 0)
+++ projects/jboss-osgi/trunk/bundle/blueprint/src/test/resources/jndi/jndi-test.bnd	2009-05-05 06:51:43 UTC (rev 88194)
@@ -0,0 +1,6 @@
+# bnd build -classpath target/test-classes -output target/test-libs/jndi-test.jar src/test/resources/jndi/jndi-test.bnd
+
+Bundle-SymbolicName: jndi-test
+Bundle-Activator: org.jboss.test.osgi.blueprint.jndi.bundle.ServiceActivator
+Export-Package: org.jboss.test.osgi.blueprint.jndi.bundle 
+Import-Package: javax.naming, org.osgi.framework, org.jboss.osgi.jndi
\ No newline at end of file

Modified: projects/jboss-osgi/trunk/bundle/jndi/pom.xml
===================================================================
--- projects/jboss-osgi/trunk/bundle/jndi/pom.xml	2009-05-05 06:29:39 UTC (rev 88193)
+++ projects/jboss-osgi/trunk/bundle/jndi/pom.xml	2009-05-05 06:51:43 UTC (rev 88194)
@@ -54,7 +54,8 @@
         <configuration>
           <instructions>
             <Bundle-SymbolicName>${artifactId}</Bundle-SymbolicName>
-            <Bundle-Activator>org.jboss.osgi.jndi.ServiceActivator</Bundle-Activator>
+            <Bundle-Activator>org.jboss.osgi.jndi.internal.ServiceActivator</Bundle-Activator>
+            <Export-Package>org.jboss.osgi.jndi</Export-Package>
             <Import-Package>
               javax.naming*, 
               javax.net, 

Added: projects/jboss-osgi/trunk/bundle/jndi/src/main/java/org/jboss/osgi/jndi/NamingService.java
===================================================================
--- projects/jboss-osgi/trunk/bundle/jndi/src/main/java/org/jboss/osgi/jndi/NamingService.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/bundle/jndi/src/main/java/org/jboss/osgi/jndi/NamingService.java	2009-05-05 06:51:43 UTC (rev 88194)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.jndi;
+
+//$Id$
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+/**
+ * A service that gives access to JNDI
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 05-May-2009
+ */
+public interface NamingService
+{
+   /**
+    * Get the InitialContext
+     * @throws NamingException if a naming exception is encountered
+    */
+   InitialContext getInitialContext() throws NamingException;
+}
\ No newline at end of file


Property changes on: projects/jboss-osgi/trunk/bundle/jndi/src/main/java/org/jboss/osgi/jndi/NamingService.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Deleted: projects/jboss-osgi/trunk/bundle/jndi/src/main/java/org/jboss/osgi/jndi/ServiceActivator.java
===================================================================
--- projects/jboss-osgi/trunk/bundle/jndi/src/main/java/org/jboss/osgi/jndi/ServiceActivator.java	2009-05-05 06:29:39 UTC (rev 88193)
+++ projects/jboss-osgi/trunk/bundle/jndi/src/main/java/org/jboss/osgi/jndi/ServiceActivator.java	2009-05-05 06:51:43 UTC (rev 88194)
@@ -1,70 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.osgi.jndi;
-
-//$Id$
-
-import org.jboss.osgi.jndi.internal.JNPServer;
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-
-/**
- * A BundleActivator for the JNDI related services
- * 
- * @author thomas.diesler at jboss.com
- * @since 24-Apr-2009
- */
-public class ServiceActivator implements BundleActivator
-{
-   public static final String REMOTE_JNDI_HOST = "org.jboss.osgi.jndi.host";
-   public static final String REMOTE_JNDI_RMI_PORT = "org.jboss.osgi.jndi.rmi.port";
-   public static final String REMOTE_JNDI_PORT = "org.jboss.osgi.jndi.port";
-
-   private JNPServer jnpServer;
-
-   public void start(BundleContext context)
-   {
-      String jndiHost = context.getProperty(REMOTE_JNDI_HOST);
-      if (jndiHost == null)
-         jndiHost = "localhost";
-
-      String jndiRmiPort = context.getProperty(REMOTE_JNDI_RMI_PORT);
-      if (jndiRmiPort == null)
-         jndiRmiPort = "1098";
-
-      String jndiPort = context.getProperty(REMOTE_JNDI_PORT);
-      if (jndiPort == null)
-         jndiPort = "1099";
-
-      jnpServer = new JNPServer(context, jndiHost, Integer.parseInt(jndiPort), Integer.parseInt(jndiRmiPort));
-      jnpServer.start();
-   }
-
-   public void stop(BundleContext context)
-   {
-      if (jnpServer != null)
-      {
-         jnpServer.stop();
-         jnpServer = null;
-      }
-   }
-}
\ No newline at end of file

Modified: projects/jboss-osgi/trunk/bundle/jndi/src/main/java/org/jboss/osgi/jndi/internal/JNPServer.java
===================================================================
--- projects/jboss-osgi/trunk/bundle/jndi/src/main/java/org/jboss/osgi/jndi/internal/JNPServer.java	2009-05-05 06:29:39 UTC (rev 88193)
+++ projects/jboss-osgi/trunk/bundle/jndi/src/main/java/org/jboss/osgi/jndi/internal/JNPServer.java	2009-05-05 06:51:43 UTC (rev 88194)
@@ -49,7 +49,7 @@
 
    public JNPServer(BundleContext context, String jndiHost, int jndiPort, int jndiRmiPort)
    {
-      log = new LogServiceTracker(context);
+      this.log = new LogServiceTracker(context);
 
       try
       {

Added: projects/jboss-osgi/trunk/bundle/jndi/src/main/java/org/jboss/osgi/jndi/internal/NamingServiceImpl.java
===================================================================
--- projects/jboss-osgi/trunk/bundle/jndi/src/main/java/org/jboss/osgi/jndi/internal/NamingServiceImpl.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/bundle/jndi/src/main/java/org/jboss/osgi/jndi/internal/NamingServiceImpl.java	2009-05-05 06:51:43 UTC (rev 88194)
@@ -0,0 +1,43 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.jndi.internal;
+
+//$Id$
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import org.jboss.osgi.jndi.NamingService;
+
+/**
+ * A Service Activator that activates the JNP Server
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 24-Apr-2009
+ */
+public class NamingServiceImpl implements NamingService
+{
+   public InitialContext getInitialContext() throws NamingException
+   {
+      return new InitialContext();
+   }
+}
\ No newline at end of file


Property changes on: projects/jboss-osgi/trunk/bundle/jndi/src/main/java/org/jboss/osgi/jndi/internal/NamingServiceImpl.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Copied: projects/jboss-osgi/trunk/bundle/jndi/src/main/java/org/jboss/osgi/jndi/internal/ServiceActivator.java (from rev 88189, projects/jboss-osgi/trunk/bundle/jndi/src/main/java/org/jboss/osgi/jndi/ServiceActivator.java)
===================================================================
--- projects/jboss-osgi/trunk/bundle/jndi/src/main/java/org/jboss/osgi/jndi/internal/ServiceActivator.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/bundle/jndi/src/main/java/org/jboss/osgi/jndi/internal/ServiceActivator.java	2009-05-05 06:51:43 UTC (rev 88194)
@@ -0,0 +1,87 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.jndi.internal;
+
+//$Id$
+
+import org.jboss.osgi.common.log.LogServiceTracker;
+import org.jboss.osgi.jndi.NamingService;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.log.LogService;
+
+/**
+ * A BundleActivator for the JNDI related services
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 24-Apr-2009
+ */
+public class ServiceActivator implements BundleActivator
+{
+   public static final String REMOTE_JNDI_HOST = "org.jboss.osgi.jndi.host";
+   public static final String REMOTE_JNDI_RMI_PORT = "org.jboss.osgi.jndi.rmi.port";
+   public static final String REMOTE_JNDI_PORT = "org.jboss.osgi.jndi.port";
+
+   private ServiceRegistration regNaming;
+   private JNPServer jnpServer;
+   private LogService log;
+
+   public void start(BundleContext context)
+   {
+      log = new LogServiceTracker(context);
+      
+      String jndiHost = context.getProperty(REMOTE_JNDI_HOST);
+      if (jndiHost == null)
+         jndiHost = "localhost";
+
+      String jndiRmiPort = context.getProperty(REMOTE_JNDI_RMI_PORT);
+      if (jndiRmiPort == null)
+         jndiRmiPort = "1098";
+
+      String jndiPort = context.getProperty(REMOTE_JNDI_PORT);
+      if (jndiPort == null)
+         jndiPort = "1099";
+
+      jnpServer = new JNPServer(context, jndiHost, Integer.parseInt(jndiPort), Integer.parseInt(jndiRmiPort));
+      jnpServer.start();
+      
+      regNaming = context.registerService(NamingService.class.getName(), new NamingServiceImpl(), null);
+      log.log(LogService.LOG_DEBUG, "NamingService registered");
+   }
+
+   public void stop(BundleContext context)
+   {
+      if (regNaming != null)
+      {
+         regNaming.unregister();
+         regNaming = null;
+         log.log(LogService.LOG_DEBUG, "NamingService unregistered");
+      }
+      
+      if (jnpServer != null)
+      {
+         jnpServer.stop();
+         jnpServer = null;
+      }
+   }
+}
\ No newline at end of file

Added: projects/jboss-osgi/trunk/bundle/jndi/src/main/resources/jnp.properties
===================================================================
--- projects/jboss-osgi/trunk/bundle/jndi/src/main/resources/jnp.properties	                        (rev 0)
+++ projects/jboss-osgi/trunk/bundle/jndi/src/main/resources/jnp.properties	2009-05-05 06:51:43 UTC (rev 88194)
@@ -0,0 +1 @@
+# Intentionally left empty
\ No newline at end of file




More information about the jboss-osgi-commits mailing list