From: <my...@us...> - 2009-02-10 20:24:31
|
Revision: 1631 http://aperture.svn.sourceforge.net/aperture/?rev=1631&view=rev Author: mylka Date: 2009-02-10 20:24:22 +0000 (Tue, 10 Feb 2009) Log Message: ----------- finishing touches on the extractor core module - added the ExtractorServiceActivator Modified Paths: -------------- aperture/trunk/core/extractor/core/pom.xml Added Paths: ----------- aperture/trunk/core/extractor/core/src/main/java/org/semanticdesktop/aperture/extractor/bundle/ExtractorServiceActivator.java Modified: aperture/trunk/core/extractor/core/pom.xml =================================================================== --- aperture/trunk/core/extractor/core/pom.xml 2009-02-10 20:15:20 UTC (rev 1630) +++ aperture/trunk/core/extractor/core/pom.xml 2009-02-10 20:24:22 UTC (rev 1631) @@ -53,22 +53,23 @@ <build> <plugins> -<!-- <plugin>--> -<!-- <artifactId>maven-jar-plugin</artifactId>--> -<!-- <configuration>--> -<!-- <archive> --> -<!-- <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>--> -<!-- </archive> --> -<!-- </configuration>--> -<!-- </plugin> --> + <plugin> + <artifactId>maven-jar-plugin</artifactId> + <configuration> + <archive> + <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile> + </archive> + </configuration> + </plugin> <plugin> <groupId>org.apache.felix</groupId> <artifactId>maven-bundle-plugin</artifactId> <extensions>true</extensions> <configuration> <instructions> - <Export-Package>org.semanticdesktop.aperture.extractor.*</Export-Package> -<!-- <Bundle-Activator>org.semanticdesktop.aperture.extractor.bundle.DataSourceServiceActivator</Bundle-Activator>--> + <Export-Package>org.semanticdesktop.aperture.extractor</Export-Package> + <Private-Package>org.semanticdesktop.aperture.extractor.impl,org.semanticdesktop.aperture.extractor.impl</Private-Package> + <Bundle-Activator>org.semanticdesktop.aperture.extractor.bundle.ExtractorServiceActivator</Bundle-Activator> </instructions> </configuration> </plugin> Copied: aperture/trunk/core/extractor/core/src/main/java/org/semanticdesktop/aperture/extractor/bundle/ExtractorServiceActivator.java (from rev 1610, trunk/aperture/src/activators/org/semanticdesktop/aperture/extractor/ExtractorServiceActivator.java) =================================================================== --- aperture/trunk/core/extractor/core/src/main/java/org/semanticdesktop/aperture/extractor/bundle/ExtractorServiceActivator.java (rev 0) +++ aperture/trunk/core/extractor/core/src/main/java/org/semanticdesktop/aperture/extractor/bundle/ExtractorServiceActivator.java 2009-02-10 20:24:22 UTC (rev 1631) @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2006 - 2008 Aduna and Deutsches Forschungszentrum fuer Kuenstliche Intelligenz DFKI GmbH. + * All rights reserved. + * + * Licensed under the Aperture BSD-style license. + */ +package org.semanticdesktop.aperture.extractor; + +import java.util.Hashtable; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceEvent; +import org.osgi.framework.ServiceListener; +import org.osgi.framework.ServiceReference; +import org.osgi.framework.ServiceRegistration; +import org.semanticdesktop.aperture.extractor.impl.ExtractorRegistryImpl; + +/** + * Listens for changes in registered ExtractorFactories and FileExtractorFactories. + * Needs two listeners for this (listeners are replaced) + */ +public class ExtractorServiceActivator implements BundleActivator, ServiceListener { + + public static BundleContext bc = null; + + private ServiceRegistration registration; + + private ExtractorRegistry registry; + + public void start(BundleContext context) throws Exception { + + bc = context; + registry = new ExtractorRegistryImpl(); + registration = bc.registerService(ExtractorRegistry.class.getName(), registry, + new Hashtable()); + + + String filter = "(objectclass=" + ExtractorFactory.class.getName() + ")"; + // ATTENTION: here we register THIS + bc.addServiceListener(this, filter); + + ServiceReference references[] = bc.getServiceReferences(null, filter); + + for (int i = 0; references != null && i < references.length; i++) { + this.serviceChanged(new ServiceEvent(ServiceEvent.REGISTERED, references[i])); + } + + filter = "(objectclass=" + FileExtractorFactory.class.getName() + ")"; + // ATTENTION: here we register another object, otherwise this overrides above listener + bc.addServiceListener(new ServiceListener() { + public void serviceChanged(ServiceEvent event) { + ExtractorServiceActivator.this.serviceChanged(event); + } + }, filter); + + references = bc.getServiceReferences(null, filter); + + for (int i = 0; references != null && i < references.length; i++) { + this.serviceChanged(new ServiceEvent(ServiceEvent.REGISTERED, references[i])); + } + + + } + + public void stop(BundleContext context) throws Exception { + registration.unregister(); + bc = null; + } + + public void serviceChanged(ServiceEvent event) { + Object instance = null; + switch (event.getType()) { + case ServiceEvent.REGISTERED: + instance = ExtractorServiceActivator.bc.getService(event.getServiceReference()); + if (instance instanceof ExtractorFactory) { + registry.add((ExtractorFactory)instance); + } else if (instance instanceof FileExtractorFactory) { + registry.add((FileExtractorFactory)instance); + } + break; + case ServiceEvent.MODIFIED: + instance = ExtractorServiceActivator.bc.getService(event.getServiceReference()); + if (instance instanceof ExtractorFactory) { + registry.remove((ExtractorFactory)instance); + registry.add((ExtractorFactory)instance); + } else if (instance instanceof FileExtractorFactory) { + registry.remove((FileExtractorFactory)instance); + registry.add((FileExtractorFactory)instance); + } + break; + case ServiceEvent.UNREGISTERING: + instance = ExtractorServiceActivator.bc.getService(event.getServiceReference()); + if (instance instanceof ExtractorFactory) { + registry.remove((ExtractorFactory)instance); + } else if (instance instanceof FileExtractorFactory) { + registry.remove((FileExtractorFactory)instance); + } + break; + } + } +} Property changes on: aperture/trunk/core/extractor/core/src/main/java/org/semanticdesktop/aperture/extractor/bundle/ExtractorServiceActivator.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:mergeinfo + /branches/smila-prep-branch/aperture/src/activators/org/semanticdesktop/aperture/extractor/ExtractorServiceActivator.java:1513-1527 Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |