Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Frost2011-05-13 13:23:12 -0400
committerChristopher Frost2011-05-13 13:23:12 -0400
commit949c21948e6dc68828879f78425f799a7e5ccf3d (patch)
tree4e9c95709be8688eb79597c70973e1f5f4221192
parent551889d0bd85f1479e68409cb01f33dc7c5a1361 (diff)
parentd7395da14e1d948de8fe43728100eb2261fc9903 (diff)
downloadorg.eclipse.virgo.kernel-949c21948e6dc68828879f78425f799a7e5ccf3d.tar.gz
org.eclipse.virgo.kernel-949c21948e6dc68828879f78425f799a7e5ccf3d.tar.xz
org.eclipse.virgo.kernel-949c21948e6dc68828879f78425f799a7e5ccf3d.zip
Merge branch 'master' of ssh://git.eclipse.org/gitroot/virgo/org.eclipse.virgo.kernel
-rw-r--r--org.eclipse.virgo.kernel.deployer.dm/src/main/java/org/eclipse/virgo/kernel/deployer/app/spring/UserRegionModuleContextAccessor.java18
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/module/KernelModuleContextAccessorFactory.java30
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/module/internal/KernelModuleContextAccessor.java76
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/module/internal/ModuleContextWrapper.java101
4 files changed, 220 insertions, 5 deletions
diff --git a/org.eclipse.virgo.kernel.deployer.dm/src/main/java/org/eclipse/virgo/kernel/deployer/app/spring/UserRegionModuleContextAccessor.java b/org.eclipse.virgo.kernel.deployer.dm/src/main/java/org/eclipse/virgo/kernel/deployer/app/spring/UserRegionModuleContextAccessor.java
index 487a8437..57a5a43b 100644
--- a/org.eclipse.virgo.kernel.deployer.dm/src/main/java/org/eclipse/virgo/kernel/deployer/app/spring/UserRegionModuleContextAccessor.java
+++ b/org.eclipse.virgo.kernel.deployer.dm/src/main/java/org/eclipse/virgo/kernel/deployer/app/spring/UserRegionModuleContextAccessor.java
@@ -13,6 +13,9 @@ package org.eclipse.virgo.kernel.deployer.app.spring;
import java.util.Collection;
+import org.eclipse.virgo.kernel.module.KernelModuleContextAccessorFactory;
+import org.eclipse.virgo.kernel.module.ModuleContext;
+import org.eclipse.virgo.kernel.module.ModuleContextAccessor;
import org.eclipse.virgo.kernel.serviceability.Assert;
import org.eclipse.virgo.kernel.serviceability.NonNull;
import org.osgi.framework.Bundle;
@@ -22,11 +25,9 @@ import org.osgi.framework.ServiceReference;
import org.springframework.context.ApplicationContext;
import org.springframework.osgi.context.ConfigurableOsgiBundleApplicationContext;
-import org.eclipse.virgo.kernel.module.ModuleContext;
-import org.eclipse.virgo.kernel.module.ModuleContextAccessor;
-
/**
- * {@link UserRegionModuleContextAccessor} accesses {@link ModuleContext ModuleContexts} in the user region.
+ * {@link UserRegionModuleContextAccessor} accesses {@link ModuleContext ModuleContexts} in either the the user region or the kernel, but this class must
+ * be loaded in the user region.
* <p />
*
* <strong>Concurrent Semantics</strong><br />
@@ -35,6 +36,12 @@ import org.eclipse.virgo.kernel.module.ModuleContextAccessor;
*
*/
final class UserRegionModuleContextAccessor implements ModuleContextAccessor {
+
+ private final ModuleContextAccessor kernelModuleContextAccessor;
+
+ UserRegionModuleContextAccessor() {
+ this.kernelModuleContextAccessor = KernelModuleContextAccessorFactory.create();
+ }
/**
* {@inheritDoc}
@@ -70,7 +77,8 @@ final class UserRegionModuleContextAccessor implements ModuleContextAccessor {
Assert.isFalse(true, "Unexpected exception %s", e.getMessage());
}
}
- return null;
+ // Try the kernel in case the bundle resides in the kernel region.
+ return this.kernelModuleContextAccessor.getModuleContext(bundle);
}
}
diff --git a/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/module/KernelModuleContextAccessorFactory.java b/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/module/KernelModuleContextAccessorFactory.java
new file mode 100644
index 00000000..fd9bc5af
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/module/KernelModuleContextAccessorFactory.java
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Copyright (c) 2011 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.module;
+
+import org.eclipse.virgo.kernel.module.internal.KernelModuleContextAccessor;
+
+/**
+ * {@link KernelModuleContextAccessorFactory} is used to construct {@link ModuleContextAccessor} instances for the
+ * kernel.
+ * <p />
+ *
+ * <strong>Concurrent Semantics</strong><br />
+ * Thread safe.
+ */
+public class KernelModuleContextAccessorFactory {
+
+ public static ModuleContextAccessor create() {
+ return new KernelModuleContextAccessor();
+ }
+
+}
diff --git a/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/module/internal/KernelModuleContextAccessor.java b/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/module/internal/KernelModuleContextAccessor.java
new file mode 100644
index 00000000..4975d080
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/module/internal/KernelModuleContextAccessor.java
@@ -0,0 +1,76 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.module.internal;
+
+import java.util.Collection;
+
+import org.eclipse.virgo.kernel.serviceability.Assert;
+import org.eclipse.virgo.kernel.serviceability.NonNull;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.springframework.context.ApplicationContext;
+import org.springframework.osgi.context.ConfigurableOsgiBundleApplicationContext;
+
+import org.eclipse.virgo.kernel.module.ModuleContext;
+import org.eclipse.virgo.kernel.module.ModuleContextAccessor;
+
+/**
+ * {@link KernelModuleContextAccessor} accesses {@link ModuleContext ModuleContexts} in the kernel region.
+ * <p />
+ *
+ * <strong>Concurrent Semantics</strong><br />
+ *
+ * Thread safe.
+ *
+ */
+public final class KernelModuleContextAccessor implements ModuleContextAccessor {
+
+ /**
+ * {@inheritDoc}
+ */
+ public ModuleContext getModuleContext(@NonNull Bundle bundle) {
+ BundleContext bundleContext = bundle.getBundleContext();
+ // The bundle must have a bundle context in order to have a module context.
+ if (bundleContext != null) {
+ String symbolicName = bundle.getSymbolicName();
+ try {
+ Collection<ServiceReference<ApplicationContext>> refs = bundleContext.getServiceReferences(ApplicationContext.class,
+ "(Bundle-SymbolicName=" + symbolicName + ")");
+ if (refs.size() != 0) {
+ for (ServiceReference<ApplicationContext> ref : refs) {
+ Object service = bundleContext.getService(ref);
+ try {
+ // Avoid non-kernel region application contexts.
+ if (service instanceof ApplicationContext) {
+ ApplicationContext appCtx = (ApplicationContext) service;
+ if (appCtx instanceof ConfigurableOsgiBundleApplicationContext) {
+ ConfigurableOsgiBundleApplicationContext cAppCtx = (ConfigurableOsgiBundleApplicationContext) appCtx;
+ if (bundleContext == cAppCtx.getBundleContext()) {
+ return new ModuleContextWrapper(cAppCtx);
+ }
+ }
+ }
+ } finally {
+ bundleContext.ungetService(ref);
+ }
+ }
+ }
+ } catch (InvalidSyntaxException e) {
+ Assert.isFalse(true, "Unexpected exception %s", e.getMessage());
+ }
+ }
+ return null;
+ }
+
+}
diff --git a/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/module/internal/ModuleContextWrapper.java b/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/module/internal/ModuleContextWrapper.java
new file mode 100644
index 00000000..e1e0e801
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/module/internal/ModuleContextWrapper.java
@@ -0,0 +1,101 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.module.internal;
+
+import org.springframework.beans.BeansException;
+import org.springframework.context.ConfigurableApplicationContext;
+
+import org.eclipse.virgo.kernel.module.Component;
+import org.eclipse.virgo.kernel.module.ModuleContext;
+import org.eclipse.virgo.kernel.module.NoSuchComponentException;
+
+/**
+ * {@link ModuleContextWrapper} wraps a {@link ConfigurableApplicationContext} to provide an equivalent {@link ModuleContext}.
+ * <p />
+ *
+ * <strong>Concurrent Semantics</strong><br />
+ *
+ * Thread safe.
+ *
+ */
+final class ModuleContextWrapper implements ModuleContext {
+
+ private final ConfigurableApplicationContext appCtx;
+
+ ModuleContextWrapper(ConfigurableApplicationContext appCtx) {
+ this.appCtx = appCtx;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object getApplicationContext() {
+ return this.appCtx;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Component getComponent(final String componentName) throws NoSuchComponentException {
+ try {
+ final Object component = this.appCtx.getBean(componentName);
+ return new Component() {
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getName() {
+ return componentName;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getType() {
+ return component.getClass().getName();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isPrototype() {
+ return ModuleContextWrapper.this.appCtx.getBeanFactory().isPrototype(componentName);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isSingleton() {
+ return ModuleContextWrapper.this.appCtx.getBeanFactory().isSingleton(componentName);
+ }
+
+ };
+ } catch (BeansException e) {
+ throw new NoSuchComponentException(e.getMessage());
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String[] getComponentNames() {
+ return this.appCtx.getBeanDefinitionNames();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getDisplayName() {
+ return this.appCtx.getDisplayName();
+ }
+
+}

Back to the top