aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g..@apache.org
Subject svn commit: r1102244 [3/4] - in /aries/trunk/subsystem: subsystem-api/ subsystem-api/src/main/java/org/apache/aries/subsystem/ subsystem-api/src/main/java/org/apache/aries/subsystem/spi/ subsystem-core/ subsystem-core/src/main/java/org/apache/aries/sub...
Date Thu, 12 May 2011 11:27:13 GMT
Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResourceProcessor.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResourceProcessor.java?rev=1102244&r1=1102243&r2=1102244&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResourceProcessor.java (original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResourceProcessor.java Thu May 12 11:27:11 2011
@@ -28,31 +28,28 @@ import static org.osgi.framework.Constan
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.InputStream;
+import java.net.URL;
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-import java.util.jar.Attributes;
 import java.util.jar.JarFile;
 import java.util.jar.Manifest;
 
 import org.apache.aries.application.utils.manifest.ManifestHeaderProcessor;
 import org.apache.aries.subsystem.Subsystem;
-import org.apache.aries.subsystem.SubsystemAdmin;
 import org.apache.aries.subsystem.SubsystemConstants;
 import org.apache.aries.subsystem.SubsystemException;
-import org.apache.aries.subsystem.scope.Scope;
-import org.apache.aries.subsystem.scope.ScopeUpdate;
-import org.apache.aries.subsystem.scope.SharePolicy;
+import org.apache.aries.subsystem.core.ResourceResolver;
 import org.apache.aries.subsystem.spi.Resource;
+import org.apache.aries.subsystem.spi.ResourceOperation;
 import org.apache.aries.subsystem.spi.ResourceProcessor;
-import org.apache.aries.subsystem.spi.ResourceResolver;
 import org.apache.felix.utils.manifest.Clause;
 import org.apache.felix.utils.manifest.Parser;
+import org.eclipse.equinox.region.Region;
+import org.eclipse.equinox.region.RegionFilter;
+import org.eclipse.equinox.region.RegionFilterBuilder;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
 import org.osgi.framework.Filter;
@@ -60,442 +57,50 @@ import org.osgi.framework.FrameworkUtil;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.Version;
 import org.osgi.framework.wiring.BundleRevision;
+import org.osgi.service.coordinator.Coordination;
+import org.osgi.service.coordinator.Participant;
 import org.osgi.util.tracker.ServiceTracker;
 
 public class SubsystemResourceProcessor implements ResourceProcessor {
-
-    private static final Version SUBSYSTEM_MANIFEST_VERSION = new Version("1.0");
-
-    public SubsystemSession createSession(SubsystemAdmin subsystemAdmin) {
-        return new SubsystemSession(subsystemAdmin);
-    }
-
-    public static class SubsystemSession implements Session {
-
-        private static final long TIMEOUT = 30000;
-        private final SubsystemAdmin subsystemAdmin;
-
-        private final Map<Resource, Subsystem> installed = new HashMap<Resource, Subsystem>();
-        /*
-         * Map to keep track of composite bundle headers before the update and
-         * the updated composite bundle. This is needed for rollback
-         */
-        private final Map<Map<String, String>, Subsystem> updated = new HashMap<Map<String, String>, Subsystem>();
-        private final Map<Resource, Subsystem> removed = new HashMap<Resource, Subsystem>();
-        private final List<Subsystem> stopped = new ArrayList<Subsystem>();
-        private final Map<String, ServiceTracker> trackers = new HashMap<String, ServiceTracker>();
-        private final Map<SubsystemAdmin, Map<String, Session>> sessions = new HashMap<SubsystemAdmin, Map<String, Session>>();
-        private final BundleContext context;
-        
-        public SubsystemSession(SubsystemAdmin subsystemAdmin) {
-            this.subsystemAdmin = subsystemAdmin;
-            this.context = Activator.getBundleContext();
-        }
-
-        /**
-         * internal used in this class only. When a manifest is passed in, we
-         * won't attempt to read the manifest from the resource
-         * 
-         * @param res
-         * @param manifest
-         */
-        private void process(Resource res, Manifest manifest) {
-
-            try {
-                SubsystemAdminImpl adminImpl = (SubsystemAdminImpl)subsystemAdmin;
-                Scope admin = adminImpl.getScopeAdmin();
-                ResourceResolver resolver = getService(ResourceResolver.class);
-
-                if (manifest == null) {
-                    // Unpack the subsystem archive into a temporary directory
-                    File dir = File.createTempFile("subsystem", "", null);
-                    if (dir == null || !dir.delete() || !dir.mkdir()) {
-                        throw new Exception("Unable to create temporary dir");
-                    }
-                    FileUtils.unpackArchive(res.open(), dir);
-
-                    manifest = new Manifest();
-                    InputStream mis = new FileInputStream(new File(dir,
-                            JarFile.MANIFEST_NAME));
-                    try {
-                        manifest.read(mis);
-                    } finally {
-                        closeQuietly(mis);
-                    }
-
-                }
-
-                List<Resource> resource = new ArrayList<Resource>();
-                String resourceHeader = manifest.getMainAttributes().getValue(
-                        SUBSYSTEM_RESOURCES);
-                Clause[] resourceClauses = Parser.parseHeader(resourceHeader);
-                for (Clause c : resourceClauses) {
-                    Resource r = resolver.find(c.toString());
-                    resource.add(r);
-                }
-
-                List<Resource> content = new ArrayList<Resource>();
-                String contentHeader = manifest.getMainAttributes().getValue(
-                        SUBSYSTEM_CONTENT);
-                Clause[] contentClauses = Parser.parseHeader(contentHeader);
-                for (Clause c : contentClauses) {
-                    Resource r = resolver.find(c.toString());
-                    content.add(r);
-                }
-
-                List<Resource> previous = new ArrayList<Resource>();
-
-                // TODO: convert resources before calling the resolver?
-
-                List<Resource> additional = resolver.resolve(content, resource);
-
-                // check manifest header to see if they are valid
-                String ssn = manifest.getMainAttributes().getValue(
-                        SUBSYSTEM_SYMBOLICNAME);
-                String sv = manifest.getMainAttributes().getValue(
-                        SUBSYSTEM_VERSION);
-                checkManifestHeaders(manifest, ssn, sv);
-
-                Map<String, String> headers = computeSubsystemHeaders(manifest,
-                        ssn, sv);
-
-                // Check existing bundles
-                Subsystem subsystem = findSubsystem(res);
-                ScopeUpdate scopeUpdate = admin.newScopeUpdate();
-                ScopeUpdate childScopeUpdate;
-                if (subsystem == null) {
-                    // brand new install
-
-                    childScopeUpdate = scopeUpdate.newChild(headers.get(Constants.BUNDLE_SYMBOLICNAME) + "_" + headers.get(Constants.BUNDLE_VERSION), res.getLocation());
-                    Map<String, List<SharePolicy>> exportSharePolicies = childScopeUpdate.getSharePolicies(SharePolicy.TYPE_EXPORT);
-                    Map<String, List<SharePolicy>> importSharePolicies = childScopeUpdate.getSharePolicies(SharePolicy.TYPE_IMPORT);
-                    
-                    setupSharePolicies(exportSharePolicies, importSharePolicies, headers);
-                    scopeUpdate.commit();
-                    
-      //              ScopeAdmin childScopeAdmin = getService(ScopeAdmin.class, "ScopeId=" + childScopeUpdate.getScope().getId());
-      
-                    Scope childScopeAdmin = childScopeUpdate.getScope();
-                    
-                    subsystem = new SubsystemImpl(childScopeUpdate.getScope(), headers);
-                    SubsystemAdmin childSubsystemAdmin = new SubsystemAdminImpl(childScopeAdmin, subsystem, subsystemAdmin.getSubsystem());
-                    context.registerService(SubsystemAdmin.class.getName(), childSubsystemAdmin, DictionaryBuilder.build("SubsystemParentId", childSubsystemAdmin.getParentSubsystem().getSubsystemId(), "SubsystemId", subsystem.getSubsystemId()));
-                    
-                    installed.put(res, subsystem);
-                    
-                    
-                } else {
-                    // update
-                    // capture data before update
-                    Map<String, String> subsystemHeaders = subsystem.getHeaders();
-                    String previousContentHeader = (String) subsystemHeaders.get(SUBSYSTEM_CONTENT);
-                    Clause[] previousContentClauses = Parser
-                            .parseHeader(previousContentHeader);
-                    for (Clause c : previousContentClauses) {
-                        Resource r = resolver.find(c.toString());
-                        previous.add(r);
-                    }
-                    
-                    subsystem.updateHeaders(headers);
-                    updated.put(subsystemHeaders, subsystem);
-                }
-
-                // content is installed in the scope, so need to find the subsystemAdmin for the scope first
-                long scopeId = subsystem.getSubsystemId();
-                SubsystemAdmin childAdmin = getService(SubsystemAdmin.class, "SubsystemId=" + scopeId);
-                
-                for (Resource r : previous) {
-                    boolean stillHere = false;
-                    for (Resource r2 : content) {
-                        if (r2.getSymbolicName().equals(r.getSymbolicName())
-                                && r2.getVersion().equals(r.getVersion())) {
-                            stillHere = true;
-                            break;
-                        }
-                    }
-                    if (!stillHere) {
-                        getSession(childAdmin,
-                                r.getType()).dropped(r);
-                    }
-                }
-                
-                // additional resource is installed outside of the subsystem.
-                for (Resource r : additional) {
-                    getSession(subsystemAdmin, r.getType()).process(r);
-                }
-                
-
-                for (Resource r : content) {
-                    getSession(childAdmin, r.getType())
-                            .process(r);
-                }
-
-            } catch (SubsystemException e) {
-                throw e;
-            } catch (Exception e) {
-                throw new SubsystemException("Unable to process subsystem", e);
-            }
-        }
-
-        private void setupSharePolicies(
-                Map<String, List<SharePolicy>> exportSharePolicies,
-                Map<String, List<SharePolicy>> importSharePolicies,
-                Map<String, String> headers) {
-            String importPackage = headers.get(SubsystemConstants.SUBSYSTEM_IMPORTPACKAGE);
-            String exportPackage = headers.get(SubsystemConstants.SUBSYSTEM_EXPORTPACKAGE);
-            String importService = headers.get(SubsystemConstants.SUBSYSTEM_IMPORTSERVICE);
-            String exportService = headers.get(SubsystemConstants.SUBSYSTEM_EXPORTSERVICE);
-            if (importPackage != null && !importPackage.trim().isEmpty()) {
-                List<SharePolicy> importPackagePolicies = importSharePolicies.get(BundleRevision.PACKAGE_NAMESPACE);
-                if (importPackagePolicies == null) {
-                    importPackagePolicies = new ArrayList<SharePolicy>();
-                    importSharePolicies.put(BundleRevision.PACKAGE_NAMESPACE,importPackagePolicies);
-                }
-                
-                importPackagePolicies.add(new SharePolicy(SharePolicy.TYPE_IMPORT, BundleRevision.PACKAGE_NAMESPACE, createFilter(importPackage, BundleRevision.PACKAGE_NAMESPACE)));
-            }
-            
-            if (importService != null && !importService.trim().isEmpty()) {
-                List<SharePolicy> importServicePolicies = importSharePolicies.get("scope.share.service");
-                if (importServicePolicies == null) {
-                    importServicePolicies = new ArrayList<SharePolicy>();
-                    importSharePolicies.put("scope.share.service",importServicePolicies);
-                }
-                
-                importServicePolicies.add(new SharePolicy(SharePolicy.TYPE_IMPORT, "scope.share.service", createFilter(importService, "scope.share.service")));
-            }
-            
-        }
-        
-        private Filter createFilter(String packages, String namespace) {
-            if (namespace.equals(BundleRevision.PACKAGE_NAMESPACE)) {
-                // split packages
-                List<String> pkgs = ManifestHeaderProcessor.split(packages, ",");
-                StringBuffer sb = new StringBuffer();
-                sb.append("(|");
-                for (String pkg : pkgs) {
-                    sb.append("(" + BundleRevision.PACKAGE_NAMESPACE + "=" + pkg + ")");
-                }
-                sb.append(")");
-                try {
-                    return FrameworkUtil.createFilter(sb.toString());
-                } catch (InvalidSyntaxException e) {
-                    // TODO Auto-generated catch block
-                    e.printStackTrace();
-                }
-                
-            }
-            if (namespace.equals("scope.share.service")) {
-                // split packages
-                List<String> pkgs = ManifestHeaderProcessor.split(packages, ",");
-                StringBuffer sb = new StringBuffer();
-                sb.append("(|");
-                for (String pkg : pkgs) {
-                    sb.append("(scope.share.service=" + pkg + ")");
-                }
-                sb.append(")");
-                try {
-                    return FrameworkUtil.createFilter(sb.toString());
-                } catch (InvalidSyntaxException e) {
-                    // TODO Auto-generated catch block
-                    e.printStackTrace();
-                }
-            }
-            
-            
-            return null;
-        }
-
-        public void process(Resource res) throws SubsystemException {
-            process(res, null);
-
-        }
-
-        public void dropped(Resource res) throws SubsystemException {
-            Subsystem subsystem = findSubsystem(res);
-            if (subsystem == null) {
-                throw new SubsystemException(
-                        "Unable to find matching subsystem to uninstall");
-            }
-            // TODO: iterate through all resources and ask for a removal on
-            // each one
-            subsystemAdmin.uninstall(subsystem);
-            removed.put(res, subsystem);
-
-        }
-
-        protected Subsystem findSubsystem(Resource resource) {
-            for (Subsystem subsystem : this.subsystemAdmin.getSubsystems()) {
-                if (resource.getLocation().equals(subsystem.getLocation())) {
-                    return subsystem;
-                }
-            }
-            return null;
-        }
-
-        public void prepare() throws SubsystemException {
-            for (Map<String, Session> sm : sessions.values()) {
-                for (Session s : sm.values()) {
-                    s.prepare();
-                }
-            }
-            for (Subsystem subsystem : stopped) {
-                subsystem.start();  
-            }
-        }
-
-        public void commit() {
-            for (Map<String, Session> sm : sessions.values()) {
-                for (Session s : sm.values()) {
-                    s.commit();
-                }
-            }
-            installed.clear();
-            updated.clear();
-            removed.clear();
-            closeTrackers();
-        }
-
-        public void rollback() {
-
-            for (Subsystem subsystem : installed.values()) {
-                subsystemAdmin.uninstall(subsystem);
-            }
-            installed.clear();
-
-            // Handle updated subsystems
-            Set<Map.Entry<Map<String, String>, Subsystem>> updatedSet = updated
-                    .entrySet();
-            for (Entry<Map<String, String>, Subsystem> entry : updatedSet) {
-                Map<String, String> oldHeader = entry.getKey();
-                Subsystem subsystem = entry.getValue();
-
-                // let's build a Manifest from oldDict
-                Manifest manifest = new Manifest();
-                Attributes attributes = manifest.getMainAttributes();
-                attributes.putAll(oldHeader);
-                String symbolicName = attributes
-                        .getValue(Constants.BUNDLE_SYMBOLICNAME);
-                Version v = Version.parseVersion(attributes
-                        .getValue(Constants.BUNDLE_VERSION));
-                Resource subsystemResource = new ResourceImpl(symbolicName, v,
-                        SubsystemConstants.RESOURCE_TYPE_SUBSYSTEM, subsystem
-                                .getLocation(), Collections
-                                .<String, String> emptyMap());
-                try {
-                    Session session = getSession(subsystemAdmin, subsystemResource
-                            .getType());
-                    if (session instanceof SubsystemSession) {
-                        ((SubsystemSession) session).process(subsystemResource,
-                                manifest);
-                    } else {
-                        throw new SubsystemException(
-                                "Invalid subsystem session - Unable to rollback subsystem");
-                    }
-                } catch (SubsystemException e) {
-                    throw e;
-                } catch (Exception e) {
-                    throw new SubsystemException(
-                            "Unable to rollback subsystem", e);
-                }
-
-            }
-
-            // handle uninstalled subsystem
-            Set<Map.Entry<Resource, Subsystem>> set = removed.entrySet();
-            for (Map.Entry<Resource, Subsystem> entry : set) {
-                Resource res = entry.getKey();
-                try {
-                    getSession(subsystemAdmin, res.getType()).process(res);
-                } catch (SubsystemException e) {
-                    throw e;
-                } catch (Exception e) {
-                    throw new SubsystemException(
-                            "Unable to rollback subsystem", e);
-                }
-            }
-
-            removed.clear();
-
-            for (Map<String, Session> sm : sessions.values()) {
-                for (Session s : sm.values()) {
-                    s.rollback();
-                }
-            }
-
-            closeTrackers();
-        }
-
-        protected Session getSession(SubsystemAdmin admin, String type)
-                throws InvalidSyntaxException, InterruptedException {
-            Map<String, Session> sm = this.sessions.get(admin);
-            if (sm == null) {
-                sm = new HashMap<String, Session>();
-                this.sessions.put(admin, sm);
-            }
-            Session session = sm.get(type);
-            if (session == null) {
-                session = getProcessor(type).createSession(admin);
-                sm.put(type, session);
-            }
-            return session;
-        }
-
-        protected ResourceProcessor getProcessor(String type)
-                throws InvalidSyntaxException, InterruptedException {
-            return getService(ResourceProcessor.class,
-                    SubsystemConstants.SERVICE_RESOURCE_TYPE + "=" + type);
-        }
-
-        protected <T> T getService(Class<T> clazz)
-                throws InvalidSyntaxException, InterruptedException {
-            return getService(clazz, null);
-        }
-
-        protected <T> T getService(Class<T> clazz, String filter)
-                throws InvalidSyntaxException, InterruptedException {
-            Filter flt;
-            if (filter != null) {
-                if (!filter.startsWith("(")) {
-                    flt = context.createFilter("(&(" + Constants.OBJECTCLASS
-                            + "=" + clazz.getName() + ")(" + filter + "))");
-                } else {
-                    flt = context.createFilter("(&(" + Constants.OBJECTCLASS
-                            + "=" + clazz.getName() + ")" + filter + ")");
-                }
-            } else {
-                flt = context.createFilter("(" + Constants.OBJECTCLASS + "="
-                        + clazz.getName() + ")");
-            }
-            ServiceTracker tracker = trackers.get(flt.toString());
-            if (tracker == null) {
-                tracker = new ServiceTracker(context, flt, null);
-                tracker.open();
-                trackers.put(flt.toString(), tracker);
-            }
-            T t = (T) tracker.waitForService(TIMEOUT);
-            if (t == null) {
-                throw new SubsystemException("No service available: " + flt);
-            }
-            return t;
-        }
-
-        private void closeTrackers() {
-            for (ServiceTracker t : trackers.values()) {
-                t.close();
-            }
-            trackers.clear();
-        }
-    }
-
-    private static void checkManifestHeaders(Manifest manifest, String ssn,
-            String sv) {
+	private static final Version SUBSYSTEM_MANIFEST_VERSION = new Version("1.0");
+	private static final long TIMEOUT = 30000;
+	
+	private final BundleContext bundleContext;
+	private final Map<Resource, Subsystem> installed = new HashMap<Resource, Subsystem>();
+	private final Map<String, ServiceTracker> trackers = new HashMap<String, ServiceTracker>();
+	private final Map<Map<String, String>, Subsystem> updated = new HashMap<Map<String, String>, Subsystem>();
+	
+	public SubsystemResourceProcessor(BundleContext bundleContext) {
+		this.bundleContext = bundleContext;
+	}
+	
+	public void process(final ResourceOperation operation) throws SubsystemException {
+		switch (operation.getType()) {
+		case INSTALL:
+			installOrUpdate(operation);
+			break;
+		case START:
+			start(operation);
+			break;
+		case STOP:
+			stop(operation);
+			break;
+		case UNINSTALL:
+			uninstall(operation);
+			break;
+		case UPDATE:
+			installOrUpdate(operation);
+			break;
+		default:
+			throw new SubsystemException("Unsupported resource opertaion type: " + operation.getType());
+	}
+	}
+	
+    private static void checkManifestHeaders(Manifest manifest, String ssn, String sv) {
         // Check subsystem manifest required headers
-        String mfv = manifest.getMainAttributes().getValue(
-                SUBSYSTEM_MANIFESTVERSION);
+        String mfv = manifest.getMainAttributes().getValue(SUBSYSTEM_MANIFESTVERSION);
         if (mfv == null || mfv.length() == 0) {
-            throw new SubsystemException("Invalid subsystem manifest version: "
-                    + mfv);
+            throw new SubsystemException("Invalid subsystem manifest version: " + mfv);
         }
         try {
             Version v = Version.parseVersion(mfv);
@@ -506,14 +111,12 @@ public class SubsystemResourceProcessor 
                                 + SubsystemConstants.SUBSYSTEM_MANIFESTVERSION
                                 + " is " + SUBSYSTEM_MANIFEST_VERSION);
             }
-        } catch (IllegalArgumentException e) {
-            throw new SubsystemException("Invalid subsystem manifest version: "
-                    + mfv, e);
+        } 
+        catch (IllegalArgumentException e) {
+            throw new SubsystemException("Invalid subsystem manifest version: " + mfv, e);
         }
-
         if (ssn == null || ssn.length() == 0) {
-            throw new SubsystemException("Invalid subsystem symbolic name: "
-                    + ssn);
+            throw new SubsystemException("Invalid subsystem symbolic name: " + ssn);
         }
         // check attributes / directives on the subsystem symbolic name
         // TODO add any other symbolic name to check
@@ -524,38 +127,20 @@ public class SubsystemResourceProcessor 
                     + " directive in " + SUBSYSTEM_SYMBOLICNAME + ": "
                     + ssDirective);
         }
-
         if (sv == null || sv.length() == 0) {
             throw new SubsystemException("Invalid subsystem version: " + sv);
         }
         try {
             new Version(sv);
-        } catch (IllegalArgumentException e) {
+        } 
+        catch (IllegalArgumentException e) {
             throw new SubsystemException("Invalid subsystem version: " + sv, e);
         }
-
         // TODO: do we want to check other headers such as
         // subsystem-importpackage, subsystem-exportpackage, etc.
-
-    }
-
-    // if the ssn already contains COMPOSITE_DIRECTIVE or SUBSYSTEM_DIRECTIVE
-    // directive
-    // let's not add them again
-    private static String getSubsystemSymbolicName(String ssn) {
-        Clause[] ssnClauses = Parser.parseHeader(ssn);
-        String ssDirective = ssnClauses[0].getDirective(SUBSYSTEM_DIRECTIVE);
-
-        if (ssDirective == null ) {
-            ssn = ssn + ";"
-                    + SUBSYSTEM_DIRECTIVE + ":=true";
-        } 
-
-        return ssn;
     }
-
-    private static Map<String, String> computeSubsystemHeaders(
-            Manifest manifest, String ssn, String sv) {
+    
+	private static Map<String, String> computeSubsystemHeaders(Manifest manifest, String ssn, String sv) {
         // Grab all headers
         Map<String, String> headers = new HashMap<String, String>();
         Iterator it = manifest.getMainAttributes().entrySet().iterator();
@@ -565,24 +150,346 @@ public class SubsystemResourceProcessor 
             String value = e.getValue().toString();
             headers.put(name, value);
         }
-
         // Create the required composite headers
         headers.put(BUNDLE_SYMBOLICNAME, getSubsystemSymbolicName(ssn));
         headers.put(BUNDLE_VERSION, sv);
-
         String subImportPkg = headers.get(SUBSYSTEM_IMPORTPACKAGE);
         String subExportPkg = headers.get(SUBSYSTEM_EXPORTPACKAGE);
-
-
         // TODO: compute other composite manifest entries
         // TODO: compute list of bundles
-
         return headers;
     }
-
-    public Session createSession(BundleContext arg0) {
-        // TODO Auto-generated method stub
+	
+    private Filter createFilter(String packages, String namespace) {
+        if (namespace.equals(BundleRevision.PACKAGE_NAMESPACE)) {
+            // split packages
+            List<String> pkgs = ManifestHeaderProcessor.split(packages, ",");
+            StringBuffer sb = new StringBuffer();
+            sb.append("(|");
+            for (String pkg : pkgs) {
+                sb.append("(" + BundleRevision.PACKAGE_NAMESPACE + "=" + pkg + ")");
+            }
+            sb.append(")");
+            try {
+                return FrameworkUtil.createFilter(sb.toString());
+            } 
+            catch (InvalidSyntaxException e) {
+                // TODO Auto-generated catch block
+                e.printStackTrace();
+            }
+        }
+        if (namespace.equals("scope.share.service")) {
+            // split packages
+            List<String> pkgs = ManifestHeaderProcessor.split(packages, ",");
+            StringBuffer sb = new StringBuffer();
+            sb.append("(|");
+            for (String pkg : pkgs) {
+                sb.append("(scope.share.service=" + pkg + ")");
+            }
+            sb.append(")");
+            try {
+                return FrameworkUtil.createFilter(sb.toString());
+            } 
+            catch (InvalidSyntaxException e) {
+                // TODO Auto-generated catch block
+                e.printStackTrace();
+            }
+        }
         return null;
     }
-
+	
+	private Subsystem findSubsystem(Resource resource, Subsystem s) {
+        for (Subsystem subsystem : s.getChildren()) {
+            if (resource.getAttributes().get(Resource.LOCATION_ATTRIBUTE).equals(subsystem.getLocation())) {
+                return subsystem;
+            }
+        }
+        return null;
+    }
+	
+	private Manifest getManifest(ResourceOperation operation) throws Exception {
+		Manifest manifest = (Manifest)operation.getContext().get("manifest");
+        if (manifest == null) {
+            // Unpack the subsystem archive into a temporary directory
+            File dir = File.createTempFile("subsystem", "", null);
+            if (dir == null || !dir.delete() || !dir.mkdir()) {
+                throw new Exception("Unable to create temporary dir");
+            }
+            String location = String.valueOf(operation.getResource().getAttributes().get(Resource.LOCATION_ATTRIBUTE));
+            FileUtils.unpackArchive(new URL(location).openStream(), dir);
+            manifest = new Manifest();
+            InputStream mis = new FileInputStream(new File(dir, JarFile.MANIFEST_NAME));
+            try {
+                manifest.read(mis);
+            } 
+            finally {
+                closeQuietly(mis);
+            }
+        }
+        return manifest;
+	}
+	
+	private <T> T getService(Class<T> clazz) throws InvalidSyntaxException, InterruptedException {
+		return getService(clazz, null);
+	}
+
+	private <T> T getService(Class<T> clazz, String filter) throws InvalidSyntaxException, InterruptedException {
+		Filter flt;
+		if (filter != null) {
+		    if (!filter.startsWith("(")) {
+		        flt = bundleContext.createFilter("(&(" + Constants.OBJECTCLASS
+		                + "=" + clazz.getName() + ")(" + filter + "))");
+		    } 
+		    else {
+		        flt = bundleContext.createFilter("(&(" + Constants.OBJECTCLASS
+		                + "=" + clazz.getName() + ")" + filter + ")");
+		    }
+		} 
+		else {
+		    flt = bundleContext.createFilter("(" + Constants.OBJECTCLASS + "="
+		            + clazz.getName() + ")");
+		}
+		ServiceTracker tracker = trackers.get(flt.toString());
+		if (tracker == null) {
+		    tracker = new ServiceTracker(bundleContext, flt, null);
+		    tracker.open();
+		    trackers.put(flt.toString(), tracker);
+		}
+		T t = (T) tracker.waitForService(TIMEOUT);
+		if (t == null) {
+		    throw new SubsystemException("No service available: " + flt);
+		}
+		return t;
+	}
+	
+	// if the ssn already contains COMPOSITE_DIRECTIVE or SUBSYSTEM_DIRECTIVE
+    // directive
+    // let's not add them again
+    private static String getSubsystemSymbolicName(String ssn) {
+        Clause[] ssnClauses = Parser.parseHeader(ssn);
+        String ssDirective = ssnClauses[0].getDirective(SUBSYSTEM_DIRECTIVE);
+        if (ssDirective == null ) {
+            ssn = ssn /*+ ";"
+                    + SUBSYSTEM_DIRECTIVE + ":=true"*/;
+        } 
+        return ssn;
+    }
+    
+    private void installOrUpdate(final ResourceOperation operation) {
+    	try {
+            SubsystemImpl subsystemInContext = (SubsystemImpl)operation.getContext().get("subsystem");
+            final Region subsystemInContextRegion = subsystemInContext.getRegion();
+            ResourceResolver resolver = getService(ResourceResolver.class);
+            Manifest manifest = getManifest(operation);
+            List<Resource> resource = new ArrayList<Resource>();
+            String resourceHeader = manifest.getMainAttributes().getValue(SUBSYSTEM_RESOURCES);
+            Clause[] resourceClauses = Parser.parseHeader(resourceHeader);
+            for (Clause c : resourceClauses) {
+                Resource r = resolver.find(c.toString());
+                resource.add(r);
+            }
+            List<Resource> content = new ArrayList<Resource>();
+            String contentHeader = manifest.getMainAttributes().getValue(SUBSYSTEM_CONTENT);
+            Clause[] contentClauses = Parser.parseHeader(contentHeader);
+            for (Clause c : contentClauses) {
+                Resource r = resolver.find(c.toString());
+                content.add(r);
+            }
+            List<Resource> previous = new ArrayList<Resource>();
+            // TODO: convert resources before calling the resolver?
+            List<Resource> additional = resolver.resolve(content, resource);
+            // check manifest header to see if they are valid
+            String ssn = manifest.getMainAttributes().getValue(SUBSYSTEM_SYMBOLICNAME);
+            String sv = manifest.getMainAttributes().getValue(SUBSYSTEM_VERSION);
+            checkManifestHeaders(manifest, ssn, sv);
+            Map<String, String> headers = computeSubsystemHeaders(manifest, ssn, sv);
+            // Check existing bundles
+            Subsystem subsystemToProcess = findSubsystem(operation.getResource(), subsystemInContext);
+            final Region childRegion;
+            if (subsystemToProcess == null) {
+                // brand new install
+            	String location = String.valueOf(operation.getResource().getAttributes().get(Resource.LOCATION_ATTRIBUTE));
+                childRegion = subsystemInContextRegion.getRegionDigraph().createRegion(headers.get(Constants.BUNDLE_SYMBOLICNAME) + "_" + headers.get(Constants.BUNDLE_VERSION));
+                setupSharePolicies(subsystemInContextRegion, childRegion, headers);
+  //              ScopeAdmin childScopeAdmin = getService(ScopeAdmin.class, "ScopeId=" + childScopeUpdate.getScope().getId());
+                subsystemToProcess = new SubsystemImpl(childRegion, headers, subsystemInContext, location);
+                bundleContext.registerService(Subsystem.class.getName(), subsystemToProcess, DictionaryBuilder.build("SubsystemParentId", subsystemInContext.getSubsystemId(), "SubsystemId", subsystemToProcess.getSubsystemId()));
+                installed.put(operation.getResource(), subsystemToProcess);
+            } 
+            else {
+            	childRegion = null;
+                // update
+                // capture data before update
+                Map<String, String> subsystemHeaders = subsystemToProcess.getHeaders();
+                String previousContentHeader = (String) subsystemHeaders.get(SUBSYSTEM_CONTENT);
+                Clause[] previousContentClauses = Parser.parseHeader(previousContentHeader);
+                for (Clause c : previousContentClauses) {
+                    Resource r = resolver.find(c.toString());
+                    previous.add(r);
+                }
+                ((SubsystemImpl)subsystemToProcess).updateHeaders(headers);
+                updated.put(subsystemHeaders, subsystemToProcess);
+            }
+            // content is installed in the scope, so need to find the subsystemAdmin for the scope first
+            long scopeId = subsystemToProcess.getSubsystemId();
+            Subsystem childSubsystem = getService(Subsystem.class, "SubsystemId=" + scopeId);
+            for (final Resource r : previous) {
+                boolean stillHere = false;
+                for (Resource r2 : content) {
+                    if (r2.getAttributes().get(Resource.SYMBOLIC_NAME_ATTRIBUTE).equals(r.getAttributes().get(Resource.SYMBOLIC_NAME_ATTRIBUTE))
+                            && r2.getAttributes().get(Resource.VERSION_ATTRIBUTE).equals(r.getAttributes().get(Resource.VERSION_ATTRIBUTE))) {
+                        stillHere = true;
+                        break;
+                    }
+                }
+                if (!stillHere) {
+                	// TODO Get this from the service registry.
+                	new BundleResourceProcessor(bundleContext).process(new ResourceOperation() {
+						public void completed() {
+							// TODO Send event.
+						}
+
+						public Coordination getCoordination() {
+							return operation.getCoordination();
+						}
+
+						public Resource getResource() {
+							return r;
+						}
+
+						public Map<String, Object> getContext() {
+							Map<String, Object> context = new HashMap<String, Object>();
+							context.put("region", childRegion == null ? subsystemInContextRegion : childRegion);
+							return context;
+						}
+
+						public Type getType() {
+							return Type.UNINSTALL;
+						}
+                	});
+                }
+            }
+            // additional resource is installed outside of the subsystem.
+            for (final Resource r : additional) {
+            	// TODO Get this from the service registry.
+            	new BundleResourceProcessor(bundleContext).process(new ResourceOperation() {
+					public void completed() {
+						// TODO Send event.
+					}
+
+					public Coordination getCoordination() {
+						return operation.getCoordination();
+					}
+
+					public Resource getResource() {
+						return r;
+					}
+
+					public Map<String, Object> getContext() {
+						Map<String, Object> context = new HashMap<String, Object>();
+						context.put("region", childRegion == null ? subsystemInContextRegion : childRegion);
+						return context;
+					}
+
+					public Type getType() {
+						return Type.INSTALL;
+					}
+            	});
+            }
+            for (final Resource r : content) {
+            	// TODO Get this from the service registry.
+            	new BundleResourceProcessor(bundleContext).process(new ResourceOperation() {
+					public void completed() {
+						// TODO Send event.
+					}
+
+					public Coordination getCoordination() {
+						return operation.getCoordination();
+					}
+
+					public Resource getResource() {
+						return r;
+					}
+
+					public Map<String, Object> getContext() {
+						Map<String, Object> context = new HashMap<String, Object>();
+						context.put("region", childRegion == null ? subsystemInContextRegion : childRegion);
+						return context;
+					}
+
+					public Type getType() {
+						return Type.INSTALL;
+					}
+            	});
+            }
+        } 
+        catch (Exception e) {
+            throw new SubsystemException("Unable to process subsystem", e);
+        }
+    }
+    
+    private void setupSharePolicies(Region parent, Region child, Map<String, String> headers) throws Exception {
+    	String importPackage = headers.get(SubsystemConstants.SUBSYSTEM_IMPORTPACKAGE);
+        String exportPackage = headers.get(SubsystemConstants.SUBSYSTEM_EXPORTPACKAGE);
+        String importService = headers.get(SubsystemConstants.SUBSYSTEM_IMPORTSERVICE);
+        String exportService = headers.get(SubsystemConstants.SUBSYSTEM_EXPORTSERVICE);
+        RegionFilterBuilder builder = child.getRegionDigraph().createRegionFilterBuilder();
+        if (importPackage != null && !importPackage.trim().isEmpty()) {
+        	builder.allow(RegionFilter.VISIBLE_PACKAGE_NAMESPACE, importPackage);
+        }
+        if (importService != null && !importService.trim().isEmpty()) {
+        	builder.allow(RegionFilter.VISIBLE_SERVICE_NAMESPACE, importService);
+        }
+        child.connectRegion(parent, builder.build());
+        builder = parent.getRegionDigraph().createRegionFilterBuilder();
+        if (exportPackage != null && !exportPackage.trim().isEmpty()) {
+        	builder.allow(RegionFilter.VISIBLE_PACKAGE_NAMESPACE, exportPackage);
+        }
+        if (exportService != null && !exportService.trim().isEmpty()) {
+        	builder.allow(RegionFilter.VISIBLE_SERVICE_NAMESPACE, exportService);
+        }
+        parent.connectRegion(child, builder.build());
+    }
+    
+    private void start(final ResourceOperation operation) {
+    	final Subsystem subsystem = (Subsystem)operation.getContext().get("subsystem");
+    	subsystem.start();
+    	operation.getCoordination().addParticipant(new Participant() {
+			public void ended(Coordination arg0) throws Exception {
+				operation.completed();
+			}
+
+			public void failed(Coordination arg0) throws Exception {
+				subsystem.stop();
+			}
+    	});
+    }
+    
+    private void stop(final ResourceOperation operation) {
+    	final Subsystem subsystem = (Subsystem)operation.getContext().get("subsystem");
+    	subsystem.stop();
+    	operation.getCoordination().addParticipant(new Participant() {
+			public void ended(Coordination arg0) throws Exception {
+				operation.completed();
+			}
+
+			public void failed(Coordination arg0) throws Exception {
+				subsystem.start();
+			}
+    	});
+    }
+    
+    private void uninstall(final ResourceOperation operation) {
+    	final Subsystem subsystem = (Subsystem)operation.getContext().get("subsystem");
+    	subsystem.uninstall();
+    	operation.getCoordination().addParticipant(new Participant() {
+			public void ended(Coordination arg0) throws Exception {
+				operation.completed();
+			}
+
+			public void failed(Coordination arg0) throws Exception {
+				// TODO Rollback?
+			}
+    	});
+    }
 }
\ No newline at end of file

Added: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemServiceFactory.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemServiceFactory.java?rev=1102244&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemServiceFactory.java (added)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemServiceFactory.java Thu May 12 11:27:11 2011
@@ -0,0 +1,32 @@
+package org.apache.aries.subsystem.core.internal;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.aries.subsystem.Subsystem;
+import org.eclipse.equinox.region.Region;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceFactory;
+import org.osgi.framework.ServiceRegistration;
+
+public class SubsystemServiceFactory implements ServiceFactory<Subsystem> {
+	private final Map<Bundle, Subsystem> bundlesToSubsystems = new HashMap<Bundle, Subsystem>();
+	private final Subsystem rootSubsystem;
+	
+	public SubsystemServiceFactory(Region region) {
+		rootSubsystem = new RootSubsystem(region);
+	}
+	
+	public Subsystem getService(Bundle bundle, ServiceRegistration<Subsystem> registration) {
+		Subsystem result = bundlesToSubsystems.get(bundle);
+		if (result == null) {
+			result = rootSubsystem;
+			bundlesToSubsystems.put(bundle, result);
+		}
+		return result;
+	}
+
+	public void ungetService(Bundle bundle, ServiceRegistration<Subsystem> registration, Subsystem service) {
+		bundlesToSubsystems.remove(bundle);
+	}
+}

Modified: aries/trunk/subsystem/subsystem-install/src/main/java/org/apache/aries/subsystem/install/internal/SubsystemInstaller.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-install/src/main/java/org/apache/aries/subsystem/install/internal/SubsystemInstaller.java?rev=1102244&r1=1102243&r2=1102244&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-install/src/main/java/org/apache/aries/subsystem/install/internal/SubsystemInstaller.java (original)
+++ aries/trunk/subsystem/subsystem-install/src/main/java/org/apache/aries/subsystem/install/internal/SubsystemInstaller.java Thu May 12 11:27:11 2011
@@ -21,36 +21,36 @@ import java.util.jar.JarFile;
 import java.util.jar.Manifest;
 
 import org.apache.aries.subsystem.Subsystem;
-import org.apache.aries.subsystem.SubsystemAdmin;
 import org.apache.aries.subsystem.SubsystemConstants;
 import org.apache.felix.fileinstall.ArtifactInstaller;
 
 public class SubsystemInstaller implements ArtifactInstaller {
 
-    private SubsystemAdmin subsystemAdmin;
+    private Subsystem root;
 
-    public SubsystemAdmin getSubsystemAdmin() {
-        return subsystemAdmin;
+    public Subsystem getRootSubsystem() {
+        return root;
     }
 
-    public void setSubsystemAdmin(SubsystemAdmin subsystemAdmin) {
-        this.subsystemAdmin = subsystemAdmin;
+    public void setRootSubsystem(Subsystem subsystem) {
+        this.root = subsystem;
     }
 
     public void install(File file) throws Exception {
-        subsystemAdmin.install(getLocation(file));
+        root.install(getLocation(file));
     }
 
     public void update(File file) throws Exception {
-        subsystemAdmin.update(getSubsystem(getLocation(file)));
+    	String location = getLocation(file);
+        getSubsystem(location).update();
     }
 
     public void uninstall(File file) throws Exception {
-        subsystemAdmin.uninstall(getSubsystem(getLocation(file)));
+        getSubsystem(getLocation(file)).uninstall();
     }
 
     protected Subsystem getSubsystem(String location) {
-        for (Subsystem s : subsystemAdmin.getSubsystems()) {
+        for (Subsystem s : root.getChildren()) {
             if (s.getLocation().equals(location)) {
                 return s;
             }

Modified: aries/trunk/subsystem/subsystem-itests/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/pom.xml?rev=1102244&r1=1102243&r2=1102244&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-itests/pom.xml (original)
+++ aries/trunk/subsystem/subsystem-itests/pom.xml Thu May 12 11:27:11 2011
@@ -1,22 +1,15 @@
-<!--
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements.  See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership.  The ASF licenses this file
- 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.
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor 
+    license agreements. See the NOTICE file distributed with this work for additional 
+    information regarding copyright ownership. The ASF licenses this file 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. -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
     <modelVersion>4.0.0</modelVersion>
     <parent>
         <groupId>org.apache.aries</groupId>
@@ -46,40 +39,109 @@
             <artifactId>org.apache.aries.subsystem.api</artifactId>
             <scope>test</scope>
             <version>0.1-SNAPSHOT</version>
+
+            <exclusions>
+
+                <exclusion>
+
+                    <groupId>org.osgi</groupId>
+
+                    <artifactId>org.osgi.core</artifactId>
+
+                </exclusion>
+
+            </exclusions>
+
         </dependency>
         <dependency>
             <groupId>org.apache.aries.subsystem</groupId>
             <artifactId>org.apache.aries.subsystem.core</artifactId>
             <scope>test</scope>
             <version>0.1-SNAPSHOT</version>
+
         </dependency>
+
         <dependency>
+
             <groupId>org.apache.aries.subsystem</groupId>
+
             <artifactId>org.apache.aries.subsystem.scope.api</artifactId>
+
             <version>0.1-SNAPSHOT</version>
+
+            <exclusions>
+
+                <exclusion>
+
+                    <groupId>org.osgi</groupId>
+
+                    <artifactId>org.osgi.core</artifactId>
+
+                </exclusion>
+
+            </exclusions>
+
         </dependency>
         <dependency>
             <groupId>org.apache.aries.subsystem</groupId>
             <artifactId>org.apache.aries.subsystem.scope.impl</artifactId>
             <version>0.1-SNAPSHOT</version>
-        </dependency>  
+        </dependency>
         <dependency>
             <groupId>org.apache.aries.subsystem</groupId>
             <artifactId>org.apache.aries.subsystem.executor</artifactId>
             <version>0.1-SNAPSHOT</version>
-        </dependency>  
+            <exclusions>
+
+                <exclusion>
+
+                    <groupId>org.osgi</groupId>
+
+                    <artifactId>org.osgi.core</artifactId>
+
+                </exclusion>
+
+            </exclusions>
+
+        </dependency>
         <dependency>
             <groupId>org.apache.aries.testsupport</groupId>
             <artifactId>org.apache.aries.testsupport.unit</artifactId>
             <scope>test</scope>
             <version>0.3</version>
+
+            <exclusions>
+
+                <exclusion>
+
+                    <groupId>org.osgi</groupId>
+
+                    <artifactId>org.osgi.core</artifactId>
+
+                </exclusion>
+
+            </exclusions>
+
         </dependency>
         <dependency>
             <groupId>org.apache.aries</groupId>
             <artifactId>org.apache.aries.util</artifactId>
             <scope>test</scope>
             <version>0.3</version>
-        </dependency>        
+
+            <exclusions>
+
+                <exclusion>
+
+                    <groupId>org.osgi</groupId>
+
+                    <artifactId>org.osgi.core</artifactId>
+
+                </exclusion>
+
+            </exclusions>
+
+        </dependency>
         <dependency>
             <groupId>org.ops4j.pax.exam</groupId>
             <artifactId>pax-exam</artifactId>
@@ -114,6 +176,19 @@
             <artifactId>org.apache.felix.configadmin</artifactId>
             <scope>test</scope>
             <version>1.2.8</version>
+
+            <exclusions>
+
+                <exclusion>
+
+                    <groupId>org.osgi</groupId>
+
+                    <artifactId>org.osgi.core</artifactId>
+
+                </exclusion>
+
+            </exclusions>
+
         </dependency>
         <dependency>
             <groupId>org.ops4j.pax.logging</groupId>
@@ -135,24 +210,75 @@
             <artifactId>org.osgi.service.obr</artifactId>
             <scope>test</scope>
             <version>1.0.2</version>
+
+            <exclusions>
+
+                <exclusion>
+
+                    <groupId>org.osgi</groupId>
+
+                    <artifactId>org.osgi.core</artifactId>
+
+                </exclusion>
+
+            </exclusions>
+
         </dependency>
         <dependency>
             <groupId>org.apache.felix</groupId>
             <artifactId>org.apache.felix.bundlerepository</artifactId>
             <scope>test</scope>
             <version>1.6.4</version>
+
+            <exclusions>
+
+                <exclusion>
+
+                    <groupId>org.osgi</groupId>
+
+                    <artifactId>org.osgi.core</artifactId>
+
+                </exclusion>
+
+            </exclusions>
+
         </dependency>
         <dependency>
             <groupId>org.apache.aries.application</groupId>
             <artifactId>org.apache.aries.application.utils</artifactId>
             <scope>test</scope>
             <version>0.3</version>
+
+            <exclusions>
+
+                <exclusion>
+
+                    <groupId>org.osgi</groupId>
+
+                    <artifactId>org.osgi.core</artifactId>
+
+                </exclusion>
+
+            </exclusions>
+
         </dependency>
         <dependency>
             <groupId>org.apache.aries.subsystem</groupId>
             <artifactId>org.apache.aries.subsystem.example.helloIsolation</artifactId>
             <version>0.1-SNAPSHOT</version>
             <scope>test</scope>
+            <exclusions>
+
+                <exclusion>
+
+                    <groupId>org.osgi</groupId>
+
+                    <artifactId>org.osgi.core</artifactId>
+
+                </exclusion>
+
+            </exclusions>
+
         </dependency>
     </dependencies>
 
@@ -205,10 +331,8 @@
                         <groupId>org.apache.maven.plugins</groupId>
                         <artifactId>maven-surefire-plugin</artifactId>
                         <configuration>
-                            <!--
-                                when the local repo location has been specified, we need to pass
-                                on this information to PAX mvn url
-                            -->
+                            <!-- when the local repo location has been specified, 
+                                we need to pass on this information to PAX mvn url -->
                             <argLine>-Dorg.ops4j.pax.url.mvn.localRepository=${maven.repo.local}</argLine>
                         </configuration>
                     </plugin>

Modified: aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemAdmin2Test.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemAdmin2Test.java?rev=1102244&r1=1102243&r2=1102244&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemAdmin2Test.java (original)
+++ aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemAdmin2Test.java Thu May 12 11:27:11 2011
@@ -30,8 +30,6 @@ import java.io.FileOutputStream;
 import java.util.Collection;
 
 import org.apache.aries.subsystem.Subsystem;
-import org.apache.aries.subsystem.SubsystemAdmin;
-import org.apache.aries.subsystem.scope.Scope;
 import org.apache.aries.unittest.fixture.ArchiveFixture;
 import org.apache.aries.unittest.fixture.ArchiveFixture.ZipFixture;
 import org.junit.Before;
@@ -69,25 +67,20 @@ public class SubsystemAdmin2Test extends
     
     @Test
     public void test() throws Exception {
-        // make sure we are using a framework that provides scope admin service
-        Scope scopeA = getOsgiService(Scope.class);
-        assertNotNull("scope admin should not be null", scopeA);
-        System.out.println("able to get scope admin service");
-        
         // obtain subsystem admin service
-        SubsystemAdmin sa = getOsgiService(SubsystemAdmin.class);
-        assertNotNull("subsystem admin should not be null", sa);
+        Subsystem s = getOsgiService(Subsystem.class);
+        assertNotNull("subsystem admin should not be null", s);
         System.out.println("able to get subsytem admin service");
         
         File f = new File("test.eba");
-        Subsystem subsystem = sa.install(f.toURI().toURL().toExternalForm());
+        Subsystem subsystem = s.install(f.toURI().toURL().toExternalForm());
         assertNotNull("subsystem should not be null", subsystem);
         
         assertTrue("subsystem should have a unique id", subsystem.getSubsystemId() > 0);
         assertTrue(subsystem.getLocation().indexOf("test.eba") != -1);
         assertTrue(subsystem.getSymbolicName().indexOf("felix-file-install2") != -1);
         assertEquals("2.0.8", subsystem.getVersion().toString());
-        Collection<Bundle> bundles = subsystem.getBundles();
+        Collection<Bundle> bundles = subsystem.getConstituents();
         assertEquals("check bundles' size", 1, bundles.size());
 
     }
@@ -108,13 +101,13 @@ public class SubsystemAdmin2Test extends
             systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("DEBUG"),
 
             // Bundles
-            mavenBundle("org.apache.aries.subsystem", "org.apache.aries.subsystem.scope.api"),
-            mavenBundle("org.apache.aries.subsystem", "org.apache.aries.subsystem.scope.impl"),
+            mavenBundle("org.eclipse.equinox", "region"),
             mavenBundle("org.apache.aries.testsupport", "org.apache.aries.testsupport.unit"),
             mavenBundle("org.apache.aries.application", "org.apache.aries.application.api"),
             mavenBundle("org.apache.aries", "org.apache.aries.util"),
             mavenBundle("org.apache.aries.application", "org.apache.aries.application.utils"),
             mavenBundle("org.apache.felix", "org.apache.felix.bundlerepository"),
+            mavenBundle("org.eclipse.equinox", "coordinator"),
             mavenBundle("org.apache.aries.subsystem", "org.apache.aries.subsystem.api"),
 
             mavenBundle("org.apache.aries.subsystem", "org.apache.aries.subsystem.core"),

Modified: aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemAdminTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemAdminTest.java?rev=1102244&r1=1102243&r2=1102244&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemAdminTest.java (original)
+++ aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemAdminTest.java Thu May 12 11:27:11 2011
@@ -30,8 +30,6 @@ import java.io.FileOutputStream;
 import java.util.Collection;
 
 import org.apache.aries.subsystem.Subsystem;
-import org.apache.aries.subsystem.SubsystemAdmin;
-import org.apache.aries.subsystem.scope.Scope;
 import org.apache.aries.unittest.fixture.ArchiveFixture;
 import org.apache.aries.unittest.fixture.ArchiveFixture.ZipFixture;
 import org.junit.Before;
@@ -71,27 +69,22 @@ public class SubsystemAdminTest extends 
     // Disable this test since it is designed to use the NoOpResolver which isn't registered.
     //@Test
     public void test() throws Exception {
-        // make sure we are using a framework that provides composite admin service
-    	Scope scopeA = getOsgiService(Scope.class);
-        assertNotNull("composite admin should not be null", scopeA);
-        System.out.println("able to get composite admin service");
-        
         // obtain subsystem admin service
-        SubsystemAdmin sa = getOsgiService(SubsystemAdmin.class);
-        assertNotNull("subsystem admin should not be null", sa);
+        Subsystem s = getOsgiService(Subsystem.class);
+        assertNotNull("subsystem admin should not be null", s);
         System.out.println("able to get subsytem admin service");
         
         File f = new File("test.eba");
         // capture initial bundle size
         int init = bundleContext.getBundles().length;
-        Subsystem subsystem = sa.install(f.toURI().toURL().toExternalForm());
+        Subsystem subsystem = s.install(f.toURI().toURL().toExternalForm());
         assertNotNull("subsystem should not be null", subsystem);
         
         assertTrue("subsystem should have a unique id", subsystem.getSubsystemId() > 0);
         assertTrue(subsystem.getLocation().indexOf("test.eba") != -1);
         assertEquals("felix-file-install", subsystem.getSymbolicName());
         assertEquals("2.0.8", subsystem.getVersion().toString());
-        Collection<Bundle> bundles = subsystem.getBundles();
+        Collection<Bundle> bundles = subsystem.getConstituents();
         assertEquals("check constituents' size", 1, bundles.size());
         // recapture bundle size
         int later = bundleContext.getBundles().length;
@@ -121,10 +114,9 @@ public class SubsystemAdminTest extends 
             mavenBundle("org.apache.aries.application", "org.apache.aries.application.api"),
             mavenBundle("org.apache.aries.application", "org.apache.aries.application.utils"),
             mavenBundle("org.apache.felix", "org.apache.felix.bundlerepository"),
+            mavenBundle("org.eclipse.equinox", "coordinator"),
             mavenBundle("org.apache.aries.subsystem", "org.apache.aries.subsystem.api"),
-            mavenBundle("org.apache.aries.subsystem", "org.apache.aries.subsystem.scope.api"),
             mavenBundle("org.apache.aries.subsystem", "org.apache.aries.subsystem.core"),
-            mavenBundle("org.apache.aries.subsystem", "org.apache.aries.subsystem.scope.impl"),
 
             //org.ops4j.pax.exam.container.def.PaxRunnerOptions.vmOption("-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"),
 

Modified: aries/trunk/subsystem/subsystem-obr/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-obr/pom.xml?rev=1102244&r1=1102243&r2=1102244&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-obr/pom.xml (original)
+++ aries/trunk/subsystem/subsystem-obr/pom.xml Thu May 12 11:27:11 2011
@@ -65,6 +65,11 @@
             <version>0.1-SNAPSHOT</version>
         </dependency>
         <dependency>
+            <groupId>org.apache.aries.subsystem</groupId>
+            <artifactId>org.apache.aries.subsystem.core</artifactId>
+            <version>0.1-SNAPSHOT</version>
+        </dependency>
+        <dependency>
             <groupId>org.apache.felix</groupId>
             <artifactId>org.apache.felix.bundlerepository</artifactId>
             <version>1.6.4</version>

Modified: aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/Activator.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/Activator.java?rev=1102244&r1=1102243&r2=1102244&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/Activator.java (original)
+++ aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/Activator.java Thu May 12 11:27:11 2011
@@ -18,7 +18,7 @@
  */
 package org.apache.aries.subsystem.obr.internal;
 
-import org.apache.aries.subsystem.spi.ResourceResolver;
+import org.apache.aries.subsystem.core.ResourceResolver;
 import org.apache.felix.bundlerepository.RepositoryAdmin;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;

Modified: aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/ObrResourceImpl.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/ObrResourceImpl.java?rev=1102244&r1=1102243&r2=1102244&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/ObrResourceImpl.java (original)
+++ aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/ObrResourceImpl.java Thu May 12 11:27:11 2011
@@ -21,8 +21,11 @@ package org.apache.aries.subsystem.obr.i
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
+import java.util.List;
 import java.util.Map;
 
+import org.apache.aries.subsystem.spi.Capability;
+import org.apache.aries.subsystem.spi.Requirement;
 import org.apache.aries.subsystem.spi.Resource;
 import org.osgi.framework.Version;
 
@@ -30,9 +33,9 @@ public class ObrResourceImpl implements 
 
     private final org.apache.felix.bundlerepository.Resource resource;
     private final String type;
-    private final Map<String,String> attributes;
+    private final Map<String,Object> attributes;
 
-    public ObrResourceImpl(org.apache.felix.bundlerepository.Resource resource, String type, Map<String,String> attributes) {
+    public ObrResourceImpl(org.apache.felix.bundlerepository.Resource resource, String type, Map<String,Object> attributes) {
         this.resource = resource;
         this.type = type;
         this.attributes = attributes;
@@ -54,11 +57,21 @@ public class ObrResourceImpl implements 
         return resource.getURI();
     }
 
-    public Map<String, String> getAttributes() {
+    public Map<String, Object> getAttributes() {
         return attributes;
     }
 
     public InputStream open() throws IOException {
         return new URL(getLocation()).openStream();
     }
+
+	public List<Capability> getCapabilities(String namespace) {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	public List<Requirement> getRequirements(String namespace) {
+		// TODO Auto-generated method stub
+		return null;
+	}
 }

Modified: aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/ObrResourceResolver.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/ObrResourceResolver.java?rev=1102244&r1=1102243&r2=1102244&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/ObrResourceResolver.java (original)
+++ aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/ObrResourceResolver.java Thu May 12 11:27:11 2011
@@ -27,8 +27,8 @@ import java.util.Map;
 
 import org.apache.aries.subsystem.SubsystemConstants;
 import org.apache.aries.subsystem.SubsystemException;
+import org.apache.aries.subsystem.core.ResourceResolver;
 import org.apache.aries.subsystem.spi.Resource;
-import org.apache.aries.subsystem.spi.ResourceResolver;
 import org.apache.felix.bundlerepository.Capability;
 import org.apache.felix.bundlerepository.Repository;
 import org.apache.felix.bundlerepository.RepositoryAdmin;
@@ -76,7 +76,7 @@ public class ObrResourceResolver impleme
         String ver = clauses[0].getAttribute(Constants.VERSION_ATTRIBUTE);
         String typ = clauses[0].getAttribute(SubsystemConstants.RESOURCE_TYPE_ATTRIBUTE);
         String loc = clauses[0].getAttribute(SubsystemConstants.RESOURCE_LOCATION_ATTRIBUTE);
-        Map<String,String> attributes = new HashMap<String,String>();
+        Map<String,Object> attributes = new HashMap<String,Object>();
         for (Attribute a : clauses[0].getAttributes()) {
             String name = a.getName();
             if (!Constants.VERSION_ATTRIBUTE.equals(name)
@@ -116,10 +116,10 @@ public class ObrResourceResolver impleme
         List<org.apache.felix.bundlerepository.Resource> obrResources = new ArrayList<org.apache.felix.bundlerepository.Resource>();
         for (Resource res : subsystemResources)
         {
-            if (res.getType().equals(SubsystemConstants.RESOURCE_TYPE_BUNDLE)) {
+            if (res.getAttributes().get(Resource.NAMESPACE_ATTRIBUTE).equals(SubsystemConstants.RESOURCE_TYPE_BUNDLE)) {
                 try
                 {
-                    obrResources.add(admin.getHelper().createResource(new URL(res.getLocation())));
+                    obrResources.add(admin.getHelper().createResource(new URL(String.valueOf(res.getAttributes().get(Resource.LOCATION_ATTRIBUTE)))));
                 }
                 catch (Exception e) {
                     // TODO: log exception
@@ -136,8 +136,10 @@ public class ObrResourceResolver impleme
 
         for (Resource res : subsystemContent)
         {
-            if (res.getType().equals(SubsystemConstants.RESOURCE_TYPE_BUNDLE)) {
-                resolver.add(admin.getHelper().requirement(Capability.BUNDLE, "(&(symbolicname=" + res.getSymbolicName() + ")" + (res.getVersion() != null ? "(version=" + res.getVersion() + ")" : "") + ")"));
+            if (res.getAttributes().get(Resource.NAMESPACE_ATTRIBUTE).equals(SubsystemConstants.RESOURCE_TYPE_BUNDLE)) {
+            	String symbolicName = String.valueOf(res.getAttributes().get(Resource.SYMBOLIC_NAME_ATTRIBUTE));
+            	Version version = (Version)res.getAttributes().get(Resource.VERSION_ATTRIBUTE);
+                resolver.add(admin.getHelper().requirement(Capability.BUNDLE, "(&(symbolicname=" + symbolicName + ")" + (version != null ? "(version=" + version + ")" : "") + ")"));
             }
         }
         if (!resolver.resolve(Resolver.NO_OPTIONAL_RESOURCES)) {
@@ -146,7 +148,7 @@ public class ObrResourceResolver impleme
 
         List<Resource> resolved = new ArrayList<Resource>();
         for (org.apache.felix.bundlerepository.Resource res : resolver.getRequiredResources()) {
-            resolved.add(new ObrResourceImpl(res, SubsystemConstants.RESOURCE_TYPE_BUNDLE, new HashMap<String,String>()));
+            resolved.add(new ObrResourceImpl(res, SubsystemConstants.RESOURCE_TYPE_BUNDLE, new HashMap<String,Object>()));
         }
         return resolved;
     }

Modified: aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/ResourceImpl.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/ResourceImpl.java?rev=1102244&r1=1102243&r2=1102244&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/ResourceImpl.java (original)
+++ aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/ResourceImpl.java Thu May 12 11:27:11 2011
@@ -21,8 +21,11 @@ package org.apache.aries.subsystem.obr.i
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
+import java.util.List;
 import java.util.Map;
 
+import org.apache.aries.subsystem.spi.Capability;
+import org.apache.aries.subsystem.spi.Requirement;
 import org.apache.aries.subsystem.spi.Resource;
 import org.osgi.framework.Version;
 
@@ -32,9 +35,9 @@ public class ResourceImpl implements Res
     private final Version version;
     private final String type;
     private final String location;
-    private final Map<String,String> attributes;
+    private final Map<String,Object> attributes;
 
-    public ResourceImpl(String symbolicName, Version version, String type, String location, Map<String,String> attributes) {
+    public ResourceImpl(String symbolicName, Version version, String type, String location, Map<String,Object> attributes) {
         this.symbolicName = symbolicName;
         this.version = version;
         this.type = type;
@@ -58,7 +61,7 @@ public class ResourceImpl implements Res
         return location;
     }
 
-    public Map<String, String> getAttributes() {
+    public Map<String, Object> getAttributes() {
         return attributes;
     }
 
@@ -66,4 +69,14 @@ public class ResourceImpl implements Res
         return new URL(getLocation()).openStream();
     }
 
+	public List<Capability> getCapabilities(String namespace) {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	public List<Requirement> getRequirements(String namespace) {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
 }

Added: aries/trunk/subsystem/subsystem-scope-impl/src/main/java/org/apache/aries/subsystem/scope/impl/IdGenerator.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-scope-impl/src/main/java/org/apache/aries/subsystem/scope/impl/IdGenerator.java?rev=1102244&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-scope-impl/src/main/java/org/apache/aries/subsystem/scope/impl/IdGenerator.java (added)
+++ aries/trunk/subsystem/subsystem-scope-impl/src/main/java/org/apache/aries/subsystem/scope/impl/IdGenerator.java Thu May 12 11:27:11 2011
@@ -0,0 +1,17 @@
+package org.apache.aries.subsystem.scope.impl;
+
+public class IdGenerator {
+	private long lastId;
+	
+	public IdGenerator() {
+		this(0);
+	}
+	
+	public IdGenerator(long firstId) {
+		lastId = firstId;
+	}
+	
+	public synchronized long nextId() {
+		return lastId++;
+	}
+}

Modified: aries/trunk/subsystem/subsystem-scope-impl/src/main/java/org/apache/aries/subsystem/scope/impl/ScopeImpl.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-scope-impl/src/main/java/org/apache/aries/subsystem/scope/impl/ScopeImpl.java?rev=1102244&r1=1102243&r2=1102244&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-scope-impl/src/main/java/org/apache/aries/subsystem/scope/impl/ScopeImpl.java (original)
+++ aries/trunk/subsystem/subsystem-scope-impl/src/main/java/org/apache/aries/subsystem/scope/impl/ScopeImpl.java Thu May 12 11:27:11 2011
@@ -2,7 +2,6 @@ package org.apache.aries.subsystem.scope
 
 import java.util.Collection;
 import java.util.Collections;
-import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
@@ -12,115 +11,31 @@ import org.apache.aries.subsystem.scope.
 import org.apache.aries.subsystem.scope.ScopeUpdate;
 import org.apache.aries.subsystem.scope.SharePolicy;
 import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
 
 public class ScopeImpl implements Scope {
-	private static class UnmodifiableSharePolicyMap implements Map<String, List<SharePolicy>> {
-		private final Map<String, List<SharePolicy>> map;
-		
-		public UnmodifiableSharePolicyMap(Map<String, List<SharePolicy>> map) {
-			this.map = map;
-		}
-		
-		public void clear() {
-			throw new UnsupportedOperationException();
-		}
-
-		public boolean containsKey(Object key) {
-			return map.containsKey(key);
-		}
-
-		public boolean containsValue(Object value) {
-			return map.containsValue(value);
-		}
-
-		public Set<java.util.Map.Entry<String, List<SharePolicy>>> entrySet() {
-			Set<Map.Entry<String, List<SharePolicy>>> result = new HashSet<Map.Entry<String, List<SharePolicy>>>(map.size());
-			for (final Map.Entry<String, List<SharePolicy>> entry : map.entrySet()) {
-				result.add(new Map.Entry<String, List<SharePolicy>>() {
-					public String getKey() {
-						return entry.getKey();
-					}
-
-					public List<SharePolicy> getValue() {
-						return entry.getValue();
-					}
-
-					public List<SharePolicy> setValue(List<SharePolicy> object) {
-						throw new UnsupportedOperationException();
-					}
-				});
-			}
-			return Collections.unmodifiableSet(result);
-		}
-
-		public List<SharePolicy> get(Object key) {
-			List<SharePolicy> result = map.get(key);
-			return result == null ? null : Collections.unmodifiableList(result);
-		}
-
-		public boolean isEmpty() {
-			return map.isEmpty();
-		}
-
-		public Set<String> keySet() {
-			return Collections.unmodifiableSet(map.keySet());
-		}
-
-		public List<SharePolicy> put(String key, List<SharePolicy> value) {
-			throw new UnsupportedOperationException();
-		}
-
-		public void putAll(Map<? extends String, ? extends List<SharePolicy>> map) {
-			throw new UnsupportedOperationException();
-		}
-
-		public List<SharePolicy> remove(Object key) {
-			throw new UnsupportedOperationException();
-		}
-
-		public int size() {
-			return map.size();
-		}
-
-		public Collection<List<SharePolicy>> values() {
-			return Collections.unmodifiableCollection(map.values());
-		}
-	}
+	private volatile boolean updating;
 	
-	private static long lastId = -1;
-	
-	private static synchronized long nextId() {
-		if (lastId == Long.MAX_VALUE)
-			throw new IllegalStateException("The next ID would exceed Long.MAX_VALUE");
-		return ++lastId;
-	}
-	
-	volatile boolean updating;
-	
-	long lastUpdate;
-	
-	final BundleContext bundleContext;
-	final Set<Bundle> bundles = Collections.synchronizedSet(new HashSet<Bundle>());
-	final Set<Scope> children = Collections.synchronizedSet(new HashSet<Scope>());
-	final Map<String, List<SharePolicy>> exportPolicies = Collections.synchronizedMap(new HashMap<String, List<SharePolicy>>());
-	final Map<String, List<SharePolicy>> importPolicies = Collections.synchronizedMap(new HashMap<String, List<SharePolicy>>());
+	private long lastUpdate;
 	
+	private final Collection<Bundle> bundles = Collections.synchronizedSet(new HashSet<Bundle>());
+	private final Set<Scope> children = Collections.synchronizedSet(new HashSet<Scope>());
 	private final long id;
 	private final String location;
 	private final String name;
-	private final Scope parent;
+	private final long parentId;
+	private final Scopes scopes;
+	private final SharePolicies sharePolicies;
 	
-	public ScopeImpl(
-			BundleContext bundleContext,
-			String name,
-			String location,
-			Scope parent) {
-		this.bundleContext = bundleContext;
+	public ScopeImpl(long id, String name, String location, long parentId, Collection<Bundle> bundles, SharePolicies sharePolicies, Scopes scopes) {
+		this.id = id;
 		this.name = name;
 		this.location = location;
-		this.parent = parent;
-		id = nextId();
+		this.parentId = parentId;
+		if (bundles != null) {
+			this.bundles.addAll(bundles);
+		}
+		this.sharePolicies = sharePolicies;
+		this.scopes = scopes;
 	}
 
 	public Collection<Bundle> getBundles() {
@@ -144,18 +59,54 @@ public class ScopeImpl implements Scope 
 	}
 	
 	public Scope getParent() {
-		return parent;
+		return scopes.getScope(parentId);
 	}
 
 	public Map<String, List<SharePolicy>> getSharePolicies(String type) {
-		if (SharePolicy.TYPE_EXPORT.equals(type))
-			return new UnmodifiableSharePolicyMap(exportPolicies);
-		else if (SharePolicy.TYPE_IMPORT.equals(type))
-			return new UnmodifiableSharePolicyMap(importPolicies);
-		throw new IllegalArgumentException(type);
+		return Collections.unmodifiableMap(sharePolicies.getSharePolicies(type));
 	}
 	
 	public ScopeUpdate newScopeUpdate() {
 		return ScopeUpdateImpl.newInstance(this);
 	}
+	
+	void addBundle(Bundle bundle) {
+		bundles.add(bundle);
+	}
+	
+	void addChild(ScopeImpl child) {
+		children.add(child);
+	}
+	
+	synchronized long getLastUpdate() {
+		return lastUpdate;
+	}
+	
+	Scopes getScopes() {
+		return scopes;
+	}
+	
+	SharePolicies getSharePolicies() {
+		return sharePolicies;
+	}
+	
+	boolean isUpdating() {
+		return updating;
+	}
+	
+	void removeBundle(Bundle bundle) {
+		bundles.remove(bundle);
+	}
+	
+	void removeChild(ScopeImpl scope) {
+		children.remove(scope);
+	}
+	
+	synchronized void setLastUpdate(long value) {
+		lastUpdate = value;
+	}
+	
+	void setUpdating(boolean value) {
+		updating = value;
+	}
 }



Mime
View raw message