From jboss-osgi-commits at lists.jboss.org Wed Jun 3 10:54:29 2009 Content-Type: multipart/mixed; boundary="===============6160450194527044058==" MIME-Version: 1.0 From: jboss-osgi-commits at lists.jboss.org To: jboss-osgi-commits at lists.jboss.org Subject: [jboss-osgi-commits] JBoss-OSGI SVN: r89741 - in projects/jboss-osgi/trunk: testsuite/example/src/test/java/org/jboss/test/osgi/example/http/bundle and 8 other directories. Date: Wed, 03 Jun 2009 10:44:56 -0400 Message-ID: --===============6160450194527044058== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: thomas.diesler(a)jboss.com Date: 2009-06-03 10:44:55 -0400 (Wed, 03 Jun 2009) New Revision: 89741 Added: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test= /osgi/example/http/bundle/HttpExampleActivator.java projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test= /osgi/example/jmx/bundle/JMXExampleActivator.java projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test= /osgi/example/jndi/bundle/JNDIExampleActivator.java projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test= /osgi/example/log/bundle/LogExampleActivator.java Removed: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test= /osgi/example/http/bundle/ServiceActivator.java projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test= /osgi/example/jmx/bundle/FooServiceActivator.java projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test= /osgi/example/jndi/bundle/ServiceActivator.java projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test= /osgi/example/log/bundle/LogServiceActivator.java Modified: projects/jboss-osgi/trunk/docbook/en/modules/ch080-provided-examples.xml projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test= /osgi/example/jndi/JNDITestCase.java projects/jboss-osgi/trunk/testsuite/example/src/test/resources/http/exam= ple-http.bnd projects/jboss-osgi/trunk/testsuite/example/src/test/resources/jmx/examp= le-jmx.bnd projects/jboss-osgi/trunk/testsuite/example/src/test/resources/jndi/exam= ple-jndi.bnd projects/jboss-osgi/trunk/testsuite/example/src/test/resources/log/examp= le-log.bnd Log: All chapters except Husky - ok Modified: projects/jboss-osgi/trunk/docbook/en/modules/ch080-provided-examp= les.xml =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- projects/jboss-osgi/trunk/docbook/en/modules/ch080-provided-examples.xm= l 2009-06-03 14:41:04 UTC (rev 89740) +++ projects/jboss-osgi/trunk/docbook/en/modules/ch080-provided-examples.xm= l 2009-06-03 14:44:55 UTC (rev 89741) @@ -14,7 +14,7 @@ and Hudso= n QA Environment. = The examples can be either run against an embedded OSGi runtime = or against - a remote runtime. Here is how you build and run the against the embedd= ed runtime. + a remote OSGi runtime. Here is how you build and run the against the e= mbedded runtime. = [tdiesler(a)tddell example]$ mvn test @@ -54,8 +54,9 @@ = To run the examples against a remote OSGi Runtime, you need to p= rovide the target container that the runtime should connect to. This can be done = with the = - target.container system property. = - Suported target container values are: = + target.container system property. + = + Suported target container values are: = = runtime @@ -68,19 +69,109 @@ = = Simple Example - = The simple example is covered in: Writing Test Cases - = = = JMX Service Example - TODO + + The example-jmx.jar bundle tr= acks the MBeanServer service and registers + a pojo with JMX. It then verifies the JMX access. + + = + + public class FooServiceActivator implements BundleActivator + { + public void start(BundleContext context) + { + ServiceTracker tracker =3D new ServiceTracker(context, MBeanServ= er.class.getName(), null) + { + public Object addingService(ServiceReference reference) + { + MBeanServer mbeanServer =3D (MBeanServer)super.addingServi= ce(reference); + registerMBean(mbeanServer); + return mbeanServer; + } + = + @Override + public void removedService(ServiceReference reference, Object= service) + { + unregisterMBean((MBeanServer)service); + super.removedService(reference, service); + } + }; + tracker.open(); + } + = + public void stop(BundleContext context) + { + ServiceReference sref =3D context.getServiceReference(MBeanServe= r.class.getName()); + if (sref !=3D null) + { + MBeanServer mbeanServer =3D (MBeanServer)context.getService(s= ref); + unregisterMBean(mbeanServer); + } + } + ... + } + + = + + public void testMBeanAccess() throws Exception + { + FooMBean foo =3D (FooMBean)MBeanProxy.get(FooMBean.class, MBEAN_NA= ME, runtime.getMBeanServer()); + assertEquals("hello", foo.echo("hello")); + } + + = + Please note that access to the MBeanServer from the test case is= part of the = + + OSGiRuntimeabstraction. + = = = JNDI Service Example - TODO + + The example-jndi.jar bundle g= ets the InitialContext service and registers + a string with JNDI. It then verifies the JNDI access. + + = + + ServiceReference sref =3D context.getServiceReference(InitialContext.c= lass.getName()); + if (sref =3D=3D null) + throw new IllegalStateException("Cannot access the InitialContext"); + = + InitialContext iniContext =3D (InitialContext)context.getService(sref); + iniCtx.createSubcontext("test").bind("Foo", new String("Bar")); + + = + + public void testJNDIAccess() throws Exception + { + InitialContext iniCtx =3D runtime.getInitialContext(); + String lookup =3D (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 + } + } + + = + Please note that access to the InitialContext from the test case= is part of the = + + OSGiRuntimeabstraction. + = = = Copied: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss= /test/osgi/example/http/bundle/HttpExampleActivator.java (from rev 89712, p= rojects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osg= i/example/http/bundle/ServiceActivator.java) =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/tes= t/osgi/example/http/bundle/HttpExampleActivator.java = (rev 0) +++ projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/tes= t/osgi/example/http/bundle/HttpExampleActivator.java 2009-06-03 14:44:55 UT= C (rev 89741) @@ -0,0 +1,53 @@ +/* + * 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.example.http.bundle; + +//$Id: ServiceActivator.java 87329 2009-04-15 10:34:21Z thomas.diesler(a)j= boss.com $ + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; + +/** + * A Service Activator + * = + * @author thomas.diesler(a)jboss.com + * @since 04-Feb-2009 + */ +public class HttpExampleActivator implements BundleActivator +{ + /* + * Implements BundleActivator.start(). = + * Registers an instance of a HttpEndpoint Service using the bundle cont= ext. + */ + public void start(BundleContext context) + { + EndpointService service =3D new EndpointService(context); + context.registerService(EndpointService.class.getName(), service, null= ); + } + + /* + * Implements BundleActivator.stop(). = + */ + public void stop(BundleContext context) + { + } +} \ No newline at end of file Deleted: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jbos= s/test/osgi/example/http/bundle/ServiceActivator.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/tes= t/osgi/example/http/bundle/ServiceActivator.java 2009-06-03 14:41:04 UTC (r= ev 89740) +++ projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/tes= t/osgi/example/http/bundle/ServiceActivator.java 2009-06-03 14:44:55 UTC (r= ev 89741) @@ -1,53 +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.test.osgi.example.http.bundle; - -//$Id: ServiceActivator.java 87329 2009-04-15 10:34:21Z thomas.diesler(a)j= boss.com $ - -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; - -/** - * A Service Activator - * = - * @author thomas.diesler(a)jboss.com - * @since 04-Feb-2009 - */ -public class ServiceActivator implements BundleActivator -{ - /* - * Implements BundleActivator.start(). = - * Registers an instance of a HttpEndpoint Service using the bundle cont= ext. - */ - public void start(BundleContext context) - { - EndpointService service =3D new EndpointService(context); - context.registerService(EndpointService.class.getName(), service, null= ); - } - - /* - * Implements BundleActivator.stop(). = - */ - public void stop(BundleContext context) - { - } -} \ No newline at end of file Deleted: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jbos= s/test/osgi/example/jmx/bundle/FooServiceActivator.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/tes= t/osgi/example/jmx/bundle/FooServiceActivator.java 2009-06-03 14:41:04 UTC = (rev 89740) +++ projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/tes= t/osgi/example/jmx/bundle/FooServiceActivator.java 2009-06-03 14:44:55 UTC = (rev 89741) @@ -1,99 +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.test.osgi.example.jmx.bundle; - -//$Id$ - -import static org.jboss.test.osgi.example.jmx.bundle.FooMBean.MBEAN_NAME; - -import javax.management.JMException; -import javax.management.MBeanServer; - -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; -import org.osgi.util.tracker.ServiceTracker; - -/** - * A Service Activator - * = - * @author thomas.diesler(a)jboss.com - * @since 24-Apr-2009 - */ -public class FooServiceActivator implements BundleActivator -{ - public void start(BundleContext context) - { - ServiceTracker tracker =3D new ServiceTracker(context, MBeanServer.c= lass.getName(), null) - { - public Object addingService(ServiceReference reference) - { - MBeanServer mbeanServer =3D (MBeanServer)super.addingService(r= eference); - registerMBean(mbeanServer); - return mbeanServer; - } - - @Override - public void removedService(ServiceReference reference, Object ser= vice) - { - unregisterMBean((MBeanServer)service); - super.removedService(reference, service); - } - }; - tracker.open(); - } - - public void stop(BundleContext context) - { - ServiceReference sref =3D context.getServiceReference(MBeanServer.cl= ass.getName()); - if (sref !=3D null) - { - MBeanServer mbeanServer =3D (MBeanServer)context.getService(sref); - unregisterMBean(mbeanServer); - } - } - - private void registerMBean(MBeanServer mbeanServer) - { - try - { - mbeanServer.registerMBean(new Foo(), MBEAN_NAME); - } - catch (JMException ex) - { - throw new IllegalStateException(ex); - } - } - - private void unregisterMBean(MBeanServer mbeanServer) - { - try - { - if (mbeanServer.isRegistered(MBEAN_NAME)) - mbeanServer.unregisterMBean(MBEAN_NAME); - } - catch (JMException ex) - { - throw new IllegalStateException(ex); - } - } -} \ No newline at end of file Copied: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss= /test/osgi/example/jmx/bundle/JMXExampleActivator.java (from rev 89712, pro= jects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/= example/jmx/bundle/FooServiceActivator.java) =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/tes= t/osgi/example/jmx/bundle/JMXExampleActivator.java = (rev 0) +++ projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/tes= t/osgi/example/jmx/bundle/JMXExampleActivator.java 2009-06-03 14:44:55 UTC = (rev 89741) @@ -0,0 +1,99 @@ +/* + * 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.example.jmx.bundle; + +//$Id$ + +import static org.jboss.test.osgi.example.jmx.bundle.FooMBean.MBEAN_NAME; + +import javax.management.JMException; +import javax.management.MBeanServer; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; +import org.osgi.util.tracker.ServiceTracker; + +/** + * A Service Activator + * = + * @author thomas.diesler(a)jboss.com + * @since 24-Apr-2009 + */ +public class JMXExampleActivator implements BundleActivator +{ + public void start(BundleContext context) + { + ServiceTracker tracker =3D new ServiceTracker(context, MBeanServer.c= lass.getName(), null) + { + public Object addingService(ServiceReference reference) + { + MBeanServer mbeanServer =3D (MBeanServer)super.addingService(r= eference); + registerMBean(mbeanServer); + return mbeanServer; + } + + @Override + public void removedService(ServiceReference reference, Object ser= vice) + { + unregisterMBean((MBeanServer)service); + super.removedService(reference, service); + } + }; + tracker.open(); + } + + public void stop(BundleContext context) + { + ServiceReference sref =3D context.getServiceReference(MBeanServer.cl= ass.getName()); + if (sref !=3D null) + { + MBeanServer mbeanServer =3D (MBeanServer)context.getService(sref); + unregisterMBean(mbeanServer); + } + } + + private void registerMBean(MBeanServer mbeanServer) + { + try + { + mbeanServer.registerMBean(new Foo(), MBEAN_NAME); + } + catch (JMException ex) + { + throw new IllegalStateException(ex); + } + } + + private void unregisterMBean(MBeanServer mbeanServer) + { + try + { + if (mbeanServer.isRegistered(MBEAN_NAME)) + mbeanServer.unregisterMBean(MBEAN_NAME); + } + catch (JMException ex) + { + throw new IllegalStateException(ex); + } + } +} \ No newline at end of file Modified: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jbo= ss/test/osgi/example/jndi/JNDITestCase.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/tes= t/osgi/example/jndi/JNDITestCase.java 2009-06-03 14:41:04 UTC (rev 89740) +++ projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/tes= t/osgi/example/jndi/JNDITestCase.java 2009-06-03 14:44:55 UTC (rev 89741) @@ -47,12 +47,16 @@ public class JNDITestCase { private static OSGiRuntime runtime; + private static OSGiBundle bundle; = @BeforeClass public static void setUpClass() throws Exception { runtime =3D new OSGiTestHelper().getDefaultRuntime(); runtime.addCapability(new JNDICapability()); + = + bundle =3D runtime.installBundle("example-jndi.jar"); + bundle.start(); } = @AfterClass @@ -64,11 +68,6 @@ @Test public void testJNDIAccess() throws Exception { - OSGiBundle bundle =3D runtime.installBundle("example-jndi.jar"); - bundle.start(); - - assertEquals("Test bundle ACTIVE", Bundle.ACTIVE, bundle.getState()); - InitialContext iniCtx =3D runtime.getInitialContext(); String lookup =3D (String)iniCtx.lookup("test/Foo"); assertEquals("JNDI bound String expected", "Bar", lookup); Copied: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss= /test/osgi/example/jndi/bundle/JNDIExampleActivator.java (from rev 89712, p= rojects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osg= i/example/jndi/bundle/ServiceActivator.java) =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/tes= t/osgi/example/jndi/bundle/JNDIExampleActivator.java = (rev 0) +++ projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/tes= t/osgi/example/jndi/bundle/JNDIExampleActivator.java 2009-06-03 14:44:55 UT= C (rev 89741) @@ -0,0 +1,76 @@ +/* + * 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.example.jndi.bundle; + +//$Id$ + +import javax.naming.InitialContext; +import javax.naming.NamingException; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; + +/** + * A Service Activator + * = + * @author thomas.diesler(a)jboss.com + * @since 05-May-2009 + */ +public class JNDIExampleActivator implements BundleActivator +{ + public void start(BundleContext context) + { + try + { + InitialContext iniCtx =3D getInitialContext(context); + iniCtx.createSubcontext("test").bind("Foo", new String("Bar")); + } + catch (NamingException ex) + { + throw new IllegalStateException("Cannot bind to JNDI", ex); + } + } + + public void stop(BundleContext context) + { + try + { + InitialContext iniCtx =3D getInitialContext(context); + iniCtx.unbind("test"); + } + catch (NamingException ex) + { + throw new IllegalStateException("Cannot unbind from JNDI", ex); + } + } + + private InitialContext getInitialContext(BundleContext context) + { + ServiceReference sref =3D context.getServiceReference(InitialContext= .class.getName()); + if (sref =3D=3D null) + throw new IllegalStateException("Cannot access the InitialContext= "); + = + InitialContext initContext =3D (InitialContext)context.getService(sr= ef); + return initContext; + } +} \ No newline at end of file Deleted: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jbos= s/test/osgi/example/jndi/bundle/ServiceActivator.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/tes= t/osgi/example/jndi/bundle/ServiceActivator.java 2009-06-03 14:41:04 UTC (r= ev 89740) +++ projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/tes= t/osgi/example/jndi/bundle/ServiceActivator.java 2009-06-03 14:44:55 UTC (r= ev 89741) @@ -1,76 +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.test.osgi.example.jndi.bundle; - -//$Id$ - -import javax.naming.InitialContext; -import javax.naming.NamingException; - -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; - -/** - * A Service Activator - * = - * @author thomas.diesler(a)jboss.com - * @since 05-May-2009 - */ -public class ServiceActivator implements BundleActivator -{ - public void start(BundleContext context) - { - try - { - InitialContext iniCtx =3D getInitialContext(context); - iniCtx.createSubcontext("test").bind("Foo", new String("Bar")); - } - catch (NamingException ex) - { - throw new IllegalStateException("Cannot bind to JNDI", ex); - } - } - - public void stop(BundleContext context) - { - try - { - InitialContext iniCtx =3D getInitialContext(context); - iniCtx.unbind("test"); - } - catch (NamingException ex) - { - throw new IllegalStateException("Cannot unbind from JNDI", ex); - } - } - - private InitialContext getInitialContext(BundleContext context) - { - ServiceReference sref =3D context.getServiceReference(InitialContext= .class.getName()); - if (sref =3D=3D null) - throw new IllegalStateException("Cannot access the InitialContext= "); - = - InitialContext initContext =3D (InitialContext)context.getService(sr= ef); - return initContext; - } -} \ No newline at end of file Copied: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss= /test/osgi/example/log/bundle/LogExampleActivator.java (from rev 89723, pro= jects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/= example/log/bundle/LogServiceActivator.java) =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/tes= t/osgi/example/log/bundle/LogExampleActivator.java = (rev 0) +++ projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/tes= t/osgi/example/log/bundle/LogExampleActivator.java 2009-06-03 14:44:55 UTC = (rev 89741) @@ -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.test.osgi.example.log.bundle; + +//$Id: ServiceActivator.java 87329 2009-04-15 10:34:21Z thomas.diesler(a)j= boss.com $ + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; + +public class LogExampleActivator implements BundleActivator +{ + public void start(final BundleContext context) + { + ServiceA service =3D new ServiceA(context); + context.registerService(ServiceA.class.getName(), service, null); + } + + public void stop(BundleContext context) + { + // Do Nothing. It is unnecessary to unregister services or Framework= listeners + // because they must be clean up by the Framework anyway. + } +} \ No newline at end of file Deleted: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jbos= s/test/osgi/example/log/bundle/LogServiceActivator.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/tes= t/osgi/example/log/bundle/LogServiceActivator.java 2009-06-03 14:41:04 UTC = (rev 89740) +++ projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/tes= t/osgi/example/log/bundle/LogServiceActivator.java 2009-06-03 14:44:55 UTC = (rev 89741) @@ -1,42 +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.test.osgi.example.log.bundle; - -//$Id: ServiceActivator.java 87329 2009-04-15 10:34:21Z thomas.diesler(a)j= boss.com $ - -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; - -public class LogServiceActivator implements BundleActivator -{ - public void start(final BundleContext context) - { - ServiceA service =3D new ServiceA(context); - context.registerService(ServiceA.class.getName(), service, null); - } - - public void stop(BundleContext context) - { - // Do Nothing. It is unnecessary to unregister services or Framework= listeners - // because they must be clean up by the Framework anyway. - } -} \ No newline at end of file Modified: projects/jboss-osgi/trunk/testsuite/example/src/test/resources/ht= tp/example-http.bnd =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- projects/jboss-osgi/trunk/testsuite/example/src/test/resources/http/exa= mple-http.bnd 2009-06-03 14:41:04 UTC (rev 89740) +++ projects/jboss-osgi/trunk/testsuite/example/src/test/resources/http/exa= mple-http.bnd 2009-06-03 14:44:55 UTC (rev 89741) @@ -1,6 +1,6 @@ # bnd build -classpath target/test-classes -output target/test-libs/exampl= e/example-http.jar src/test/resources/example/http/example-http.bnd = Bundle-SymbolicName: example-http -Bundle-Activator: org.jboss.test.osgi.example.http.bundle.ServiceActivator +Bundle-Activator: org.jboss.test.osgi.example.http.bundle.HttpExampleActiv= ator Export-Package: org.jboss.test.osgi.example.http.bundle Include-Resource: res/message.txt=3Dmessage.txt \ No newline at end of file Modified: projects/jboss-osgi/trunk/testsuite/example/src/test/resources/jm= x/example-jmx.bnd =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- projects/jboss-osgi/trunk/testsuite/example/src/test/resources/jmx/exam= ple-jmx.bnd 2009-06-03 14:41:04 UTC (rev 89740) +++ projects/jboss-osgi/trunk/testsuite/example/src/test/resources/jmx/exam= ple-jmx.bnd 2009-06-03 14:44:55 UTC (rev 89741) @@ -1,5 +1,5 @@ # bnd build -classpath target/test-classes -output target/test-libs/exampl= e-jmx.jar src/test/resources/jmx/example-jmx.bnd = Bundle-SymbolicName: example-jmx -Bundle-Activator: org.jboss.test.osgi.example.jmx.bundle.FooServiceActivat= or +Bundle-Activator: org.jboss.test.osgi.example.jmx.bundle.JMXExampleActivat= or Export-Package: org.jboss.test.osgi.example.jmx.bundle = Modified: projects/jboss-osgi/trunk/testsuite/example/src/test/resources/jn= di/example-jndi.bnd =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- projects/jboss-osgi/trunk/testsuite/example/src/test/resources/jndi/exa= mple-jndi.bnd 2009-06-03 14:41:04 UTC (rev 89740) +++ projects/jboss-osgi/trunk/testsuite/example/src/test/resources/jndi/exa= mple-jndi.bnd 2009-06-03 14:44:55 UTC (rev 89741) @@ -1,6 +1,6 @@ # bnd build -classpath target/test-classes -output target/test-libs/jndi-t= est.jar src/test/resources/jndi/jndi-test.bnd = Bundle-SymbolicName: example-jndi -Bundle-Activator: org.jboss.test.osgi.example.jndi.bundle.ServiceActivator +Bundle-Activator: org.jboss.test.osgi.example.jndi.bundle.JNDIExampleActiv= ator Export-Package: org.jboss.test.osgi.example.jndi.bundle = Import-Package: javax.naming, org.osgi.framework \ No newline at end of file Modified: projects/jboss-osgi/trunk/testsuite/example/src/test/resources/lo= g/example-log.bnd =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- projects/jboss-osgi/trunk/testsuite/example/src/test/resources/log/exam= ple-log.bnd 2009-06-03 14:41:04 UTC (rev 89740) +++ projects/jboss-osgi/trunk/testsuite/example/src/test/resources/log/exam= ple-log.bnd 2009-06-03 14:44:55 UTC (rev 89741) @@ -2,5 +2,5 @@ = Bundle-SymbolicName: example-log = -Bundle-Activator: org.jboss.test.osgi.example.log.bundle.LogServiceActivat= or +Bundle-Activator: org.jboss.test.osgi.example.log.bundle.LogExampleActivat= or Export-Package: org.jboss.test.osgi.example.log.bundle --===============6160450194527044058==--