diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-03-26 22:03:11 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-03-26 22:03:11 +0000 |
commit | df746069d21296db4551dcff9d10a184969e4d07 (patch) | |
tree | f267c7202b8c1f248f3cf25e540930e203b5e7e3 /java | |
parent | 4e86272ed741d72dfeb32369bb20344dbdb52981 (diff) |
Add a print in the OperationsActivator to show which bundle loads AddService
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@758881 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java')
2 files changed, 27 insertions, 6 deletions
diff --git a/java/sca/modules/node-impl-osgi/src/test/java/calculator/dosgi/operations/impl/OperationsActivator.java b/java/sca/modules/node-impl-osgi/src/test/java/calculator/dosgi/operations/impl/OperationsActivator.java index afc1ff4c1c..5348d19f34 100644 --- a/java/sca/modules/node-impl-osgi/src/test/java/calculator/dosgi/operations/impl/OperationsActivator.java +++ b/java/sca/modules/node-impl-osgi/src/test/java/calculator/dosgi/operations/impl/OperationsActivator.java @@ -6,15 +6,15 @@ * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations - * under the License. + * under the License. */ package calculator.dosgi.operations.impl; @@ -23,8 +23,11 @@ import java.util.Dictionary; import java.util.Hashtable; import java.util.logging.Logger; +import org.osgi.framework.Bundle; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; +import org.osgi.service.packageadmin.PackageAdmin; import calculator.dosgi.operations.AddService; import calculator.dosgi.operations.DivideService; @@ -32,7 +35,7 @@ import calculator.dosgi.operations.MultiplyService; import calculator.dosgi.operations.SubtractService; /** - * + * */ public class OperationsActivator implements BundleActivator { private Logger logger = Logger.getLogger(OperationsActivator.class.getName()); @@ -58,11 +61,28 @@ public class OperationsActivator implements BundleActivator { props.put("sca.service", "DivideComponent#service-name(Divide)"); context.registerService(DivideService.class.getName(), new DivideServiceImpl(), props); + getBundle(context, AddService.class); } public void stop(BundleContext context) throws Exception { logger.info("Stopping " + context.getBundle()); - // Registered services will be automatically unregistered + // Registered services will be automatically unregistered + } + + private Bundle getBundle(BundleContext bundleContext, Class<?> cls) { + PackageAdmin packageAdmin = null; + // PackageAdmin is used to resolve bundles + ServiceReference ref = bundleContext.getServiceReference("org.osgi.service.packageadmin.PackageAdmin"); + if (ref != null) { + packageAdmin = (PackageAdmin)bundleContext.getService(ref); + Bundle bundle = packageAdmin.getBundle(cls); + if (bundle != null) { + logger.info(cls.getName() + " is loaded by bundle: " + bundle.getSymbolicName()); + } + bundleContext.ungetService(ref); + return bundle; + } + return null; } } diff --git a/java/sca/modules/node-impl-osgi/src/test/resources/calculator/dosgi/operations/META-INF/MANIFEST.MF b/java/sca/modules/node-impl-osgi/src/test/resources/calculator/dosgi/operations/META-INF/MANIFEST.MF index ccdb755d56..ef8c19f9c8 100644 --- a/java/sca/modules/node-impl-osgi/src/test/resources/calculator/dosgi/operations/META-INF/MANIFEST.MF +++ b/java/sca/modules/node-impl-osgi/src/test/resources/calculator/dosgi/operations/META-INF/MANIFEST.MF @@ -6,7 +6,8 @@ Bundle-Activator: calculator.dosgi.operations.impl.OperationsActivator Bundle-ManifestVersion: 2
Import-Package: calculator.dosgi.operations;version="1.0.0",
org.osgi.framework,
- org.osgi.service.component;resolution:=optional
+ org.osgi.service.component;resolution:=optional,
+ org.osgi.service.packageadmin
Bundle-SymbolicName: calculator.dosgi.operations
Bundle-Vendor: The Apache Software Foundation
Bundle-ActivationPolicy: lazy
|