Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2011-03-11 10:07:27 -0500
committerGlyn Normington2011-03-11 10:07:27 -0500
commitf40763f49ddf7b5eb73e6b70063b76b5fea9828f (patch)
treea6a29dda507fe780968e0d90ab76df319e9437e2 /org.eclipse.virgo.kernel.userregionfactory
parentdd1885e0dee73ceea135bb978a5a957282bbc504 (diff)
parent36b7b669bedc99d1921b2d8adb7a7dad5512b1fc (diff)
downloadorg.eclipse.virgo.kernel-f40763f49ddf7b5eb73e6b70063b76b5fea9828f.tar.gz
org.eclipse.virgo.kernel-f40763f49ddf7b5eb73e6b70063b76b5fea9828f.tar.xz
org.eclipse.virgo.kernel-f40763f49ddf7b5eb73e6b70063b76b5fea9828f.zip
Merge branch 'master' into region_api
Conflicts: org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/hook/RegionResolverHook.java org.eclipse.virgo.kernel.userregionfactory/src/main/java/org/eclipse/virgo/kernel/userregionfactory/Activator.java
Diffstat (limited to 'org.eclipse.virgo.kernel.userregionfactory')
-rw-r--r--org.eclipse.virgo.kernel.userregionfactory/src/main/java/org/eclipse/virgo/kernel/userregionfactory/Activator.java23
-rw-r--r--org.eclipse.virgo.kernel.userregionfactory/src/main/java/org/eclipse/virgo/kernel/userregionfactory/PackageImportWildcardExpander.java18
-rw-r--r--org.eclipse.virgo.kernel.userregionfactory/src/main/java/org/eclipse/virgo/kernel/userregionfactory/UserRegionFactoryLogEvents.java54
-rw-r--r--org.eclipse.virgo.kernel.userregionfactory/src/main/java/org/eclipse/virgo/kernel/userregionfactory/UserRegionFactoryParserLogger.java3
-rw-r--r--org.eclipse.virgo.kernel.userregionfactory/src/main/resources/EventLogMessages.properties16
-rw-r--r--org.eclipse.virgo.kernel.userregionfactory/src/test/java/org/eclipse/virgo/kernel/userregionfactory/PackageImportWildcardExpanderTests.java5
6 files changed, 88 insertions, 31 deletions
diff --git a/org.eclipse.virgo.kernel.userregionfactory/src/main/java/org/eclipse/virgo/kernel/userregionfactory/Activator.java b/org.eclipse.virgo.kernel.userregionfactory/src/main/java/org/eclipse/virgo/kernel/userregionfactory/Activator.java
index 26efcb90..46d56cfd 100644
--- a/org.eclipse.virgo.kernel.userregionfactory/src/main/java/org/eclipse/virgo/kernel/userregionfactory/Activator.java
+++ b/org.eclipse.virgo.kernel.userregionfactory/src/main/java/org/eclipse/virgo/kernel/userregionfactory/Activator.java
@@ -26,7 +26,6 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.eclipse.virgo.kernel.core.Shutdown;
-import org.eclipse.virgo.kernel.osgi.framework.OsgiFrameworkLogEvents;
import org.eclipse.virgo.kernel.osgi.framework.OsgiFrameworkUtils;
import org.eclipse.virgo.kernel.osgi.framework.OsgiServiceHolder;
import org.eclipse.virgo.kernel.osgi.region.Region;
@@ -125,7 +124,7 @@ public final class Activator implements BundleActivator {
Shutdown shutdown = getPotentiallyDelayedService(bundleContext, Shutdown.class);
getRegionConfiguration(configAdmin, eventLogger, shutdown);
- createUserRegion(bundleContext, regionDigraph, eventLogger);
+ createUserRegion(regionDigraph, eventLogger);
}
private void getRegionConfiguration(ConfigurationAdmin configAdmin, EventLogger eventLogger, Shutdown shutdown) {
@@ -142,20 +141,19 @@ public final class Activator implements BundleActivator {
this.regionBundleImports = properties.get(USER_REGION_BUNDLE_IMPORTS_PROPERTY);
this.regionServiceExports = properties.get(USER_REGION_SERVICE_EXPORTS_PROPERTY);
} else {
- eventLogger.log(OsgiFrameworkLogEvents.USER_REGION_CONFIGURATION_UNAVAILABLE);
+ eventLogger.log(UserRegionFactoryLogEvents.USER_REGION_CONFIGURATION_UNAVAILABLE);
shutdown.immediateShutdown();
}
} catch (Exception e) {
- eventLogger.log(OsgiFrameworkLogEvents.USER_REGION_CONFIGURATION_UNAVAILABLE, e);
+ eventLogger.log(UserRegionFactoryLogEvents.USER_REGION_CONFIGURATION_UNAVAILABLE, e);
shutdown.immediateShutdown();
}
}
- private void createUserRegion(BundleContext userRegionBundleContext, RegionDigraph regionDigraph, EventLogger eventLogger)
- throws BundleException, InvalidSyntaxException {
+ private void createUserRegion(RegionDigraph regionDigraph, EventLogger eventLogger) throws BundleException, InvalidSyntaxException {
BundleContext systemBundleContext = getSystemBundleContext();
- Bundle userRegionFactoryBundle = userRegionBundleContext.getBundle();
+ Bundle userRegionFactoryBundle = this.bundleContext.getBundle();
Region kernelRegion = getKernelRegion(regionDigraph);
kernelRegion.removeBundle(userRegionFactoryBundle);
@@ -169,12 +167,12 @@ public final class Activator implements BundleActivator {
RegionFilter userRegionFilter = createUserRegionFilter(regionDigraph);
kernelRegion.connectRegion(userRegion, userRegionFilter);
- notifyUserRegionStarting(userRegionBundleContext);
+ notifyUserRegionStarting(this.bundleContext);
initialiseUserRegionBundles(userRegion);
registerRegionService(userRegion);
- publishUserRegionBundleContext(userRegionBundleContext);
+ publishUserRegionBundleContext(this.bundleContext);
}
private RegionFilter createUserRegionFilter(RegionDigraph digraph) throws InvalidSyntaxException {
@@ -197,7 +195,7 @@ public final class Activator implements BundleActivator {
for (String filter : allowedBundles) {
builder.allow(RegionFilter.VISIBLE_BUNDLE_NAMESPACE, filter);
}
- Collection<String> allowedPackages = createUserRegionPackageImportPolicy(systemBundleContext);
+ Collection<String> allowedPackages = createUserRegionPackageImportPolicy(systemBundleContext, eventLogger);
for (String filter : allowedPackages) {
builder.allow(RegionFilter.VISIBLE_PACKAGE_NAMESPACE, filter);
}
@@ -298,15 +296,14 @@ public final class Activator implements BundleActivator {
return result;
}
- private Collection<String> createUserRegionPackageImportPolicy(BundleContext systemBundleContext) {
+ private Collection<String> createUserRegionPackageImportPolicy(BundleContext systemBundleContext, EventLogger eventLogger) {
String userRegionImportsProperty = this.regionPackageImports != null ? this.regionPackageImports
: this.bundleContext.getProperty(USER_REGION_PACKAGE_IMPORTS_PROPERTY);
String expandedUserRegionImportsProperty = null;
if (userRegionImportsProperty != null) {
expandedUserRegionImportsProperty = PackageImportWildcardExpander.expandPackageImportsWildcards(userRegionImportsProperty,
- systemBundleContext);
+ systemBundleContext, eventLogger);
}
-
return importPackageToFilter(expandedUserRegionImportsProperty);
}
diff --git a/org.eclipse.virgo.kernel.userregionfactory/src/main/java/org/eclipse/virgo/kernel/userregionfactory/PackageImportWildcardExpander.java b/org.eclipse.virgo.kernel.userregionfactory/src/main/java/org/eclipse/virgo/kernel/userregionfactory/PackageImportWildcardExpander.java
index 92cbbf27..eff809c0 100644
--- a/org.eclipse.virgo.kernel.userregionfactory/src/main/java/org/eclipse/virgo/kernel/userregionfactory/PackageImportWildcardExpander.java
+++ b/org.eclipse.virgo.kernel.userregionfactory/src/main/java/org/eclipse/virgo/kernel/userregionfactory/PackageImportWildcardExpander.java
@@ -18,7 +18,6 @@ import java.util.Hashtable;
import java.util.List;
import java.util.Set;
-import org.eclipse.virgo.kernel.osgi.framework.OsgiFrameworkLogEvents;
import org.eclipse.virgo.kernel.serviceability.Assert;
import org.eclipse.virgo.medic.eventlog.EventLogger;
import org.eclipse.virgo.util.osgi.manifest.BundleManifest;
@@ -46,17 +45,10 @@ final class PackageImportWildcardExpander {
private static final String wildcard = "*";
- static String expandPackageImportsWildcards(String userRegionImportsProperty, BundleContext bundleContext) {
- ServiceReference<EventLogger> eventLoggerServiceReference = bundleContext.getServiceReference(EventLogger.class);
- EventLogger eventLogger = bundleContext.getService(eventLoggerServiceReference);
+ static String expandPackageImportsWildcards(String userRegionImportsProperty, BundleContext systemBundleContext, EventLogger eventLogger) {
+ String[] exportedPackageNames = getExportedPackageNames(systemBundleContext);
- String[] exportedPackageNames = getExportedPackageNames(bundleContext);
-
- String expandedUserRegionImportsProperty = expandWildcards(userRegionImportsProperty, exportedPackageNames, eventLogger);
-
- bundleContext.ungetService(eventLoggerServiceReference);
-
- return expandedUserRegionImportsProperty;
+ return expandWildcards(userRegionImportsProperty, exportedPackageNames, eventLogger);
}
private static String[] getExportedPackageNames(BundleContext bundleContext) {
@@ -64,7 +56,7 @@ final class PackageImportWildcardExpander {
for (ExportedPackage exportedPackage : getExportedPackages(bundleContext)) {
exportedPackageNames.add(exportedPackage.getName());
}
- return exportedPackageNames.toArray(new String[] {});
+ return exportedPackageNames.toArray(new String[exportedPackageNames.size()]);
}
private static ExportedPackage[] getExportedPackages(BundleContext bundleContext) {
@@ -132,7 +124,7 @@ final class PackageImportWildcardExpander {
}
}
if (expansions.isEmpty()) {
- eventLogger.log(OsgiFrameworkLogEvents.REGION_IMPORT_NO_MATCH, wildcardedPackageName);
+ eventLogger.log(UserRegionFactoryLogEvents.REGION_IMPORT_NO_MATCH, wildcardedPackageName);
}
return expansions;
}
diff --git a/org.eclipse.virgo.kernel.userregionfactory/src/main/java/org/eclipse/virgo/kernel/userregionfactory/UserRegionFactoryLogEvents.java b/org.eclipse.virgo.kernel.userregionfactory/src/main/java/org/eclipse/virgo/kernel/userregionfactory/UserRegionFactoryLogEvents.java
new file mode 100644
index 00000000..7d1ba060
--- /dev/null
+++ b/org.eclipse.virgo.kernel.userregionfactory/src/main/java/org/eclipse/virgo/kernel/userregionfactory/UserRegionFactoryLogEvents.java
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * 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.userregionfactory;
+
+import org.eclipse.virgo.kernel.serviceability.LogEventDelegate;
+import org.eclipse.virgo.medic.eventlog.Level;
+import org.eclipse.virgo.medic.eventlog.LogEvent;
+
+/**
+ * {@link org.eclipse.virgo.medic.eventlog.LogEvent} for the OSGi provisioning bundle.
+ * <p/>
+ *
+ * <strong>Concurrent Semantics</strong><br />
+ *
+ * Threadsafe.
+ *
+ */
+public enum UserRegionFactoryLogEvents implements LogEvent {
+
+ REGION_IMPORTS_PARSE_FAILED(1, Level.ERROR), //
+ REGION_IMPORT_NO_MATCH(2, Level.WARNING), //
+ USER_REGION_CONFIGURATION_UNAVAILABLE(10, Level.ERROR);
+
+ private static final String PREFIX = "UF";
+
+ private final LogEventDelegate delegate;
+
+ private UserRegionFactoryLogEvents(int code, Level level) {
+ this.delegate = new LogEventDelegate(PREFIX, code, level);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getEventCode() {
+ return this.delegate.getEventCode();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Level getLevel() {
+ return this.delegate.getLevel();
+ }
+}
diff --git a/org.eclipse.virgo.kernel.userregionfactory/src/main/java/org/eclipse/virgo/kernel/userregionfactory/UserRegionFactoryParserLogger.java b/org.eclipse.virgo.kernel.userregionfactory/src/main/java/org/eclipse/virgo/kernel/userregionfactory/UserRegionFactoryParserLogger.java
index a69be1ca..d36ca6c4 100644
--- a/org.eclipse.virgo.kernel.userregionfactory/src/main/java/org/eclipse/virgo/kernel/userregionfactory/UserRegionFactoryParserLogger.java
+++ b/org.eclipse.virgo.kernel.userregionfactory/src/main/java/org/eclipse/virgo/kernel/userregionfactory/UserRegionFactoryParserLogger.java
@@ -11,7 +11,6 @@
package org.eclipse.virgo.kernel.userregionfactory;
-import org.eclipse.virgo.kernel.osgi.framework.OsgiFrameworkLogEvents;
import org.eclipse.virgo.medic.eventlog.EventLogger;
import org.eclipse.virgo.util.osgi.manifest.parse.ParserLogger;
@@ -37,6 +36,6 @@ final class UserRegionFactoryParserLogger implements ParserLogger {
}
public void outputErrorMsg(Exception re, String item) {
- this.eventLogger.log(OsgiFrameworkLogEvents.REGION_IMPORTS_PARSE_FAILED, re, item);
+ this.eventLogger.log(UserRegionFactoryLogEvents.REGION_IMPORTS_PARSE_FAILED, re, item);
}
}
diff --git a/org.eclipse.virgo.kernel.userregionfactory/src/main/resources/EventLogMessages.properties b/org.eclipse.virgo.kernel.userregionfactory/src/main/resources/EventLogMessages.properties
new file mode 100644
index 00000000..340bb1fb
--- /dev/null
+++ b/org.eclipse.virgo.kernel.userregionfactory/src/main/resources/EventLogMessages.properties
@@ -0,0 +1,16 @@
+################################################################################
+# Copyright (c) 2011 SAP AG
+# 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:
+# Hristo Iliev, SAP AG - initial contribution
+################################################################################
+
+# User region factory
+UF0001E=Region imports parsing failed: {}.
+UF0002W=No match found for region import: {}.
+
+UF0010E=User region configuration unavailable.
diff --git a/org.eclipse.virgo.kernel.userregionfactory/src/test/java/org/eclipse/virgo/kernel/userregionfactory/PackageImportWildcardExpanderTests.java b/org.eclipse.virgo.kernel.userregionfactory/src/test/java/org/eclipse/virgo/kernel/userregionfactory/PackageImportWildcardExpanderTests.java
index 62050d61..c3896e69 100644
--- a/org.eclipse.virgo.kernel.userregionfactory/src/test/java/org/eclipse/virgo/kernel/userregionfactory/PackageImportWildcardExpanderTests.java
+++ b/org.eclipse.virgo.kernel.userregionfactory/src/test/java/org/eclipse/virgo/kernel/userregionfactory/PackageImportWildcardExpanderTests.java
@@ -44,7 +44,6 @@ public class PackageImportWildcardExpanderTests {
this.mockEventLogger = createMock(EventLogger.class);
replay(this.mockEventLogger);
- this.stubBundleContext.registerService(EventLogger.class.getName(), this.mockEventLogger, null);
this.mockPackageAdmin = createMock(PackageAdmin.class);
this.exportedPackages = new ExportedPackage[] { createdMockExportedPackage("q"), createdMockExportedPackage("r.a"),
@@ -63,13 +62,13 @@ public class PackageImportWildcardExpanderTests {
@Test
public void testNoWildcards() {
- String expansion = PackageImportWildcardExpander.expandPackageImportsWildcards("p,r", this.stubBundleContext);
+ String expansion = PackageImportWildcardExpander.expandPackageImportsWildcards("p,r", this.stubBundleContext, mockEventLogger);
assertEquals("Incorrect expansion", "p,r", expansion);
}
@Test
public void testWildcards() {
- String expansion = PackageImportWildcardExpander.expandPackageImportsWildcards("r.*", this.stubBundleContext);
+ String expansion = PackageImportWildcardExpander.expandPackageImportsWildcards("r.*", this.stubBundleContext, mockEventLogger);
assertEquals("Incorrect expansion", "r.a,r.b.c", expansion);
}

Back to the top