You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by rw...@apache.org on 2012/12/06 11:11:36 UTC

svn commit: r1417790 - in /stanbol/trunk/commons/namespaceprefix: prefixccprovider/ prefixccprovider/src/ prefixccprovider/src/license/ prefixccprovider/src/main/ prefixccprovider/src/main/java/ prefixccprovider/src/main/java/org/ prefixccprovider/src/...

Author: rwesten
Date: Thu Dec  6 10:11:33 2012
New Revision: 1417790

URL: http://svn.apache.org/viewvc?rev=1417790&view=rev
Log:
STANBOL-825: implementation of a NamespacePrefixProvider for prefix.cc; STANBOL-824: minor adaptions,improvements to other providers

Added:
    stanbol/trunk/commons/namespaceprefix/prefixccprovider/   (with props)
    stanbol/trunk/commons/namespaceprefix/prefixccprovider/README.md
    stanbol/trunk/commons/namespaceprefix/prefixccprovider/pom.xml
    stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/
    stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/license/
    stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/license/THIRD-PARTY.properties
    stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/main/
    stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/main/java/
    stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/main/java/org/
    stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/main/java/org/apache/
    stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/main/java/org/apache/stanbol/
    stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/main/java/org/apache/stanbol/commons/
    stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/main/java/org/apache/stanbol/commons/namespaceprefix/
    stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/main/java/org/apache/stanbol/commons/namespaceprefix/provider/
    stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/main/java/org/apache/stanbol/commons/namespaceprefix/provider/prefixcc/
    stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/main/java/org/apache/stanbol/commons/namespaceprefix/provider/prefixcc/PrefixccProvider.java
    stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/main/java/org/apache/stanbol/commons/namespaceprefix/provider/prefixcc/component/
    stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/main/java/org/apache/stanbol/commons/namespaceprefix/provider/prefixcc/component/PrefixccProviderComponent.java
    stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/main/resources/
    stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/main/resources/META-INF/
    stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/main/resources/META-INF/services/
    stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/main/resources/META-INF/services/org.apache.stanbol.commons.namespaceprefix.NamespacePrefixProvider
    stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/main/resources/OSGI-INF/
    stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/main/resources/OSGI-INF/metatype/
    stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/main/resources/OSGI-INF/metatype/metatype.properties
    stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/test/
    stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/test/java/
    stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/test/java/org/
    stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/test/java/org/apache/
    stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/test/java/org/apache/stanbol/
    stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/test/java/org/apache/stanbol/commons/
    stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/test/java/org/apache/stanbol/commons/namespaceprefix/
    stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/test/java/org/apache/stanbol/commons/namespaceprefix/provider/
    stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/test/java/org/apache/stanbol/commons/namespaceprefix/provider/prefixcc/
    stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/test/java/org/apache/stanbol/commons/namespaceprefix/provider/prefixcc/PrefixccProviderTest.java
    stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/test/resources/
    stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/test/resources/log4j.properties
    stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/test/resources/testnamespaceprefix.mappings
Modified:
    stanbol/trunk/commons/namespaceprefix/service/src/main/java/org/apache/stanbol/commons/namespaceprefix/NamespaceMappingUtils.java
    stanbol/trunk/commons/namespaceprefix/service/src/main/java/org/apache/stanbol/commons/namespaceprefix/service/StanbolNamespacePrefixService.java
    stanbol/trunk/commons/namespaceprefix/stanbolprovider/src/main/java/org/apache/stanbol/commons/namespaceprefix/provider/stanbol/DefaultNamespaceMappingsProvider.java
    stanbol/trunk/commons/namespaceprefix/stanbolprovider/src/main/resources/OSGI-INF/metatype/metatype.properties

Propchange: stanbol/trunk/commons/namespaceprefix/prefixccprovider/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Dec  6 10:11:33 2012
@@ -0,0 +1,7 @@
+target
+
+.classpath
+
+.project
+
+.settings

Added: stanbol/trunk/commons/namespaceprefix/prefixccprovider/README.md
URL: http://svn.apache.org/viewvc/stanbol/trunk/commons/namespaceprefix/prefixccprovider/README.md?rev=1417790&view=auto
==============================================================================
--- stanbol/trunk/commons/namespaceprefix/prefixccprovider/README.md (added)
+++ stanbol/trunk/commons/namespaceprefix/prefixccprovider/README.md Thu Dec  6 10:11:33 2012
@@ -0,0 +1,32 @@
+<!--
+  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.
+-->
+
+Namespace Prefix Provider for prefix.cc
+---------------------------------
+
+This provides an implementation of the NamespacePrefixProvider interface that
+provides all namespace prefixes defined/managed by [prefix.cc](http://prefix.cc).
+
+This implementation can be used within and outside of an OSGI environment.
+When running within OSGI it will deactivate itself if the Stanbol OfflineMode
+is active. 
+
+Mappings are periodically updated but hold locally in-memory. The default update
+cycle is one hour, but can be configured by manually constructing an instance
+or via the OSGI component configuration. 
+
+

Added: stanbol/trunk/commons/namespaceprefix/prefixccprovider/pom.xml
URL: http://svn.apache.org/viewvc/stanbol/trunk/commons/namespaceprefix/prefixccprovider/pom.xml?rev=1417790&view=auto
==============================================================================
--- stanbol/trunk/commons/namespaceprefix/prefixccprovider/pom.xml (added)
+++ stanbol/trunk/commons/namespaceprefix/prefixccprovider/pom.xml Thu Dec  6 10:11:33 2012
@@ -0,0 +1,129 @@
+<?xml version="1.0"?>
+<!--
+  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>
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <groupId>org.apache.stanbol</groupId>
+    <artifactId>stanbol-parent</artifactId>
+    <version>2-SNAPSHOT</version>
+    <relativePath>../../../parent</relativePath>
+  </parent>
+
+  <groupId>org.apache.stanbol</groupId>
+  <artifactId>org.apache.stanbol.commons.namespaceprefix.provider.prefixcc</artifactId>
+  <version>0.10.0-SNAPSHOT</version>
+  <packaging>bundle</packaging>
+
+  <name>Apache Stanbol Commons prefix.cc based Namespace Prefix Provider</name>
+  <description>
+    prefix.cc is a service where users can define namespace prefix mappings
+  </description>
+  <scm>
+    <connection>
+      scm:svn:http://svn.apache.org/repos/asf/stanbol/trunk/commons/namespaceprefix/prefixccprovider
+    </connection>
+    <developerConnection>
+      scm:svn:https://svn.apache.org/repos/asf/stanbol/trunk/commons/namespaceprefix/prefixccprovider
+    </developerConnection>
+    <url>http://stanbol.apache.org/</url>
+  </scm>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-scr-plugin</artifactId>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <extensions>true</extensions>
+        <configuration>
+          <instructions>
+            <Private-Package>
+              org.apache.stanbol.commons.namespaceprefix.provider.prefixcc
+            </Private-Package>
+          </instructions>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <version>2.3.1</version>
+        <configuration>
+          <source>1.6</source>
+          <target>1.6</target>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
+  <dependencies>
+    <dependency>
+	  <groupId>org.apache.stanbol</groupId>
+	  <artifactId>org.apache.stanbol.commons.namespaceprefix.service</artifactId>
+      <version>0.10.0-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.stanbol</groupId>
+      <artifactId>org.apache.stanbol.commons.stanboltools.offline</artifactId>
+      <version>0.9.0-incubating</version>
+      <optional>true</optional>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+    </dependency>
+    <dependency>
+        <groupId>commons-io</groupId>
+        <artifactId>commons-io</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>org.osgi.core</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>org.osgi.compendium</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.felix</groupId>
+      <artifactId>org.apache.felix.scr.annotations</artifactId>
+    </dependency>
+    
+        <!-- testing -->
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>      
+    </dependency>
+    <dependency>  <!-- used for debug level logging during tests -->
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-log4j12</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>log4j</groupId>
+      <artifactId>log4j</artifactId>
+      <scope>test</scope>
+    </dependency>
+    
+    
+  </dependencies>
+</project>

Added: stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/license/THIRD-PARTY.properties
URL: http://svn.apache.org/viewvc/stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/license/THIRD-PARTY.properties?rev=1417790&view=auto
==============================================================================
--- stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/license/THIRD-PARTY.properties (added)
+++ stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/license/THIRD-PARTY.properties Thu Dec  6 10:11:33 2012
@@ -0,0 +1,23 @@
+# Generated by org.codehaus.mojo.license.AddThirdPartyMojo
+#-------------------------------------------------------------------------------
+# Already used licenses in project :
+# - Apache Software License
+# - Apache Software License, Version 2.0
+# - BSD License
+# - Common Development And Distribution License (CDDL), Version 1.0
+# - Common Development And Distribution License (CDDL), Version 1.1
+# - Common Public License, Version 1.0
+# - Eclipse Public License, Version 1.0
+# - GNU General Public License (GPL), Version 2 with classpath exception
+# - GNU Lesser General Public License (LGPL)
+# - GNU Lesser General Public License (LGPL), Version 2.1
+# - MIT License
+# - Public Domain License
+#-------------------------------------------------------------------------------
+# Please fill the missing licenses for dependencies :
+#
+#
+#Mon Apr 09 11:11:04 CEST 2012
+javax.servlet--servlet-api--2.4=Common Development And Distribution License (CDDL), Version 1.0
+org.osgi--org.osgi.compendium--4.1.0=The Apache Software License, Version 2.0
+org.osgi--org.osgi.core--4.1.0=The Apache Software License, Version 2.0

Added: stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/main/java/org/apache/stanbol/commons/namespaceprefix/provider/prefixcc/PrefixccProvider.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/main/java/org/apache/stanbol/commons/namespaceprefix/provider/prefixcc/PrefixccProvider.java?rev=1417790&view=auto
==============================================================================
--- stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/main/java/org/apache/stanbol/commons/namespaceprefix/provider/prefixcc/PrefixccProvider.java (added)
+++ stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/main/java/org/apache/stanbol/commons/namespaceprefix/provider/prefixcc/PrefixccProvider.java Thu Dec  6 10:11:33 2012
@@ -0,0 +1,159 @@
+package org.apache.stanbol.commons.namespaceprefix.provider.prefixcc;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Date;
+import java.util.List;
+import java.util.ServiceLoader;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+import org.apache.stanbol.commons.namespaceprefix.NamespacePrefixProvider;
+import org.apache.stanbol.commons.namespaceprefix.impl.NamespacePrefixProviderImpl;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class PrefixccProvider implements NamespacePrefixProvider {
+
+    private static final Logger log = LoggerFactory.getLogger(PrefixccProvider.class);
+        
+    public static final URL GET_ALL;
+    static {
+        try {
+            GET_ALL = new URL("http://prefix.cc/popular/all.file.txt");
+        } catch (MalformedURLException e) {
+            throw new IllegalStateException("Unable to create http://prefix.cc URL",e);
+        }
+    }
+    private final ScheduledExecutorService scheduler = 
+            Executors.newScheduledThreadPool(1);
+    
+
+    private NamespacePrefixProvider cache;
+    private long cacheStamp;
+
+    /**
+     * Intended to be used by the {@link ServiceLoader} utility.
+     * uses 1 hour delay and DOES a sync initial load of the mappings
+     * before returning.
+     */
+    public PrefixccProvider(){ //by default update once every hour
+        this(1,TimeUnit.HOURS, true);
+    }
+    /**
+     * Creates a prefix.cc provider with the specified delay. The initial
+     * load of the mappings is done immediately but asynchronously. That means
+     * that the mappings will not be available when the constructor returns. <p>
+     * While this implementation does not restrict configured delays expected 
+     * values are in the era of hours.
+     * @param delay the delay
+     * @param unit the unit of the delay.
+     */
+    public PrefixccProvider(int delay,TimeUnit unit){
+        this(delay,unit,false);
+    }
+    /**
+     * Creates a prefix.cc provider. If syncInitialLoad is enabled the initial
+     * load of the data is done before the constructor returns. Otherwise
+     * mappings are loaded asynchronously as specified by the parsed delay.<p>
+     * While this implementation does not restrict configured delays expected 
+     * values are in the era of hours.
+     * @param delay the delay
+     * @param unit the time unit of the delay
+     * @param syncInitialLoad if <code>true</code> mappings are loaded before
+     * the constructor returns. Otherwise mappings are loaded asynchronously
+     */
+    public PrefixccProvider(int delay,TimeUnit unit, boolean syncInitialLoad){
+        if(delay <= 0){
+            throw new IllegalArgumentException("The parsed delay '"
+                +delay+"' MUST NOT be <= 0");
+        }
+        if(unit == null){
+            unit = TimeUnit.SECONDS;
+        }
+        int initialDelay;
+        if(syncInitialLoad){
+            loadMappings();
+            initialDelay = delay;
+        } else {
+            initialDelay = 0;
+        }
+        scheduler.scheduleWithFixedDelay(
+            new Runnable() {
+                
+                @Override
+                public void run() {
+                    loadMappings();
+                }
+            }, initialDelay, delay, unit);
+    }
+    
+    protected final void loadMappings() {
+        try {
+            log.info("Load Namespace Prefix Mappings form {}",GET_ALL);
+            cache = new NamespacePrefixProviderImpl(GET_ALL.openStream());
+            cacheStamp = System.currentTimeMillis();
+            log.info("  ... completed");
+        } catch (IOException e) {
+            log.warn("Unable to load prefix.cc NamespaceMappings (Message: "
+                + e.getMessage() +")",e);
+            ;
+        }
+    }
+    /**
+     * deletes the local cahe and stops the periodical updates of the cache
+     */
+    public void close(){
+        scheduler.shutdown();
+        cache = null;
+    }
+    
+    /**
+     * If prefix.cc data are available
+     * @return
+     */
+    public boolean isAvailable(){
+        return cache != null;
+    }
+    /**
+     * The Date where the locally cached data where synced the last time with
+     * prefix.cc. Will return <code>null</code> if no data where received from
+     * prefix.cc (<code>{@link #isAvailable()} == false</code>)
+     * @return the date where the local cache was received from prefix.cc
+     */
+    public Date getCacheTimeStamp(){
+        if(cache != null){
+            return new Date(cacheStamp);
+        } else {
+            return null;
+        }
+    }
+    
+    @Override
+    protected void finalize() throws Throwable {
+        close();
+        super.finalize();
+    }
+    
+    @Override
+    public String getNamespace(String prefix) {
+        NamespacePrefixProvider npp = cache;
+        return npp == null ? null : npp.getNamespace(prefix);
+    }
+    
+    @Override
+    public String getPrefix(String namespace) {
+        NamespacePrefixProvider npp = cache;
+        return npp == null ? null : npp.getPrefix(namespace);
+    }
+    @Override
+    public List<String> getPrefixes(String namespace) {
+        NamespacePrefixProvider npp = cache;
+        return npp == null ? null : npp.getPrefixes(namespace);
+    }
+}

Added: stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/main/java/org/apache/stanbol/commons/namespaceprefix/provider/prefixcc/component/PrefixccProviderComponent.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/main/java/org/apache/stanbol/commons/namespaceprefix/provider/prefixcc/component/PrefixccProviderComponent.java?rev=1417790&view=auto
==============================================================================
--- stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/main/java/org/apache/stanbol/commons/namespaceprefix/provider/prefixcc/component/PrefixccProviderComponent.java (added)
+++ stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/main/java/org/apache/stanbol/commons/namespaceprefix/provider/prefixcc/component/PrefixccProviderComponent.java Thu Dec  6 10:11:33 2012
@@ -0,0 +1,143 @@
+package org.apache.stanbol.commons.namespaceprefix.provider.prefixcc.component;
+
+import java.math.BigDecimal;
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.ConfigurationPolicy;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Properties;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.apache.felix.scr.annotations.ReferencePolicy;
+import org.apache.felix.scr.annotations.ReferenceStrategy;
+import org.apache.stanbol.commons.namespaceprefix.NamespacePrefixProvider;
+import org.apache.stanbol.commons.namespaceprefix.provider.prefixcc.PrefixccProvider;
+import org.apache.stanbol.commons.stanboltools.offline.OfflineMode;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.cm.ConfigurationException;
+import org.osgi.service.component.ComponentContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * OSGI component configuring and registering the {@link PrefixccProvider}.
+ * Non-OSGI users do not need to bother with this. <p>
+ * This class mainly exists to keep the {@link PrefixccProvider} independent of
+ * the Stanbol {@link OfflineMode} switch
+ * 
+ * @author Rupert Westenthaler
+ *
+ */
+@Component(immediate=true,policy=ConfigurationPolicy.OPTIONAL,metatype = true)
+@Properties(value={
+    @Property(name=PrefixccProviderComponent.UPDATE_INTERVAL,intValue=60),
+    @Property(name=Constants.SERVICE_RANKING,intValue=-100)
+})
+public class PrefixccProviderComponent {
+
+    private Logger log = LoggerFactory.getLogger(PrefixccProviderComponent.class);
+    
+    /**
+     * The duration 
+     */
+    public static final String UPDATE_INTERVAL = "stanbol.commons.namespaceprovider.prefixcc.update-interval";
+    public static final int DEFAULT_UPDATE_INTERVAL = 60;
+    
+    ServiceRegistration providerRegistration;
+    
+    @Reference(cardinality=ReferenceCardinality.OPTIONAL_UNARY,
+            policy=ReferencePolicy.DYNAMIC,strategy=ReferenceStrategy.EVENT,
+            bind="bindOfflineMode",unbind="unbindOfflineMode")
+    private OfflineMode offlineMode;
+    
+    int updateInterval;
+    private Dictionary<String,Object> providerProperties = null;
+    private BundleContext bc;
+    private PrefixccProvider provider;
+    
+    protected void bindOfflineMode(OfflineMode mode){
+        this.offlineMode = mode;
+        updateProviderState();
+    }
+    protected void unbindOfflineMode(OfflineMode mode){
+        this.offlineMode = null;
+        updateProviderState();
+    }
+    
+    @Activate
+    protected void activate(ComponentContext ctx) throws ConfigurationException {
+        bc = ctx.getBundleContext();
+        Object value = ctx.getProperties().get(UPDATE_INTERVAL);
+        if(value instanceof Number){
+            updateInterval = ((Number)value).intValue();
+        } else if(value != null && !value.toString().isEmpty()){
+            try {
+                updateInterval = new BigDecimal(value.toString()).intValue();
+            } catch (NumberFormatException e) {
+                throw new ConfigurationException(UPDATE_INTERVAL, 
+                    "Unable to parse integer value from the configured value '"
+                    + value +"' (type: "+value.getClass()+")");
+            }
+        } else {
+            updateInterval = DEFAULT_UPDATE_INTERVAL;
+        }
+        if(updateInterval < 0){
+            log.warn("Negative update interval '{}' configured. Will use default '{}'!",
+                updateInterval,DEFAULT_UPDATE_INTERVAL);
+            updateInterval = DEFAULT_UPDATE_INTERVAL;
+        } else if(updateInterval == 0){
+            updateInterval = DEFAULT_UPDATE_INTERVAL;
+        }
+        //we need to copy over the service ranking
+        providerProperties = new Hashtable<String,Object>();
+        Object ranking = ctx.getProperties().get(Constants.SERVICE_RANKING);
+        if(ranking != null){
+            providerProperties.put(Constants.SERVICE_RANKING, ranking);
+        }
+        updateProviderState();
+    }
+
+    @Deactivate
+    protected void deactivate(ComponentContext ctx){
+        providerProperties = null;
+        updateProviderState();
+        bc = null;
+    }
+    
+    /**
+     * uses the {@link #providerProperties} and {@link #offlineMode}
+     * state to decide if the {@link PrefixccProvider} should be registered as
+     * a service or not. If the current state is different the desired state it
+     * creates and register / unregister destroys the {@link #provider<p>
+     * Consumes: {@link #providerProperties} and {@link #offlineMode}<br>
+     * Manages: {@link #provider} and {@link #providerRegistration}
+     */
+    private synchronized void updateProviderState(){
+        if(providerProperties != null && offlineMode == null){ //register
+            if(providerRegistration == null){
+                provider = new PrefixccProvider(updateInterval, TimeUnit.MINUTES);
+                providerRegistration = bc.registerService(
+                    NamespacePrefixProvider.class.getName(), provider, providerProperties);
+                log.info("registered prefix.cc NamespacePrefixProvider ...");
+            }
+        } else { //unregister
+            if(providerRegistration != null){
+                providerRegistration.unregister();
+                log.info("unregistered prefix.cc NamespacePrefixProvider ...");
+            }
+            if(provider != null){
+                provider.close();
+                provider = null;
+            }
+        }
+    }
+    
+    
+}

Added: stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/main/resources/META-INF/services/org.apache.stanbol.commons.namespaceprefix.NamespacePrefixProvider
URL: http://svn.apache.org/viewvc/stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/main/resources/META-INF/services/org.apache.stanbol.commons.namespaceprefix.NamespacePrefixProvider?rev=1417790&view=auto
==============================================================================
--- stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/main/resources/META-INF/services/org.apache.stanbol.commons.namespaceprefix.NamespacePrefixProvider (added)
+++ stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/main/resources/META-INF/services/org.apache.stanbol.commons.namespaceprefix.NamespacePrefixProvider Thu Dec  6 10:11:33 2012
@@ -0,0 +1 @@
+org.apache.stanbol.commons.namespaceprefix.provider.prefixcc.PrefixccProvider
\ No newline at end of file

Added: stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/main/resources/OSGI-INF/metatype/metatype.properties
URL: http://svn.apache.org/viewvc/stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/main/resources/OSGI-INF/metatype/metatype.properties?rev=1417790&view=auto
==============================================================================
--- stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/main/resources/OSGI-INF/metatype/metatype.properties (added)
+++ stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/main/resources/OSGI-INF/metatype/metatype.properties Thu Dec  6 10:11:33 2012
@@ -0,0 +1,28 @@
+# 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.
+
+org.apache.stanbol.commons.namespaceprefix.provider.prefixcc.component.PrefixccProviderComponent.name=Stanbol \
+Commons Namespace Prefix Provider for http://prefix.cc
+org.apache.stanbol.commons.namespaceprefix.provider.prefixcc.component.PrefixccProviderComponent.description=This \
+Namespace Prefix Provider provides mappings as manged by http://prefix.cc. It downloads priodically all \
+available mappings and caches them locally in-memory. This provider is only available if OfflineMode is NOT active.
+
+stanbol.commons.namespaceprovider.prefixcc.update-interval.name=Update Interval
+stanbol.commons.namespaceprovider.prefixcc.update-interval.description=The interval in minutes \
+used by the provider to reload mappings from http://prefix.cc
+
+service.ranking.name=Service Ranking
+service.ranking.description=Namespace prefix mappings from providers with a higher ranking will \
+override those with lower rankings. 
\ No newline at end of file

Added: stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/test/java/org/apache/stanbol/commons/namespaceprefix/provider/prefixcc/PrefixccProviderTest.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/test/java/org/apache/stanbol/commons/namespaceprefix/provider/prefixcc/PrefixccProviderTest.java?rev=1417790&view=auto
==============================================================================
--- stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/test/java/org/apache/stanbol/commons/namespaceprefix/provider/prefixcc/PrefixccProviderTest.java (added)
+++ stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/test/java/org/apache/stanbol/commons/namespaceprefix/provider/prefixcc/PrefixccProviderTest.java Thu Dec  6 10:11:33 2012
@@ -0,0 +1,88 @@
+package org.apache.stanbol.commons.namespaceprefix.provider.prefixcc;
+
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Date;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.stanbol.commons.namespaceprefix.NamespacePrefixService;
+import org.apache.stanbol.commons.namespaceprefix.service.StanbolNamespacePrefixService;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class PrefixccProviderTest {
+    
+    private static final Logger log = LoggerFactory.getLogger(PrefixccProviderTest.class);
+
+    private static String foaf_ns = "http://xmlns.com/foaf/0.1/";
+    private static String foaf_pf = "foaf";
+    
+        
+    @Test
+    public void test(){
+        Date date = new Date();
+        PrefixccProvider pcp = new PrefixccProvider(10,TimeUnit.SECONDS);
+        Assert.assertNull(pcp.getPrefix(foaf_ns)); //async loading
+        for(int i =0; i<5 && !pcp.isAvailable();i++){
+            try {
+               Thread.sleep(1000);
+            } catch (InterruptedException e) {}
+        }
+        if(!pcp.isAvailable()){
+            log.warn("Unable to obtain prefix.cc data after 5sec .. skipping further tests");
+            return;
+        }
+        //assertMappings
+        Assert.assertEquals(foaf_pf, pcp.getPrefix(foaf_ns));
+        Assert.assertEquals(foaf_ns, pcp.getNamespace(foaf_pf));
+        //assert cache time stamp
+        Date cacheDate = pcp.getCacheTimeStamp();
+        Assert.assertTrue(date.compareTo(cacheDate) == -1);
+        Assert.assertTrue(new Date().compareTo(cacheDate) >= 0);
+        //assert close
+        pcp.close();
+        Assert.assertFalse(pcp.isAvailable());
+        Assert.assertNull(pcp.getCacheTimeStamp());
+    }
+    
+    @Test
+    public void testServiceLoader() throws IOException{
+        //this test works only if online
+        try {
+            PrefixccProvider.GET_ALL.openStream();
+        } catch (IOException e) {
+           log.info("Unable to connect to http://prefix.cc ... deactivating "
+               + PrefixccProvider.class.getSimpleName()+ "ServiceLoader support test");
+           return;
+        }
+        
+        //this test for now does not use predefined mappings
+        
+        URL mappingURL = PrefixccProviderTest.class.getClassLoader()
+                .getResource("testnamespaceprefix.mappings");
+        //Assert.assertNotNull(mappingURL);
+        File mappingFile;
+        if(mappingURL != null){
+            try {
+              mappingFile = new File(mappingURL.toURI());
+            } catch(URISyntaxException e) {
+              mappingFile = new File(mappingURL.getPath());
+            }
+            //Assert.assertTrue(mappingFile.isFile());
+        } else {
+            mappingFile = new File("testnamespaceprefix.mappings");
+        }
+        NamespacePrefixService service = new StanbolNamespacePrefixService(mappingFile);
+        //assertMappings
+        Assert.assertEquals(foaf_pf, service.getPrefix(foaf_ns));
+        Assert.assertEquals(foaf_ns, service.getNamespace(foaf_pf));
+        
+    }
+    
+}

Added: stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/test/resources/log4j.properties?rev=1417790&view=auto
==============================================================================
--- stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/test/resources/log4j.properties (added)
+++ stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/test/resources/log4j.properties Thu Dec  6 10:11:33 2012
@@ -0,0 +1,24 @@
+# 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.
+
+# Root logger option
+log4j.rootLogger=INFO, stdout
+ 
+# Direct log messages to stdout
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.Target=System.out
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
+log4j.logger.org.apache.stanbol.enhancer.engines.keywordextraction=DEBUG
\ No newline at end of file

Added: stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/test/resources/testnamespaceprefix.mappings
URL: http://svn.apache.org/viewvc/stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/test/resources/testnamespaceprefix.mappings?rev=1417790&view=auto
==============================================================================
--- stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/test/resources/testnamespaceprefix.mappings (added)
+++ stanbol/trunk/commons/namespaceprefix/prefixccprovider/src/test/resources/testnamespaceprefix.mappings Thu Dec  6 10:11:33 2012
@@ -0,0 +1 @@
+dummy	http://test.dummy.org/
\ No newline at end of file

Modified: stanbol/trunk/commons/namespaceprefix/service/src/main/java/org/apache/stanbol/commons/namespaceprefix/NamespaceMappingUtils.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/commons/namespaceprefix/service/src/main/java/org/apache/stanbol/commons/namespaceprefix/NamespaceMappingUtils.java?rev=1417790&r1=1417789&r2=1417790&view=diff
==============================================================================
--- stanbol/trunk/commons/namespaceprefix/service/src/main/java/org/apache/stanbol/commons/namespaceprefix/NamespaceMappingUtils.java (original)
+++ stanbol/trunk/commons/namespaceprefix/service/src/main/java/org/apache/stanbol/commons/namespaceprefix/NamespaceMappingUtils.java Thu Dec  6 10:11:33 2012
@@ -3,6 +3,10 @@ package org.apache.stanbol.commons.names
 
 import java.util.regex.Pattern;
 
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.osgi.service.cm.ConfigurationException;
+
 public class NamespaceMappingUtils {
     /**
      * This pattern checks for invalid chars within an prefix.
@@ -101,4 +105,78 @@ public class NamespaceMappingUtils {
                     namespace.charAt(namespace.length()-1) == '/') && 
                     namespace.indexOf(":/") > 0;
     }
+    
+    
+    /**
+     * Utility intended to be used during activate of OSGI components that support
+     * the use of '{prefix}:{localname}' in its configurations. The
+     * {@link NamespacePrefixService} is assumed as optional so that users can
+     * use <code>ReferenceCardinality.OPTIONAL_UNARY</code> to inject the service.
+     * <p>
+     * Here is an example
+     * <code><pre>
+     *     @Reference(cardinality=ReferenceCardinality.OPTIONAL_UNARY)
+     *     protected NamespacePrefixService nps;
+     * </pre></code>
+     * @param nps the {@link NamespacePrefixService} or <code>null</code> if not
+     * available
+     * @param property the configuration property (used for creating {@link ConfigurationException}s)
+     * @param value configured value. Might be both a '{prefix}:{localname}' or the full URI.
+     * @return the full URI
+     * @throws ConfigurationException if the conversion was not possible because
+     * the {@link #nsPrefixService} is <code>null</code> or the prefix is 
+     * unknown to the service
+     */
+    public static String getConfiguredUri(NamespacePrefixService nps, String property, String value) throws ConfigurationException{
+        if(nps != null){
+            String fieldUri = nps.getFullName(value);
+            if(fieldUri == null){
+                throw new ConfigurationException(property, "The prefix '"
+                        + NamespaceMappingUtils.getPrefix(value)+"' is unknown (not mapped to an "
+                        + "namespace) by the Stanbol Namespace Prefix Mapping Service. Please "
+                        + "change the configuration to use the full URI instead of '"+value+"'!");
+            }
+            return fieldUri;
+        } else if(NamespaceMappingUtils.getPrefix(value) != null){
+            throw new ConfigurationException(property, "'{prefix}:{localname}' configurations "
+                + "such as '"+value+"' are only supported if the NamespacePrefixService is "
+                + "available for the Stanbol instance (what is currently not the case). Please "
+                + "change the configuration to use the full URI");
+        } else { //no service but a full uri
+            return value;
+        }
+    }
+    
+    /**
+     * Utility intended to be used to by components that do allow the use of
+     * '{prefix}:{localname}' in its configurations. The {@link NamespacePrefixService}
+     * is considered optional.  
+     * @param nps the {@link NamespacePrefixService} or <code>null</code> if not
+     * available
+     * @param value configured value. Might be both a '{prefix}:{localname}' or the full URI.
+     * @return the full URI
+     * @throws IllegalArgumentException if the conversion was not possible because
+     * the {@link #nsPrefixService} is <code>null</code> or the prefix is 
+     * unknown to the service
+     */
+    public static String getConfiguredUri(NamespacePrefixService nps, String value) throws IllegalArgumentException {
+        if(nps != null){
+            String fieldUri = nps.getFullName(value);
+            if(fieldUri == null){
+                throw new IllegalArgumentException("The prefix '"
+                        + NamespaceMappingUtils.getPrefix(value)+"' is unknown (not mapped to an "
+                        + "namespace) by the Stanbol Namespace Prefix Mapping Service. Please "
+                        + "change the configuration to use the full URI instead of '"+value+"'!");
+            }
+            return fieldUri;
+        } else if(NamespaceMappingUtils.getPrefix(value) != null){
+            throw new IllegalArgumentException("'{prefix}:{localname}' configurations "
+                + "such as '"+value+"' are only supported if the NamespacePrefixService is "
+                + "available for the Stanbol instance (what is currently not the case). Please "
+                + "change the configuration to use the full URI");
+        } else { //no service but a full uri
+            return value;
+        }
+    }
+    
 }

Modified: stanbol/trunk/commons/namespaceprefix/service/src/main/java/org/apache/stanbol/commons/namespaceprefix/service/StanbolNamespacePrefixService.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/commons/namespaceprefix/service/src/main/java/org/apache/stanbol/commons/namespaceprefix/service/StanbolNamespacePrefixService.java?rev=1417790&r1=1417789&r2=1417790&view=diff
==============================================================================
--- stanbol/trunk/commons/namespaceprefix/service/src/main/java/org/apache/stanbol/commons/namespaceprefix/service/StanbolNamespacePrefixService.java (original)
+++ stanbol/trunk/commons/namespaceprefix/service/src/main/java/org/apache/stanbol/commons/namespaceprefix/service/StanbolNamespacePrefixService.java Thu Dec  6 10:11:33 2012
@@ -67,13 +67,23 @@ public class StanbolNamespacePrefixServi
     private SortedMap<String,List<String>> namespaceMap = new TreeMap<String,List<String>>();
     
     /**
-     * OSGI constructor
+     * OSGI constructor <b> DO NOT USE</b> outside of an OSGI environment as this
+     * will not initialise the {@link NamespacePrefixProvider} using the
+     * {@link ServiceLoader} utility!
      */
     public StanbolNamespacePrefixService(){}
     
+    /**
+     * Constructs an Stanbol NamespacePrefixService and initialises other
+     * {@link NamespacePrefixProvider} implementations using the
+     * Java {@link ServiceLoader} utility.
+     * @param mappingFile the mapping file used to manage local mappings. If
+     * <code>null</code> no local mappings are supported.
+     * @throws IOException
+     */
     public StanbolNamespacePrefixService(File mappingFile) throws IOException {
         this.mappingsFile = mappingFile;
-        if(mappingsFile.isFile()){
+        if(mappingsFile != null && mappingsFile.isFile()){
             readPrefixMappings(new FileInputStream(mappingsFile));
         } //else no mappings yet ... nothing todo
         loader = ServiceLoader.load(NamespacePrefixProvider.class);
@@ -185,7 +195,9 @@ public class StanbolNamespacePrefixServi
                         if(!mappingsFile.isFile()){
                             mappingsFile.createNewFile();
                         }
-                        writePrefixMappings(new FileOutputStream(mappingsFile, false));
+                        if(mappingsFile != null){
+                            writePrefixMappings(new FileOutputStream(mappingsFile, false));
+                        } //else do not persist mappings
                     }
                     //(2) update the inverse mappings (ensure read only lists!)
                     List<String> prefixes = namespaceMap.get(namespace);

Modified: stanbol/trunk/commons/namespaceprefix/stanbolprovider/src/main/java/org/apache/stanbol/commons/namespaceprefix/provider/stanbol/DefaultNamespaceMappingsProvider.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/commons/namespaceprefix/stanbolprovider/src/main/java/org/apache/stanbol/commons/namespaceprefix/provider/stanbol/DefaultNamespaceMappingsProvider.java?rev=1417790&r1=1417789&r2=1417790&view=diff
==============================================================================
--- stanbol/trunk/commons/namespaceprefix/stanbolprovider/src/main/java/org/apache/stanbol/commons/namespaceprefix/provider/stanbol/DefaultNamespaceMappingsProvider.java (original)
+++ stanbol/trunk/commons/namespaceprefix/stanbolprovider/src/main/java/org/apache/stanbol/commons/namespaceprefix/provider/stanbol/DefaultNamespaceMappingsProvider.java Thu Dec  6 10:11:33 2012
@@ -12,7 +12,7 @@ import org.osgi.framework.Constants;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-@Component(immediate=true)
+@Component(immediate=true, metatype=true)
 @Service
 @Property(name=Constants.SERVICE_RANKING,value="1000000")
 public class DefaultNamespaceMappingsProvider extends NamespacePrefixProviderImpl implements NamespacePrefixProvider {

Modified: stanbol/trunk/commons/namespaceprefix/stanbolprovider/src/main/resources/OSGI-INF/metatype/metatype.properties
URL: http://svn.apache.org/viewvc/stanbol/trunk/commons/namespaceprefix/stanbolprovider/src/main/resources/OSGI-INF/metatype/metatype.properties?rev=1417790&r1=1417789&r2=1417790&view=diff
==============================================================================
--- stanbol/trunk/commons/namespaceprefix/stanbolprovider/src/main/resources/OSGI-INF/metatype/metatype.properties (original)
+++ stanbol/trunk/commons/namespaceprefix/stanbolprovider/src/main/resources/OSGI-INF/metatype/metatype.properties Thu Dec  6 10:11:33 2012
@@ -13,9 +13,13 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-org.apache.stanbol.commons.stanboltools.namespaceprefixservice.stanbol.DefaultNamespaceMappingsProvider.name=Stanbol \
+org.apache.stanbol.commons.namespaceprefix.provider.stanbol.DefaultNamespaceMappingsProvider.name=Stanbol \
 Commons Namespace Prefix Provider for Stanbol Default Namespaces
-org.apache.stanbol.commons.stanboltools.namespaceprefixservice.stanbol.DefaultNamespaceMappingsProvider.description=This \
+org.apache.stanbol.commons.namespaceprefix.provider.stanbol.DefaultNamespaceMappingsProvider.description=This \
 Namespace Prefix Provider provides mappings that where previously exposed by the NamespaceEnum's of the \
 Stanbol Enhancer and the Stanbol Entityhub. Its intension is to ensure backward compatibility to \
-configurations used before the introduction of the Stanbol Namespace Prefix Mapping Service.
\ No newline at end of file
+configurations used before the introduction of the Stanbol Namespace Prefix Mapping Service.
+
+service.ranking.name=Service Ranking
+service.ranking.description=Namespace prefix mappings from providers with a higher ranking will \
+override those with lower rankings. 
\ No newline at end of file