From 9ec42334e97fc6e10c766b55dd9a74de192f9b46 Mon Sep 17 00:00:00 2001 From: Donald Woods Date: Fri, 19 Feb 2010 03:10:33 +0000 Subject: [PATCH] OPENJPA-1512 minor updates to BundleActivator support git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@911684 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/openjpa/osgi/PersistenceActivator.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/openjpa/src/main/java/org/apache/openjpa/osgi/PersistenceActivator.java b/openjpa/src/main/java/org/apache/openjpa/osgi/PersistenceActivator.java index 370deedc7..1ab99effe 100644 --- a/openjpa/src/main/java/org/apache/openjpa/osgi/PersistenceActivator.java +++ b/openjpa/src/main/java/org/apache/openjpa/osgi/PersistenceActivator.java @@ -23,6 +23,7 @@ import javax.persistence.spi.PersistenceProvider; import org.apache.openjpa.persistence.PersistenceProviderImpl; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceRegistration; /** @@ -36,24 +37,26 @@ public class PersistenceActivator implements BundleActivator { // following would be set by Aries to expose their OSGi enabled provider public static final String PERSISTENCE_PROVIDER = PersistenceProvider.class.getName(); public static final String OSGI_PERSISTENCE_PROVIDER = PersistenceProviderImpl.class.getName(); - private static BundleContext ctx; + private ServiceRegistration svcReg = null; /* (non-Javadoc) * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext) */ - public void start(BundleContext arg0) throws Exception { - ctx = arg0; + public void start(BundleContext ctx) throws Exception { PersistenceProvider provider = new PersistenceProviderImpl(); Hashtable props = new Hashtable(); props.put(PERSISTENCE_PROVIDER_ARIES, OSGI_PERSISTENCE_PROVIDER); - ctx.registerService(PERSISTENCE_PROVIDER, provider, props); + svcReg = ctx.registerService(PERSISTENCE_PROVIDER, provider, props); } /* (non-Javadoc) * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext) */ - public void stop(BundleContext arg0) throws Exception { - // no-op + public void stop(BundleContext ctx) throws Exception { + if (svcReg != null) { + svcReg.unregister(); + svcReg = null; + } } }