Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2011-03-08 17:40:34 -0500
committerGlyn Normington2011-03-08 17:40:34 -0500
commitff162a9d83339f67d5dfa38049c72e6bca0d561d (patch)
tree82df2590644b2b772a1fa6d8e19cec3637520862 /org.eclipse.virgo.kernel.userregionfactory
parent872a13f91cbb586989e73b7776dcf992a6f7c48b (diff)
downloadorg.eclipse.virgo.kernel-ff162a9d83339f67d5dfa38049c72e6bca0d561d.tar.gz
org.eclipse.virgo.kernel-ff162a9d83339f67d5dfa38049c72e6bca0d561d.tar.xz
org.eclipse.virgo.kernel-ff162a9d83339f67d5dfa38049c72e6bca0d561d.zip
- make RegionFilter an inteface
- add createRegionFilter to RegionDigraph - tidy up StandardRegionFilter code
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.java34
-rw-r--r--org.eclipse.virgo.kernel.userregionfactory/src/test/java/org/eclipse/virgo/kernel/userregionfactory/UserRegionPackageImportPolicyTests.java114
2 files changed, 14 insertions, 134 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 5bbf0af4..8107a18f 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
@@ -161,10 +161,10 @@ public final class Activator implements BundleActivator {
Region userRegion = regionDigraph.createRegion(REGION_USER);
userRegion.addBundle(userRegionFactoryBundle);
- RegionFilter kernelFilter = createKernelFilter(systemBundleContext, eventLogger);
+ RegionFilter kernelFilter = createKernelFilter(regionDigraph, systemBundleContext, eventLogger);
userRegion.connectRegion(kernelRegion, kernelFilter);
- RegionFilter userRegionFilter = createUserRegionFilter();
+ RegionFilter userRegionFilter = createUserRegionFilter(regionDigraph);
kernelRegion.connectRegion(userRegion, userRegionFilter);
notifyUserRegionStarting(userRegionBundleContext);
@@ -175,39 +175,33 @@ public final class Activator implements BundleActivator {
publishUserRegionBundleContext(userRegionBundleContext);
}
- private RegionFilter createUserRegionFilter() throws BundleException {
- RegionFilter userRegionFilter = new RegionFilter();
+ private RegionFilter createUserRegionFilter(RegionDigraph digraph) throws InvalidSyntaxException {
+ Map<String, Collection<String>> policy = new HashMap<String, Collection<String>>();
Collection<String> serviceFilter = classesToFilter(this.regionServiceExports);
- try {
- userRegionFilter.setFilters(RegionFilter.VISIBLE_SERVICE_NAMESPACE, serviceFilter);
- } catch (InvalidSyntaxException e) {
- throw new BundleException("Invalid " + USER_REGION_SERVICE_EXPORTS_PROPERTY + "in user region configuration: '"
- + this.regionServiceExports + "'", e);
- }
-
- return userRegionFilter;
+ policy.put(RegionFilter.VISIBLE_SERVICE_NAMESPACE, serviceFilter);
+ return digraph.createRegionFilter(policy);
}
private Region getKernelRegion(RegionDigraph regionDigraph) {
return regionDigraph.iterator().next();
}
- private RegionFilter createKernelFilter(BundleContext systemBundleContext, EventLogger eventLogger) throws BundleException, InvalidSyntaxException {
- RegionFilter kernelFilter = new RegionFilter();
- allowImportedBundles(kernelFilter, eventLogger);
- kernelFilter.setFilters(RegionFilter.VISIBLE_PACKAGE_NAMESPACE, createUserRegionPackageImportPolicy(systemBundleContext));
+ private RegionFilter createKernelFilter(RegionDigraph digraph, BundleContext systemBundleContext, EventLogger eventLogger) throws BundleException, InvalidSyntaxException {
+ Map<String, Collection<String>> policy = new HashMap<String, Collection<String>>();
+ allowImportedBundles(policy, eventLogger);
+ policy.put(RegionFilter.VISIBLE_PACKAGE_NAMESPACE, createUserRegionPackageImportPolicy(systemBundleContext));
Collection<String> serviceFilter = classesToFilter(this.regionServiceImports);
- kernelFilter.setFilters(RegionFilter.VISIBLE_SERVICE_NAMESPACE, serviceFilter);
- return kernelFilter;
+ policy.put(RegionFilter.VISIBLE_SERVICE_NAMESPACE, serviceFilter);
+ return digraph.createRegionFilter(policy);
}
- private void allowImportedBundles(RegionFilter kernelFilter, EventLogger eventLogger) throws InvalidSyntaxException {
+ private void allowImportedBundles(Map<String, Collection<String>> policy, EventLogger eventLogger) {
String userRegionBundleImports = this.regionBundleImports != null ? this.regionBundleImports
: this.bundleContext.getProperty(USER_REGION_BUNDLE_IMPORTS_PROPERTY);
RequireBundle bundleImportsAsRequireBundle = representBundleImportsAsRequireBundle(userRegionBundleImports, eventLogger);
Collection<String> importedBundles = importBundleToFilter(bundleImportsAsRequireBundle.getRequiredBundles());
- kernelFilter.setFilters(RegionFilter.VISIBLE_BUNDLE_NAMESPACE, importedBundles);
+ policy.put(RegionFilter.VISIBLE_BUNDLE_NAMESPACE, importedBundles);
}
private RequireBundle representBundleImportsAsRequireBundle(String userRegionBundleImportsProperty, EventLogger eventLogger) {
diff --git a/org.eclipse.virgo.kernel.userregionfactory/src/test/java/org/eclipse/virgo/kernel/userregionfactory/UserRegionPackageImportPolicyTests.java b/org.eclipse.virgo.kernel.userregionfactory/src/test/java/org/eclipse/virgo/kernel/userregionfactory/UserRegionPackageImportPolicyTests.java
deleted file mode 100644
index 4adbca53..00000000
--- a/org.eclipse.virgo.kernel.userregionfactory/src/test/java/org/eclipse/virgo/kernel/userregionfactory/UserRegionPackageImportPolicyTests.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*******************************************************************************
- * This file is part of the Virgo Web Server.
- *
- * Copyright (c) 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:
- * SpringSource, a division of VMware - initial API and implementation and/or initial documentation
- *******************************************************************************/
-
-package org.eclipse.virgo.kernel.userregionfactory;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.junit.Assert;
-import org.junit.Test;
-import org.osgi.framework.Version;
-import org.osgi.framework.wiring.BundleRevision;
-
-public class UserRegionPackageImportPolicyTests {
-/*
- @Test
- public void testNullPackageString() {
- new UserRegionPackageImportPolicy(null);
- }
-
- @Test
- public void testEmptyPackageString() {
- new UserRegionPackageImportPolicy("");
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testWildcard() {
- new UserRegionPackageImportPolicy("*");
- }
-
- @Test
- public void testPackageStringWithArbitraryAttribute() {
- UserRegionPackageImportPolicy userRegionPackageImportPolicy = createUserRegionPackageImportPolicy("p;pa=pv,q");
- Assert.assertFalse(userRegionPackageImportPolicy.isImported("p", null, null));
- Map<String, Object> attributes = createAttributes("p");
- attributes.put("pa", "pv");
- Assert.assertTrue(userRegionPackageImportPolicy.isImported("p", attributes, null));
-
- }
-
- private UserRegionPackageImportPolicy createUserRegionPackageImportPolicy(String regionImports) {
- UserRegionPackageImportPolicy userRegionPackageImportPolicy = new UserRegionPackageImportPolicy(regionImports);
- return userRegionPackageImportPolicy;
- }
-
- @Test
- public void testPackageStringWithoutArbitraryAttribute() {
- RegionPackageImportPolicy userRegionPackageImportPolicy = createUserRegionPackageImportPolicy("p,q");
- Map<String, Object> attributes = createAttributes("p");
- attributes.put("pa", "pv");
- Assert.assertTrue(userRegionPackageImportPolicy.isImported("p", attributes, null));
-
- }
-
- private Map<String, Object> createAttributes(String packageName) {
- Map<String, Object> attributes = new HashMap<String, Object>();
- attributes.put(BundleRevision.PACKAGE_NAMESPACE, packageName);
- return attributes;
- }
-
- @Test
- public void testPackageStringWithMandatoryAttribute() {
- RegionPackageImportPolicy userRegionPackageImportPolicy = createUserRegionPackageImportPolicy("p;pa=pv");
- Assert.assertFalse(userRegionPackageImportPolicy.isImported("p", null, null));
- Map<String, Object> attributes = createAttributes("p");
- attributes.put("pa", "pv");
- Map<String, String> directives = createMandatoryDirective("pa");
- Assert.assertTrue(userRegionPackageImportPolicy.isImported("p", attributes, directives));
- }
-
- @Test
- public void testPackageStringWithoutMandatoryAttribute() {
- RegionPackageImportPolicy userRegionPackageImportPolicy = createUserRegionPackageImportPolicy("p");
- Map<String, Object> attributes = createAttributes("p");
- attributes.put("pa", "pv");
- Map<String, String> directives = createMandatoryDirective("pa");
- Assert.assertFalse(userRegionPackageImportPolicy.isImported("p", attributes, directives));
- }
-
- private Map<String, String> createMandatoryDirective(String attributes) {
- Map<String, String> directives = new HashMap<String, String>();
- directives.put("mandatory", attributes);
- return directives;
- }
-
- @Test
- public void testPackageStringWithVersion() {
- RegionPackageImportPolicy userRegionPackageImportPolicy = createUserRegionPackageImportPolicy("p;version=2,q");
- Assert.assertFalse(userRegionPackageImportPolicy.isImported("p", null, null));
- Map<String, Object> attributes = new HashMap<String, Object>();
- attributes.put("version", new Version("2.0.0"));
- Assert.assertTrue(userRegionPackageImportPolicy.isImported("p", attributes, null));
-
- }
-
- @Test
- public void testPackages() {
- RegionPackageImportPolicy userRegionPackageImportPolicy = createUserRegionPackageImportPolicy("p,q");
- Assert.assertTrue(userRegionPackageImportPolicy.isImported("p", null, null));
- Assert.assertTrue(userRegionPackageImportPolicy.isImported("q", null, null));
- Assert.assertFalse(userRegionPackageImportPolicy.isImported("r", null, null));
- }
-*/
-}

Back to the top