incubator-aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject svn commit: r1030900 - in /incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender: ./ META-INF/ src/ src/api/ src/extender/ src/org/ src/org/apache/ src/org/apache/aries/ src/org/apache/aries/spifly/ src/org/apache/aries/spifly/api/ src...
Date Thu, 04 Nov 2010 12:18:46 GMT
Author: davidb
Date: Thu Nov  4 12:18:45 2010
New Revision: 1030900

URL: http://svn.apache.org/viewvc?rev=1030900&view=rev
Log:
Initial import.

Added:
    incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/.classpath
    incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/.project
    incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/META-INF/
    incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/META-INF/MANIFEST.MF
    incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/build.properties
    incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/src/
    incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/src/api/
    incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/src/extender/
    incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/src/extender/Activator.java
    incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/src/extender/HeaderParser.java
    incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/src/extender/SPIBundleTrackerCustomizer.java
    incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/src/extender/SPIClassloaderAdviceServiceImpl.java
    incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/src/org/
    incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/src/org/apache/
    incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/src/org/apache/aries/
    incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/src/org/apache/aries/spifly/
    incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/src/org/apache/aries/spifly/api/
    incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/src/org/apache/aries/spifly/api/SPIClassloaderAdviceService.java
    incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/src/org/apache/aries/spifly/api/SpiFlyConstants.java
    incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/src/org/apache/aries/spifly/util/
    incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/src/org/apache/aries/spifly/util/MultiDelegationClassloader.java
Modified:
    incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/   (props changed)

Propchange: incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Nov  4 12:18:45 2010
@@ -0,0 +1 @@
+.settings

Added: incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/.classpath
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/.classpath?rev=1030900&view=auto
==============================================================================
--- incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/.classpath (added)
+++ incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/.classpath Thu
Nov  4 12:18:45 2010
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>

Added: incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/.project
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/.project?rev=1030900&view=auto
==============================================================================
--- incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/.project (added)
+++ incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/.project Thu Nov
 4 12:18:45 2010
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>Extender</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.pde.ManifestBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.pde.SchemaBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.pde.PluginNature</nature>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>

Added: incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/META-INF/MANIFEST.MF?rev=1030900&view=auto
==============================================================================
--- incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/META-INF/MANIFEST.MF
(added)
+++ incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/META-INF/MANIFEST.MF
Thu Nov  4 12:18:45 2010
@@ -0,0 +1,12 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Extender
+Bundle-SymbolicName: Extender
+Bundle-Version: 1.0.0.qualifier
+Bundle-Activator: extender.Activator
+Import-Package: org.osgi.framework;version="1.3.0",
+ org.osgi.framework.wiring;version="1.0.0",
+ org.osgi.service.log;version="1.3.0",
+ org.osgi.util.tracker;version="1.5.0"
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Export-Package: org.apache.aries.spifly.util

Added: incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/build.properties
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/build.properties?rev=1030900&view=auto
==============================================================================
--- incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/build.properties
(added)
+++ incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/build.properties
Thu Nov  4 12:18:45 2010
@@ -0,0 +1,4 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+               .

Added: incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/src/extender/Activator.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/src/extender/Activator.java?rev=1030900&view=auto
==============================================================================
--- incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/src/extender/Activator.java
(added)
+++ incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/src/extender/Activator.java
Thu Nov  4 12:18:45 2010
@@ -0,0 +1,93 @@
+/**
+ * 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.
+ */
+package extender;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.log.LogService;
+import org.osgi.util.tracker.BundleTracker;
+import org.osgi.util.tracker.ServiceTracker;
+import org.osgi.util.tracker.ServiceTrackerCustomizer;
+
+public class Activator implements BundleActivator {
+    BundleTracker bt;
+    ServiceTracker lst;
+    List<LogService> logServices = new ArrayList<LogService>();
+
+    public synchronized void start(final BundleContext context) throws Exception {
+        lst = new LogServiceTracker(context, LogService.class.getName(), null);
+        lst.open();
+        
+	    bt = new BundleTracker(context, Bundle.ACTIVE, 
+	            new SPIBundleTrackerCustomizer(this, context.getBundle()));
+	    bt.open();
+	}
+
+	public synchronized void stop(BundleContext context) throws Exception {
+	    bt.close();
+	    lst.close();	    
+	}
+	
+	void log(int level, String message) {
+	    synchronized (logServices) {
+	        for (LogService log : logServices) {
+	            log.log(level, message);
+	        }
+        }
+	}
+
+	void log(int level, String message, Throwable th) {
+        synchronized (logServices) {
+            for (LogService log : logServices) {
+                log.log(level, message, th);
+            }
+        }
+    }
+    
+	private final class LogServiceTracker extends ServiceTracker {
+        private LogServiceTracker(BundleContext context, String clazz,
+                ServiceTrackerCustomizer customizer) {
+            super(context, clazz, customizer);
+        }
+
+        @Override
+        public Object addingService(ServiceReference reference) {
+            Object svc = super.addingService(reference);
+            if (svc instanceof LogService) {
+                synchronized (logServices) {
+                    logServices.add((LogService) svc);
+                }
+            }
+            return svc;
+        }
+
+        @Override
+        public void removedService(ServiceReference reference, Object service) {
+            synchronized (logServices) {
+                logServices.remove(service);
+            }
+            super.removedService(reference, service);
+        }
+    }
+}

Added: incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/src/extender/HeaderParser.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/src/extender/HeaderParser.java?rev=1030900&view=auto
==============================================================================
--- incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/src/extender/HeaderParser.java
(added)
+++ incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/src/extender/HeaderParser.java
Thu Nov  4 12:18:45 2010
@@ -0,0 +1,96 @@
+package extender;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Utility class to parse a standard OSGi header with paths.
+ *
+ * Stolen from Aries Blueprint Core (blueprint.utils). Need to give it back! 
+ */
+public class HeaderParser  {
+
+    /**
+     * Parse a given OSGi header into a list of paths
+     *
+     * @param header the OSGi header to parse
+     * @return the list of paths extracted from this header
+     */
+    public static List<PathElement> parseHeader(String header) {
+        List<PathElement> elements = new ArrayList<PathElement>();
+        if (header == null || header.trim().length() == 0) {
+            return elements;
+        }
+        String[] clauses = header.split(",");
+        for (String clause : clauses) {
+            String[] tokens = clause.split(";");
+            if (tokens.length < 1) {
+                throw new IllegalArgumentException("Invalid header clause: " + clause);
+            }
+            PathElement elem = new PathElement(tokens[0].trim());
+            elements.add(elem);
+            for (int i = 1; i < tokens.length; i++) {
+                int pos = tokens[i].indexOf('=');
+                if (pos != -1) {
+                    if (pos > 0 && tokens[i].charAt(pos - 1) == ':') {
+                        String name = tokens[i].substring(0, pos - 1).trim();
+                        String value = tokens[i].substring(pos + 1).trim();
+                        elem.addDirective(name, value);
+                    } else {
+                        String name = tokens[i].substring(0, pos).trim();
+                        String value = tokens[i].substring(pos + 1).trim();
+                        elem.addAttribute(name, value);
+                    }
+                } else {
+                    elem = new PathElement(tokens[i].trim());
+                    elements.add(elem);
+                }
+            }
+        }
+        return elements;
+    }
+
+    public static class PathElement {
+        
+        private String path;
+        private Map<String, String> attributes;
+        private Map<String, String> directives;
+        
+        public PathElement(String path) {
+            this.path = path;
+            this.attributes = new HashMap<String, String>();
+            this.directives = new HashMap<String, String>();
+        }
+        
+        public String getName() {
+            return this.path;
+        }
+        
+        public Map<String, String> getAttributes() {
+            return attributes;
+        }
+        
+        public String getAttribute(String name) {
+            return attributes.get(name);
+        }
+        
+        public void addAttribute(String name, String value) {
+            attributes.put(name, value);
+        }
+        
+        public Map<String, String> getDirectives() {
+            return directives;
+        }
+        
+        public String getDirective(String name) {
+            return directives.get(name);
+        }
+        
+        public void addDirective(String name, String value) {
+            directives.put(name, value);
+        }        
+        
+    }
+}

Added: incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/src/extender/SPIBundleTrackerCustomizer.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/src/extender/SPIBundleTrackerCustomizer.java?rev=1030900&view=auto
==============================================================================
--- incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/src/extender/SPIBundleTrackerCustomizer.java
(added)
+++ incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/src/extender/SPIBundleTrackerCustomizer.java
Thu Nov  4 12:18:45 2010
@@ -0,0 +1,253 @@
+package extender;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import org.apache.aries.spifly.api.SPIClassloaderAdviceService;
+import org.apache.aries.spifly.api.SpiFlyConstants;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleEvent;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.framework.wiring.BundleWiring;
+import org.osgi.service.log.LogService;
+import org.osgi.util.tracker.BundleTrackerCustomizer;
+
+import extender.HeaderParser;
+import extender.HeaderParser.PathElement;
+
+public class SPIBundleTrackerCustomizer implements BundleTrackerCustomizer {
+
+    final Activator activator;
+    final Bundle spiBundle;
+
+    public SPIBundleTrackerCustomizer(Activator a, Bundle b) {
+        activator = a;
+        spiBundle = b;
+    }
+
+    public Object addingBundle(Bundle bundle, BundleEvent event) {
+        log(LogService.LOG_INFO, "Bundle Considered for SPI providers: "
+                + bundle.getSymbolicName());
+
+        if (bundle.getBundleId() == 0)
+        	return null;
+        
+        if (bundle.equals(spiBundle)) {
+            return null;
+        }
+
+        if (bundle.getHeaders().get(SpiFlyConstants.SPI_PROVIDER_HEADER) == null) {
+            log(LogService.LOG_INFO, "No '"
+                    + SpiFlyConstants.SPI_PROVIDER_HEADER
+                    + "' Manifest header. Skipping bundle: "
+                    + bundle.getSymbolicName());
+            // TEMPORARY return null;
+        } else {
+            log(LogService.LOG_INFO, "Examining bundle for SPI provider: "
+                    + bundle.getSymbolicName());
+        }
+
+        Enumeration<?> entries = bundle.findEntries("META-INF/services", "*",
+                false);
+        if (entries == null) {
+            return null;
+        }
+
+        BundleWiring bw = bundle.adapt(BundleWiring.class);
+        ClassLoader bundleClassloader = bw.getClassLoader();
+        List<ServiceRegistration<?>> registrations = new ArrayList<ServiceRegistration<?>>();
+        
+        String spiProviderHeader = bundle.getHeaders().get(SpiFlyConstants.SPI_PROVIDER_HEADER);
+        List<PathElement> parsedHeader = HeaderParser.parseHeader(spiProviderHeader);
+        for (PathElement pe : parsedHeader) {
+        	String apiName = pe.getName();
+    		URL url = bundle.getResource("META-INF/services/" + apiName);
+    		try {
+				BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
+				String className = null;
+				while ((className = reader.readLine()) != null) {
+					Class<?> cls = bundle.loadClass(className);
+					Object o = cls.newInstance();
+					
+					registrations.add(bundle.getBundleContext().registerService(apiName, o, null));
+					
+//					SPIClassloaderAdviceService adviceSvc = new SPIClassloaderAdviceServiceImpl(bundleClassloader);
+//					Hashtable<String, Object> props = new Hashtable<String, Object>();
+//					props.put(SpiFlyConstants.API_NAME_SERVICE_ATTRIBUTE, )
+				}					
+			} catch (Exception e) {
+                log(LogService.LOG_INFO,
+                    "Could not load SPI implementation referred from " + url, e);
+			}    		
+        }
+        	
+        // the old approach
+        /*
+        while (entries.hasMoreElements()) {
+            URL url = (URL) entries.nextElement();
+            log(LogService.LOG_INFO, "Found SPI resource: " + url);
+
+            try {
+                BufferedReader reader = new BufferedReader(
+                        new InputStreamReader(url.openStream()));
+                String className = reader.readLine();
+                // do we need to read more than one class name?
+
+                Class<?> cls = bundle.loadClass(className);
+                // FIXME Is there a cleaner way to get the classloader being
+                // only provided with a reference to a bundle? Currently we're
+                // just taking the name of the service provider class that is
+                // defined in this bundle, loading it and then retrieving the
+                // classloader from this loaded class.
+                if (bundleClassloader == null) {
+                    bundleClassloader = cls.getClassLoader();
+                }
+                Object o = cls.newInstance();
+                log(LogService.LOG_INFO, "Instantiated SPI provider: " + o);
+
+                Hashtable<String, Object> props = new Hashtable<String, Object>();
+                props.put(SpiFlyConstants.SPI_PROVIDER_URL, url);
+
+                String s = url.toExternalForm();
+                int idx = s.lastIndexOf('/');
+                String registrationClassName = className;
+                if (s.length() > idx) {
+                    registrationClassName = s.substring(idx + 1);
+                }
+
+                ServiceRegistration reg = bundle.getBundleContext()
+                        .registerService(registrationClassName, o, props);
+                registrations.add(reg);
+                log(LogService.LOG_INFO, "Registered service: " + reg);
+            } catch (Exception e) {
+                log(LogService.LOG_INFO,
+                        "Could not load SPI implementation referred from "
+                                + url, e);
+            }
+        }
+        
+
+        // the new approach - services are being registered based on contents of
+        // the SPI-Provider header
+        if (bundleClassloader == null) {
+            log(LogService.LOG_INFO, "Unable to identify classloader. "
+                    + "Skipping SPIClassloaderAdviceService(s) registeration.");
+        } else {
+
+            // Register SPIClassloaderAdviceService services for APIs mentioned
+            // in the header
+            String spiProviderHeader = (String) bundle.getHeaders().get(
+                    SpiFlyConstants.SPI_PROVIDER_HEADER);
+            List<PathElement> parsedHeader = HeaderParser
+                    .parseHeader(spiProviderHeader);
+            for (PathElement pe : parsedHeader) {
+
+                // Format of each path element:
+                // api1Name;provider-name="myimpl2";service-ids="myserviceId"
+
+                // An example below.
+                // Please note:
+                // 1. The service-ids attribute holds a list of ids that will be
+                // used when searching META-INF/services/. In other words
+                // this will be the name of the class that will be passed to
+                // ServiceLoader.load().
+                // 2. A single bundle can provide implementations for many APIs
+                // - there might be many api names in a single SPI-Provider
+                // header.
+
+                // Sample:
+                // jaxb;provider-name="xerces123";service-ids="javax.xml.bind.JAXBContext"
+
+                // the clause begins with a name of the API for which this
+                // bundle provides an impl
+                String apiName = pe.getName();
+                // unique name of the provider
+                String providerName = pe
+                        .getAttribute(SpiFlyConstants.PROVIDER_NAME_ATTRIBUTE);
+                providerName = trimQuotes(providerName);
+
+                // 
+                String serviceIds = pe
+                        .getAttribute(SpiFlyConstants.SERVICE_IDS_ATTRIBUTE);
+                serviceIds = trimQuotes(serviceIds);
+
+                / *
+                if (apiName == null || providerName == null
+                        || serviceIds == null) {
+                    log(LogService.LOG_INFO, "Skipping: " + apiName + " "
+                            + providerName + " " + serviceIds
+                            + ". Null values are not allowed.");
+                }
+                * /
+
+                StringTokenizer tokenizer = new StringTokenizer(serviceIds, ",");
+                while (tokenizer.hasMoreTokens()) {
+                    String serviceId = tokenizer.nextToken().trim();
+                    SPIClassloaderAdviceServiceImpl service = new SPIClassloaderAdviceServiceImpl(
+                            bundleClassloader);
+                    Hashtable<String, Object> props = new Hashtable<String, Object>();
+                    props.put(SpiFlyConstants.API_NAME_SERVICE_ATTRIBUTE,
+                            apiName);
+                    props.put(SpiFlyConstants.PROVIDER_NAME_SERVICE_ATTRIBUTE,
+                            providerName);
+                    props.put(SpiFlyConstants.SERVICE_ID_SERVICE_ATTRIBUTE,
+                            serviceId);
+                    ServiceRegistration reg = bundle
+                            .getBundleContext()
+                            .registerService(
+                                    SPIClassloaderAdviceService.class.getName(),
+                                    service, props);
+                    registrations.add(reg);
+                    log(LogService.LOG_INFO, "Registered service: " + reg);
+                } 
+            }
+        } */
+
+        return registrations;
+    }
+
+    private String trimQuotes(String input) {
+        if (input == null) {
+            return input;
+        }
+        if (input.startsWith("\"")) {
+            input = input.substring(1);
+        }
+
+        if (input.endsWith("\"")) {
+            input = input.substring(0, input.length() - 1);
+        }
+
+        return input;
+    }
+
+    public void modifiedBundle(Bundle bundle, BundleEvent event, Object object) {
+        // nothing to do here
+    }
+
+    public void removedBundle(Bundle bundle, BundleEvent event, Object object) {
+        if (object instanceof List<?>) {
+            for (Object reg : (List<?>) object) {
+                if (reg instanceof ServiceRegistration) {
+                    ((ServiceRegistration) reg).unregister();
+                    log(LogService.LOG_INFO, "Unregistered: " + reg);
+                }
+            }
+        }
+    }
+
+    private void log(int level, String message) {
+        activator.log(level, message);
+    }
+
+    private void log(int level, String message, Throwable th) {
+        activator.log(level, message, th);
+    }
+}

Added: incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/src/extender/SPIClassloaderAdviceServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/src/extender/SPIClassloaderAdviceServiceImpl.java?rev=1030900&view=auto
==============================================================================
--- incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/src/extender/SPIClassloaderAdviceServiceImpl.java
(added)
+++ incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/src/extender/SPIClassloaderAdviceServiceImpl.java
Thu Nov  4 12:18:45 2010
@@ -0,0 +1,36 @@
+/*
+ * 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.
+ */
+package extender;
+
+import org.apache.aries.spifly.api.SPIClassloaderAdviceService;
+
+public class SPIClassloaderAdviceServiceImpl implements
+        SPIClassloaderAdviceService {
+
+    private ClassLoader cl;
+
+    public SPIClassloaderAdviceServiceImpl(ClassLoader cl) {
+        this.cl = cl;
+    }
+
+    public ClassLoader getServiceClassLoader(Class<?> cls) {
+        return cl;
+    }
+
+}

Added: incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/src/org/apache/aries/spifly/api/SPIClassloaderAdviceService.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/src/org/apache/aries/spifly/api/SPIClassloaderAdviceService.java?rev=1030900&view=auto
==============================================================================
--- incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/src/org/apache/aries/spifly/api/SPIClassloaderAdviceService.java
(added)
+++ incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/src/org/apache/aries/spifly/api/SPIClassloaderAdviceService.java
Thu Nov  4 12:18:45 2010
@@ -0,0 +1,25 @@
+/**
+ * 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.
+ */
+package org.apache.aries.spifly.api;
+
+public interface SPIClassloaderAdviceService {
+
+    ClassLoader getServiceClassLoader(Class<?> cls);
+
+}

Added: incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/src/org/apache/aries/spifly/api/SpiFlyConstants.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/src/org/apache/aries/spifly/api/SpiFlyConstants.java?rev=1030900&view=auto
==============================================================================
--- incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/src/org/apache/aries/spifly/api/SpiFlyConstants.java
(added)
+++ incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/src/org/apache/aries/spifly/api/SpiFlyConstants.java
Thu Nov  4 12:18:45 2010
@@ -0,0 +1,55 @@
+/**
+ * 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.
+ */
+package org.apache.aries.spifly.api;
+
+public interface SpiFlyConstants {
+
+    /*
+     * Header names
+     */
+
+    String SPI_CONSUMER_HEADER = "SPI-Consumer";
+
+    String SPI_PROVIDER_HEADER = "SPI-Provider";
+
+    /*
+     * Attributes to be used with the SPI-Provider and SPI-Consumer headers
+     */
+
+    String PROVIDER_NAME_ATTRIBUTE = "provider-name";
+
+    String SERVICE_IDS_ATTRIBUTE = "service-ids";
+
+    /*
+     * Attributes to be used with services created using the 'old' approach
+     */
+
+    String SPI_PROVIDER_URL = "spi.provider.url";
+
+    /*
+     * Attributes to be used with services created using the 'new' approach
+     */
+
+    String SERVICE_ID_SERVICE_ATTRIBUTE = "ServiceId";
+
+    String PROVIDER_NAME_SERVICE_ATTRIBUTE = "ProviderName";
+
+    String API_NAME_SERVICE_ATTRIBUTE = "ApiName";
+
+}

Added: incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/src/org/apache/aries/spifly/util/MultiDelegationClassloader.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/src/org/apache/aries/spifly/util/MultiDelegationClassloader.java?rev=1030900&view=auto
==============================================================================
--- incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/src/org/apache/aries/spifly/util/MultiDelegationClassloader.java
(added)
+++ incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/Extender/src/org/apache/aries/spifly/util/MultiDelegationClassloader.java
Thu Nov  4 12:18:45 2010
@@ -0,0 +1,80 @@
+/**
+ * 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.
+ */
+package org.apache.aries.spifly.util;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.List;
+
+public class MultiDelegationClassloader extends ClassLoader {
+    private final ClassLoader[] delegates;
+    
+    public MultiDelegationClassloader(ClassLoader ... classLoaders) {
+        if (classLoaders == null) 
+            throw new NullPointerException();
+        
+        delegates = classLoaders.clone();
+    }
+    
+    @Override
+    public URL getResource(String name) {
+        for (ClassLoader cl : delegates) {
+            URL res = cl.getResource(name);
+            if (res != null)
+                return res;
+        }                
+        return null;
+    }
+    
+    @Override
+    public InputStream getResourceAsStream(String name) {
+        for (ClassLoader cl : delegates) {
+            InputStream is = cl.getResourceAsStream(name);
+            if (is != null)
+                return is;
+        }
+        return null;
+    }
+    
+    @Override
+    public Enumeration<URL> getResources(String name) throws IOException {
+        List<URL> urls = new ArrayList<URL>();
+        
+        for (ClassLoader cl : delegates) {
+            urls.addAll(Collections.list(cl.getResources(name)));
+        }
+        return Collections.enumeration(urls);
+    }
+    
+    @Override
+    public Class<?> loadClass(String name) throws ClassNotFoundException {
+        ClassNotFoundException lastEx = null;
+        for (ClassLoader cl : delegates) {
+            try {
+                return cl.loadClass(name);
+            } catch (ClassNotFoundException e) {
+                lastEx = e;
+            }
+        }
+        throw lastEx;
+    }
+}
\ No newline at end of file



Mime
View raw message