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 2011/03/25 06:12:04 UTC

svn commit: r1085255 [2/2] - in /incubator/stanbol/trunk/entityhub: generic/core/src/main/java/org/apache/stanbol/entityhub/core/impl/ generic/core/src/main/java/org/apache/stanbol/entityhub/core/mapping/ generic/core/src/main/java/org/apache/stanbol/e...

Copied: incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/SolrServerProviderManager.java (from r1082929, incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/provider/SolrServerProviderManager.java)
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/SolrServerProviderManager.java?p2=incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/SolrServerProviderManager.java&p1=incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/provider/SolrServerProviderManager.java&r1=1082929&r2=1085255&rev=1085255&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/provider/SolrServerProviderManager.java (original)
+++ incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/SolrServerProviderManager.java Fri Mar 25 05:12:03 2011
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.stanbol.entityhub.yard.solr.provider;
+package org.apache.stanbol.entityhub.yard.solr;
 
 import java.util.Collections;
 import java.util.EnumMap;
@@ -33,7 +33,9 @@ import org.apache.felix.scr.annotations.
 import org.apache.felix.scr.annotations.ReferenceStrategy;
 import org.apache.felix.scr.annotations.Service;
 import org.apache.solr.client.solrj.SolrServer;
-import org.apache.stanbol.entityhub.yard.solr.provider.SolrServerProvider.Type;
+import org.apache.stanbol.entityhub.yard.solr.SolrServerProvider.Type;
+import org.apache.stanbol.entityhub.yard.solr.impl.DefaultSolrServerProvider;
+import org.apache.stanbol.entityhub.yard.solr.impl.EmbeddedSolrPorovider;
 import org.osgi.service.component.ComponentContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -43,7 +45,22 @@ import org.slf4j.LoggerFactory;
  * environment.
  * This manager works both within an OSGI Environment by defining an Reference
  * and outside by using {@link #getInstance()}.
- * 
+ * <p>
+ * <b>TODO:</b> Race Condition (Rupert Westenthaler, 2011-03-21)
+ *   There are cases where the SolrYard requests a provider {@link Type} before
+ *   the actual {@link SolrServerProvider} instance that supports this type has
+ *   initialised. In such cases the {@link #getSolrServer(Type, String, String...)}
+ *   would return an {@link IllegalArgumentException} what causes the
+ *   initialisation of the SolrYard to fail.<br>
+ *   For now this problem is solved by declaring a dependency of this manager
+ *   implementation to both the {@link EmbeddedSolrPorovider} and the
+ *   {@link DefaultSolrServerProvider}. This ensures that this manager is only
+ *   activated after this two implementations are available. <br>
+ *   A different solution that could ensure that the SolrYard does not request
+ *   an SolrServer before all the internal {@link SolrServerProvider}
+ *   implementations are initialised would be favourable.
+ *   
+ *   
  * @author Rupert Westenthaler
  *
  */
@@ -57,6 +74,14 @@ public final class SolrServerProviderMan
      */
     private static SolrServerProviderManager solrServerProviderManager;
     
+//    //TODO See Race Condition in class doc
+//    @Reference
+//    private EmbeddedSolrPorovider embeddedProvider;
+//    
+//    //TODO See Race Condition in class doc
+//    @Reference
+//    private DefaultSolrServerProvider defaultProvider;
+    
     private final static Logger log = LoggerFactory.getLogger(SolrServerProviderManager.class);
     @Reference(
         referenceInterface=SolrServerProvider.class,

Propchange: incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/SolrServerProviderManager.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/DefaultSolrDirectoryManager.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/DefaultSolrDirectoryManager.java?rev=1085255&view=auto
==============================================================================
--- incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/DefaultSolrDirectoryManager.java (added)
+++ incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/DefaultSolrDirectoryManager.java Fri Mar 25 05:12:03 2011
@@ -0,0 +1,238 @@
+/*
+ * 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.stanbol.entityhub.yard.solr.impl;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.io.filefilter.DirectoryFileFilter;
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+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.Service;
+import org.apache.stanbol.entityhub.yard.solr.SolrDirectoryManager;
+import org.apache.stanbol.entityhub.yard.solr.utils.ConfigUtils;
+import org.osgi.service.component.ComponentContext;
+
+/**
+ * Implementation of the {@link SolrDirectoryManager} interface that supports
+ * the dynamic initialisation of new cores based on the default core configuration
+ * contained within the SolrYard bundle.
+ * 
+ * @author Rupert Westenthaler
+ *
+ */
+@Component(immediate=true,metatype=true)
+@Service
+@Properties(value={
+           @Property(name=SolrDirectoryManager.MANAGED_SOLR_DIR_PROPERTY,value=SolrDirectoryManager.DEFAULT_SOLR_DATA_DIR)
+    })
+public class DefaultSolrDirectoryManager implements SolrDirectoryManager {
+    //private final Logger log = LoggerFactory.getLogger(DefaultSolrDirectoryManager.class);
+    /**
+     * The directory used by the internally managed embedded solr server.
+     */
+    private File solrDataDir;
+    
+    /**
+     * The component context. Only available when running within an OSGI 
+     * Environment and the component is active.
+     */
+    private ComponentContext componentContext;
+    /**
+     * For some functionality within this component it is important to track
+     * if this instance operates within or outside of an OSGI environment.
+     * because of this this boolean is set to true as soon as the first time
+     * {@link #activate(ComponentContext)} or {@link #deactivate(ComponentContext)}
+     * is called. If someone knows a better method to check that feel free to
+     * change!
+     */
+    private boolean withinOSGI = false;
+    
+    /* (non-Javadoc)
+     * @see org.apache.stanbol.entityhub.yard.solr.impl.ManagedSolrDirectory#isSolrDir(java.lang.String)
+     */
+    public final boolean isManagedIndex(String solrIndexName) throws IllegalStateException {
+        if(solrIndexName == null){
+            throw new IllegalArgumentException("The parsed name of the Solr index MUST NOT be NULL");
+        }
+        if(solrIndexName.isEmpty()){
+            throw new IllegalArgumentException("The parsed name of the Solr index MUST NOT be empty");
+        }
+        //also here we need to initialise the SolrDirectory if not already done
+        return new File(initSolrDirectory(null),solrIndexName).exists();
+    }
+    /* (non-Javadoc)
+     * @see org.apache.stanbol.entityhub.yard.solr.impl.ManagedSolrDirectory#getManagedIndices()
+     */
+    public final Map<String,File> getManagedIndices() throws IllegalStateException {
+        File solrDir = initSolrDirectory(null);
+        String[] indexNames = solrDir.list(DirectoryFileFilter.INSTANCE);
+        Map<String,File> indexes = new HashMap<String,File>();
+        for(String indexName:indexNames){
+            //TODO: validate that this is actually a SolrCore!
+            indexes.put(indexName, new File(solrDir,indexName));
+        }
+        return indexes;
+    }
+    /* (non-Javadoc)
+     * @see org.apache.stanbol.entityhub.yard.solr.impl.ManagedSolrDirectory#getSolrDirectory(java.lang.String)
+     */
+    public final File getSolrDirectory(final String solrIndexName) throws IllegalArgumentException {
+        if(solrIndexName == null){
+            throw new IllegalArgumentException("The parsed name of the Solr index MUST NOT be NULL");
+        }
+        if(solrIndexName.isEmpty()){
+            throw new IllegalArgumentException("The parsed name of the Solr index MUST NOT be empty");
+        }
+        return initSolrDirectory(solrIndexName);
+    }
+    /**
+     * Internally used to get/init the Solr directory of a SolrCore or the root
+     * Solr directory (if <code>null</code> is parsed)
+     * @param solrIndexName the name of the Core or <code>null</code> to get/init
+     * the root solr directory
+     * @return the Solr directory or <code>null</code> in case this component is
+     * deactivated
+     * @throws IllegalStateException in case this method is called when this
+     * component is running within an OSGI environment and it is deactivated or
+     * the initialisation for the parsed index failed.
+     */
+    private final File initSolrDirectory(final String solrIndexName) throws IllegalStateException {
+        File managedCoreContainerDirectory = lookupManagedSolrDir();
+        ComponentContext context = componentContext;
+        if(!managedCoreContainerDirectory.exists()){
+            try {
+                if(context != null){ //load via bundle
+                    managedCoreContainerDirectory = ConfigUtils.copyDefaultConfig(
+                        context.getBundleContext().getBundle(),managedCoreContainerDirectory, false);
+                } else { //load from jar
+                    managedCoreContainerDirectory = ConfigUtils.copyDefaultConfig(
+                        (Class<?>)null, managedCoreContainerDirectory, false);
+                }
+            } catch (IOException e) {
+                throw new IllegalStateException(
+                    String.format("Unable to copy default configuration for the manages Solr Directory to the configured path %s!"
+                        , managedCoreContainerDirectory.getAbsoluteFile()),e);
+            }
+        }
+        if(solrIndexName == null){
+            return managedCoreContainerDirectory;
+        }
+        File coreDir = new File(managedCoreContainerDirectory,solrIndexName);
+        if(!coreDir.exists()){
+            try {
+                if(context != null){ //load via bundle
+                    ConfigUtils.copyCore(context.getBundleContext().getBundle(),
+                        coreDir, null, false);
+                } else { //load from jar
+                    ConfigUtils.copyCore((Class<?>)null, coreDir, null, false);
+                }
+            } catch (Exception e) {
+                throw new IllegalStateException(
+                    String.format("Unable to copy default configuration for Solr Index %s to the configured path %s"
+                        ,solrIndexName==null?"":solrIndexName,managedCoreContainerDirectory.getAbsoluteFile()),e);
+            }
+        }
+        return coreDir;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.stanbol.entityhub.yard.solr.impl.ManagedSolrDirectory#getManagedSolrDir()
+     */
+    public File getManagedDirectory() {
+        // call initSolrDirectory(null) to initialise the internally managed
+        // Solr directory in case it is not already initialised.
+        return initSolrDirectory(null);
+    }
+    /**
+     * Lookup the location of the managed Solr directory
+     * @return the directory based on the current configuration
+     * @throws IllegalStateException in case this method is called when this
+     * component is running within an OSGI environment and it is deactivated.
+     */
+    private File lookupManagedSolrDir() throws IllegalStateException {
+        //local copy to avoid NullPointerExceptions when deactivate is called
+        //during this method
+        ComponentContext context = componentContext;
+        if(solrDataDir == null){
+            String configuredDataDir;
+            if(context == null){ //load via system properties
+                configuredDataDir = System.getProperty(MANAGED_SOLR_DIR_PROPERTY,DEFAULT_SOLR_DATA_DIR);
+            } else { //load via OSGI config
+                Object value = context.getProperties().get(MANAGED_SOLR_DIR_PROPERTY);
+                if(value != null){
+                    configuredDataDir = value.toString();
+                } else {
+                    configuredDataDir = DEFAULT_SOLR_DATA_DIR;
+                }
+            }
+            //property substitution
+            configuredDataDir = substituteProperty(configuredDataDir);
+            //determine the directory holding the SolrIndex
+            /*
+             * NOTE:
+             * In case the configuredDataDir.isAbsolute()==false this code will
+             * initialise the index relative to the "user.dir" of the application.
+             */
+            if(withinOSGI && context == null){
+                //ensure to do not set an solrDataDir if this component is
+                //running within an  OSGI environment and is deactivated
+                throw new IllegalStateException("Unable to lookup managed Solr directories when component is deactivated!");
+            } else { //set the the absolute path
+                solrDataDir = new File(configuredDataDir);
+            }
+        }
+        return solrDataDir;
+    }
+
+    /**
+     * Substitutes ${property.name} with the values retrieved via
+     * {@link System#getProperty(String, String)}. An empty string is used as
+     * default<p>
+     * If someone knows a default implementation feel free to replace!
+     * @param value the value to substitute
+     * @return the substituted value
+     */
+    private static String substituteProperty(String value) {
+        int prevAt = 0;
+        int foundAt = 0;
+        StringBuilder substitution = new StringBuilder();
+        while((foundAt = value.indexOf("${",prevAt))>=prevAt){
+            substitution.append(value.substring(prevAt, foundAt));
+            String propertyName = value.substring(
+                foundAt+2,value.indexOf('}',foundAt));
+            substitution.append(System.getProperty(propertyName, ""));
+            prevAt = foundAt+propertyName.length()+3;
+        }
+        substitution.append(value.substring(prevAt, value.length()));
+        return substitution.toString();
+    }
+    @Activate
+    protected void activate(ComponentContext context) {
+        this.componentContext = context;
+        this.withinOSGI = true;
+    }
+    @Deactivate
+    protected void deactivate(ComponentContext context) {
+        this.componentContext = null;
+    }
+}

Propchange: incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/DefaultSolrDirectoryManager.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/DefaultSolrServerProvider.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/DefaultSolrServerProvider.java?rev=1085255&r1=1085254&r2=1085255&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/DefaultSolrServerProvider.java (original)
+++ incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/DefaultSolrServerProvider.java Fri Mar 25 05:12:03 2011
@@ -30,7 +30,7 @@ import org.apache.solr.client.solrj.Solr
 import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer;
 import org.apache.solr.client.solrj.impl.LBHttpSolrServer;
 import org.apache.solr.client.solrj.impl.StreamingUpdateSolrServer;
-import org.apache.stanbol.entityhub.yard.solr.provider.SolrServerProvider;
+import org.apache.stanbol.entityhub.yard.solr.SolrServerProvider;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 /**

Copied: incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/EmbeddedSolrPorovider.java (from r1082932, incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/embedded/EmbeddedSolrPorovider.java)
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/EmbeddedSolrPorovider.java?p2=incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/EmbeddedSolrPorovider.java&p1=incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/embedded/EmbeddedSolrPorovider.java&r1=1082932&r2=1085255&rev=1085255&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/embedded/EmbeddedSolrPorovider.java (original)
+++ incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/EmbeddedSolrPorovider.java Fri Mar 25 05:12:03 2011
@@ -14,13 +14,10 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.stanbol.entityhub.yard.solr.embedded;
+package org.apache.stanbol.entityhub.yard.solr.impl;
 
 import java.io.File;
-import java.io.FilenameFilter;
 import java.io.IOException;
-import java.net.URI;
-import java.net.URISyntaxException;
 import java.util.Collections;
 import java.util.Map;
 import java.util.Set;
@@ -28,21 +25,19 @@ import java.util.Set;
 import javax.xml.parsers.ParserConfigurationException;
 
 import org.apache.commons.collections.map.ReferenceMap;
+import org.apache.commons.io.filefilter.NameFileFilter;
 import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Deactivate;
-import org.apache.felix.scr.annotations.Property;
 import org.apache.felix.scr.annotations.Service;
 import org.apache.solr.client.solrj.SolrServer;
 import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
-import org.apache.solr.common.ResourceLoader;
 import org.apache.solr.core.CoreContainer;
 import org.apache.solr.core.CoreDescriptor;
 import org.apache.solr.core.SolrCore;
-import org.apache.stanbol.entityhub.yard.solr.provider.SolrServerProvider;
-import org.apache.stanbol.entityhub.yard.solr.provider.SolrServerProvider.Type;
+import org.apache.stanbol.entityhub.yard.solr.SolrServerProvider;
+import org.apache.stanbol.entityhub.yard.solr.SolrServerProvider.Type;
 import org.apache.stanbol.entityhub.yard.solr.utils.ConfigUtils;
-import org.osgi.framework.BundleContext;
 import org.osgi.service.component.ComponentContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -51,32 +46,13 @@ import org.xml.sax.SAXException;
  * Support for the use of {@link EmbeddedSolrPorovider} in combination with the
  * SolrYard implementation. This implements the {@link SolrServerProvider}
  * interface for the {@link Type#EMBEDDED}.<p>
- * This implementation manages an internally managed instance of an 
- * {@link EmbeddedSolrServer} that is used to create/lookup cores if a
- * relative path is parsed as second parameter to 
- * {@link #getSolrServer(Type, String, String...)}. In case such a relative path
- * refers to a core that does not already exist this provider will create and
- * initialise a new one. It is also possible for other components to copy the
- * required files to the according directory and than use this provider to 
- * initialise the core. The {@link ConfigUtils} class provides some utilities
- * for that.<p>
- * The {@link #SOLR_DATA_DIR_PROPERTY} property can be used to define the location
- * of the internally managed index. By default it is within the 
- * {@link #DEFAULT_SOLR_DATA_DIR} directory located within the working-directory
- * (if running outside an OSGI environment) or within the data directory of the
- * SolrYard bundle (when running within an OSGI environment).<p>
- * Note that property substitution is supported for the 
- * {@link #SOLR_DATA_DIR_PROPERTY} property by using {@link System#getProperty(String, String)}
- * to search for values (empty string is used as default)<p>
- * Parsing the value "${data.dir}/indexes" will lookup the value of the system
- * property "data.dir" and the index will be located at "{property-value}/indexes".
  * 
  * TODO: add functionality to lookup the internally managed {@link CoreContainer}.
  * Maybe this requires to add a second service
  * @author Rupert Westenthaler
  *
  */
-@Component(immediate=true,metatype=true)
+@Component(immediate=true,metatype=false)
 @Service
 public class EmbeddedSolrPorovider implements SolrServerProvider {
     private final Logger log = LoggerFactory.getLogger(EmbeddedSolrPorovider.class);
@@ -91,48 +67,7 @@ public class EmbeddedSolrPorovider imple
      */
     @SuppressWarnings("unchecked")
     private Map<String, CoreContainer> coreContainers = new ReferenceMap(); 
-    
-    /**
-     * This property can be used to configure the location of the internally
-     * managed EmbeddedSolrServer.<p>
-     * Configuring an absolute path (starting with {@link File#separatorChar}) 
-     * will cause the index to be initialised in this directory.<p>
-     * Configuring an relative value will use  <ul>
-     * <li> the working directory (<code>Systen.getProperty("user.dir")</code>)
-     *      outside of an OSGI environment
-     * <li> the data directory provided by the SolrYard bundle (by calling
-     *      {@link BundleContext#getDataFile(String)} with the relative path.
-     * </ul>
-     * In case this property is not present the {@link #DEFAULT_SOLR_DATA_DIR}
-     * (an relative path) is used.
-     */
-    @Property(value=EmbeddedSolrPorovider.DEFAULT_SOLR_DATA_DIR)
-    public static final String SOLR_DATA_DIR_PROPERTY = "org.apache.stanbol.entityhub.yard.solr.embedded.solrDataDir";
-    /**
-     * default value for the relative path used if the {@link #SOLR_DATA_DIR_PROPERTY}
-     * is not present
-     */
-    public static final String DEFAULT_SOLR_DATA_DIR = "indexes";
-    
-    /**
-     * The directory used by the internally managed embedded solr server.
-     */
-    private File solrDataDir;
-    
-    /**
-     * The component context. Only available when running within an OSGI 
-     * Environment and the component is active.
-     */
-    private ComponentContext componentContext;
-    /**
-     * For some functionality within this component it is important to track
-     * if this instance operates within or outside of an OSGI environment.
-     * because of this this boolean is set to true as soon as the first time
-     * {@link #activate(ComponentContext)} or {@link #deactivate(ComponentContext)}
-     * is called. If someone knows a better method to check that feel free to
-     * change!
-     */
-    private boolean withinOSGI = false;
+        
     
     public EmbeddedSolrPorovider() {
     }
@@ -145,29 +80,9 @@ public class EmbeddedSolrPorovider imple
         }
         log.info("parsed solr server location "+uriOrPath);
         //first try as file (but keep in mind it could also be an URI)
-        File index = new File(uriOrPath);
-        //if it is absolute and it exists -> take it
-        if(!index.isAbsolute() || !index.exists()){
-            //otherwise test if it is an URI
-            try {
-                URI fileUri = new URI(uriOrPath);
-                index = new File(fileUri);
-            } catch (URISyntaxException e) {
-                //not an URI -> ignore
-            } catch (IllegalArgumentException e){
-                //this happens if it is a URI but can not be converted to a file
-                //still we should try to work with the parsed file ...
-            }
-            //ok now we have the file path ... do some evaluation
-            if(!index.isAbsolute()){ //if it is not absolute
-                //use the internally managed EmbeddedSolrServer
-                index = initManagedCoreDirectory(uriOrPath);
-                if(index == null){ 
-                    throw new IllegalArgumentException(String.format("The parsed Index Path %s does not exist and con not be initialised ",uriOrPath));
-                }
-            } else if(!index.exists()){ //if it is absolute -> check that it exist
-                throw new IllegalArgumentException(String.format("The parsed Index Path %s does not exist",uriOrPath));
-            }
+        File index = ConfigUtils.toFile(uriOrPath);
+        if(!index.exists()){
+            throw new IllegalArgumentException(String.format("The parsed Index Path %s does not exist",uriOrPath));
         }
         log.info("get solr server for location "+index);
         File coreDir = null;
@@ -197,14 +112,6 @@ public class EmbeddedSolrPorovider imple
             if(!coreName.isEmpty() && !coreContainer.getCoreNames().contains(coreName)){
                 //register this core first
                 /*
-                 * NOTE: This assumes that the data for the core are already copied
-                 * to the required location, but the core itself is not yet registered
-                 * in the SOLR_XML_NAME.
-                 * This uses the java API to register the core. Changes are saved
-                 * within the SOLR_XML_NAME if persistent="true" is present within the
-                 * solr element.
-                 */
-                /*
                  * NOTE:
                  * We need to reset the ContextClassLoader to the one used for this
                  * Bundle, because Solr uses this ClassLoader to load all the
@@ -237,170 +144,6 @@ public class EmbeddedSolrPorovider imple
             throw new IllegalArgumentException(String.format("The parsed Index Path %s is no Directory",uriOrPath));
         }
     }
-    /**
-     * The {@link CoreContainer} managed internally for the SolrYard. This is
-     * used whenever a {@link #getSolrServer(Type, String, String...)} parses
-     * an relative path as second parameter.<p>
-     * Within an OSGI Environment this CoreContainer is started/stopped
-     * within the activate/deactivate methods. With the exception if the
-     * {@link #solrDataDir} does not exist, because this means that this internally
-     * managed CoreContainer is not yet used. A lazy initialisation will be
-     * performed when required.<p>
-     * This Method does not perform any initialisation!
-     * @return the managed CoreContainer or <code>null</code> if it is not yet
-     * initialised or if the component is deactivated.
-     */
-    public CoreContainer getManagedCoreContainer(){
-        File managedCoreContainerDir = getManagedSolrDataDir();
-        if(managedCoreContainerDir != null){
-            return coreContainers.get(managedCoreContainerDir.getAbsolutePath());
-        } else {
-            return null;
-        }
-    }
-    /**
-     * This will invalidate all EmbeddedSolrServers created by using this
-     * CoreContainer or any of the Cores associated with this one
-     * ({@link CoreContainer#getCores()})
-     * @return <code>true</code> if the managed core was shutdown <code>false</code>
-     * if the managed core was not active and therefore no change was performed
-     */
-    private boolean shutdownManagedCoreContainer(){
-        File managedCoreContainerDir = getManagedSolrDataDir();
-        if(managedCoreContainerDir != null){
-            CoreContainer managedCoreContainer = coreContainers.remove(managedCoreContainerDir);
-            if(managedCoreContainer != null){
-                managedCoreContainer.shutdown();
-                return true;
-            }
-        }
-        return false;
-    }
-    /**
-     * Getter for the defaultCore
-     * @param coreName the name of the core or <code>null</code> to get/init the
-     * default directory of the default CoreContainer.<p>
-     * Works only within an OSGI Environment
-     * @return the directory (instanceDir) of the core or the solr server (if
-     * <code>null</code> is parsed as coreName). <code>null</code> is returned
-     * if the initialisation was not successful.
-     */
-    protected final File initManagedCoreDirectory(final String coreName){
-        File managedCoreContainerDirectory = getManagedSolrDataDir();
-        if(managedCoreContainerDirectory == null){
-            return null;
-        }
-        ComponentContext context = componentContext;
-        if(!managedCoreContainerDirectory.exists()){
-            try {
-                if(context != null){ //load via bundle
-                    managedCoreContainerDirectory = ConfigUtils.copyDefaultConfig(
-                        context.getBundleContext().getBundle(),managedCoreContainerDirectory, false);
-                } else { //load from jar
-                    managedCoreContainerDirectory = ConfigUtils.copyDefaultConfig(
-                        (Class<?>)null, managedCoreContainerDirectory, false);
-                }
-            } catch (Exception e) {
-                log.warn("Unable to initialise the default EmbeddedSolrServer!",e);
-                return null;
-            }
-        }
-        if(coreName == null){
-            return managedCoreContainerDirectory;
-        }
-        File coreDir = new File(managedCoreContainerDirectory,coreName);
-        if(!coreDir.exists()){
-            try {
-                if(context != null){ //load via bundle
-                    ConfigUtils.copyCore(context.getBundleContext().getBundle(),
-                        coreDir, null, false);
-                } else { //load from jar
-                    ConfigUtils.copyCore((Class<?>)null, coreDir, null, false);
-                }
-            } catch (Exception e) {
-                log.warn("Unable to initialise the core "+coreName+" with the default Core configuration!",e);
-                return null;
-            }
-        }
-        return coreDir;
-    }
-
-    /**
-     * Internally used during initialisation to get the location of the directory
-     * used for the data of the internally managed {@link CoreContainer}.<p>
-     * This method checks the configuration based on of this EmbeddesSolrServerProvider
-     * operates within or outside of an OSGI environment. It is not intended for
-     * @return the directory of the Solr Home used for the internally managed
-     * {@link CoreContainer} or <code>null</code> if running within an OSGI
-     * Environment and this component is deactivated.
-     */
-    private File getManagedSolrDataDir() {
-        //local copy to avoid NullPointerExceptions when deactivate is called
-        //during this method
-        ComponentContext context = componentContext;
-        if(solrDataDir == null){
-            String configuredDataDir;
-            if(context == null){
-                configuredDataDir = System.getProperty(SOLR_DATA_DIR_PROPERTY,DEFAULT_SOLR_DATA_DIR);
-            } else {
-                Object value = context.getProperties().get(SOLR_DATA_DIR_PROPERTY);
-                if(value != null){
-                    configuredDataDir = value.toString();
-                } else {
-                    configuredDataDir = DEFAULT_SOLR_DATA_DIR;
-                }
-            }
-            //property substitution
-            configuredDataDir = substituteProperty(configuredDataDir);
-            //determine the directory holding the SolrIndex
-            if(!configuredDataDir.isEmpty() && configuredDataDir.charAt(0) == File.separatorChar){
-                //absolute path (same within/outside OSGI environment)
-                if(withinOSGI && context == null){
-                    //however set to  null if within OSGI environment and
-                    //deactivated
-                    solrDataDir = null;
-                } else { //set the the absolute path
-                    solrDataDir = new File(configuredDataDir);
-                }
-            } else { //relative path
-                if(!withinOSGI){ //not within OSGI Environment
-                    String workingDir = System.getProperty("user.dir");
-                    solrDataDir = new File(workingDir,configuredDataDir);
-                } else if(context != null){ //within OSGI && activated
-                    solrDataDir = context.getBundleContext().getDataFile(configuredDataDir);
-                } else { //within OSGI && deactivated
-                    solrDataDir = null;
-                }
-            }
-        }
-        return solrDataDir;
-    }
-
-    /**
-     * Substitutes ${property.name} with the values retrieved via
-     * {@link System#getProperty(String, String)}. An empty string is used as
-     * default<p>
-     * If someone knows a default implementation feel free to replace!
-     * @param value the value to substitute
-     * @return the substituted value
-     */
-    private static String substituteProperty(String value) {
-        int prevAt = 0;
-        int foundAt = 0;
-        StringBuilder substitution = new StringBuilder();
-        while((foundAt = value.indexOf("${",prevAt))>=prevAt){
-            substitution.append(value.substring(prevAt, foundAt));
-            String propertyName = value.substring(
-                foundAt+2,value.indexOf('}',foundAt));
-            substitution.append(System.getProperty(propertyName, ""));
-            prevAt = foundAt+propertyName.length()+3;
-        }
-        substitution.append(value.substring(prevAt, value.length()));
-        return substitution.toString();
-    }
-    public static void main(String[] args) {
-        System.out.println(substituteProperty("this ${user.dir} is ${not.existant} of version ${java.version}"));
-    }
     
     protected final CoreContainer getCoreContainer(File solrDir) throws IllegalArgumentException, IllegalStateException {
         return getCoreContainer(solrDir.getAbsolutePath(), new File(solrDir,SOLR_XML_NAME));
@@ -441,46 +184,43 @@ public class EmbeddedSolrPorovider imple
     }
     @Activate
     protected void activate(ComponentContext context) {
-        this.withinOSGI = true;
-        this.componentContext = context;
-        File managedCoreContainerDir = getManagedSolrDataDir();
-        if(managedCoreContainerDir != null){
-            if(managedCoreContainerDir.exists()) {
-                //this indicated, that the core was alredy used ... so start it
-                getCoreContainer(managedCoreContainerDir);
-            } //else -> the internally managed core was not yet used ->
-            // use lazy initialisation on first usage (no need to load all the
-            //solr stuff in environments that do not use an EmbeddedSolrServer
-        } else {
-            //that should never happen ... 
-            throw new IllegalStateException("Unable to get Directory for the internally managed Solr Server");
-        }
+        log.debug("activating"+EmbeddedSolrPorovider.class.getSimpleName());
+        //currently not used
+
     }
     @Deactivate
     protected void deactivate(ComponentContext context) {
-        this.withinOSGI = true;
-        shutdownManagedCoreContainer();
-        solrDataDir = null;
-        this.componentContext = null;
-        //should we remove the coreContainers -> currently I don't because
-        // (1) activate deactivate do not have any affect
-        // (2) it are soft references anyway.
+        log.debug("deactivating"+EmbeddedSolrPorovider.class.getSimpleName());
+        //currently not used
     }
+//Keeping for now because this might be useful when checking for required files
+//    /**
+//     * Checks if the parsed directory contains a file that starts with the parsed
+//     * name. Parsing "hallo" will find "hallo.all", "hallo.ween" as well as "hallo".
+//     * @param dir the Directory. This assumes that the parsed File is not
+//     * <code>null</code>, exists and is an directory
+//     * @param name the name. If <code>null</code> any file is accepted, meaning
+//     * that this will return true if the directory contains any file 
+//     * @return the state
+//     */
+//    private boolean hasFile(File dir, String name){
+//        return dir.list(new NameFileFilter(name)).length>0;
+//    }
+//    /**
+//     * Returns the first file that matches the parsed name.
+//     * Parsing "hallo" will find "hallo.all", "hallo.ween" as well as "hallo".
+//     * @param dir the Directory. This assumes that the parsed File is not
+//     * <code>null</code>, exists and is an directory.
+//     * @param name the name. If <code>null</code> any file is accepted, meaning
+//     * that this will return true if the directory contains any file 
+//     * @return the first file matching the parsed prefix.
+//     */
+//    private File getFileByPrefix(File dir, String prefix){
+//        String[] files =  dir.list(new PrefixFileFilter(prefix));
+//        return files.length>0?new File(dir,files[0]):null;
+//    }
     /**
-     * Checks if the parsed directory contains a file that starts with the parsed
-     * name. Parsing "hallo" will find "hallo.all", "hallo.ween" as well as "hallo".
-     * @param dir the Directory. This assumes that the parsed File is not
-     * <code>null</code>, exists and is an directory
-     * @param name the name. If <code>null</code> any file is accepted, meaning
-     * that this will return true if the directory contains any file 
-     * @return the state
-     */
-    private boolean hasFile(File dir, String name){
-        return dir.listFiles(new SimpleFileNameFilter(name)).length>0;
-    }
-    /**
-     * Returns the first file that matches the parsed name.
-     * Parsing "hallo" will find "hallo.all", "hallo.ween" as well as "hallo".
+     * Returns the first file that matches the parsed name (case sensitive)
      * @param dir the Directory. This assumes that the parsed File is not
      * <code>null</code>, exists and is an directory.
      * @param name the name. If <code>null</code> any file is accepted, meaning
@@ -488,26 +228,7 @@ public class EmbeddedSolrPorovider imple
      * @return the first file matching the parsed name.
      */
     private File getFile(File dir, String name){
-        File[] files =  dir.listFiles(new SimpleFileNameFilter(name));
-        return files.length>0?files[0]:null;
-    }
-    /**
-     * Could not find a simple implementation of {@link FilenameFilter} that
-     * can be used if a file exists. If someone knows one, feel free to replace
-     * this one! 
-     * @author Rupert Westenthaler
-     *
-     */
-    private static class SimpleFileNameFilter implements FilenameFilter {
-
-        private String name;
-        public SimpleFileNameFilter(String name) {
-            this.name = name;
-        }
-        @Override
-        public boolean accept(File dir, String name) {
-            return this.name == null?true:name.startsWith(this.name);
-        }
-        
+        String[] files =  dir.list(new NameFileFilter(name));
+        return files.length>0?new File(dir,files[0]):null;
     }
 }

Propchange: incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/EmbeddedSolrPorovider.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrYard.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrYard.java?rev=1085255&r1=1085254&r2=1085255&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrYard.java (original)
+++ incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrYard.java Fri Mar 25 05:12:03 2011
@@ -16,6 +16,7 @@
  */
 package org.apache.stanbol.entityhub.yard.solr.impl;
 
+import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -25,6 +26,7 @@ import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.ServiceLoader;
 import java.util.Set;
 import java.util.Map.Entry;
 
@@ -57,15 +59,17 @@ import org.apache.stanbol.entityhub.serv
 import org.apache.stanbol.entityhub.servicesapi.query.QueryResultList;
 import org.apache.stanbol.entityhub.servicesapi.yard.Yard;
 import org.apache.stanbol.entityhub.servicesapi.yard.YardException;
+import org.apache.stanbol.entityhub.yard.solr.SolrDirectoryManager;
+import org.apache.stanbol.entityhub.yard.solr.SolrServerProviderManager;
+import org.apache.stanbol.entityhub.yard.solr.SolrServerProvider.Type;
 import org.apache.stanbol.entityhub.yard.solr.defaults.IndexDataTypeEnum;
 import org.apache.stanbol.entityhub.yard.solr.impl.SolrQueryFactory.SELECT;
 import org.apache.stanbol.entityhub.yard.solr.model.FieldMapper;
 import org.apache.stanbol.entityhub.yard.solr.model.IndexField;
 import org.apache.stanbol.entityhub.yard.solr.model.IndexValue;
 import org.apache.stanbol.entityhub.yard.solr.model.IndexValueFactory;
-import org.apache.stanbol.entityhub.yard.solr.provider.SolrServerProviderManager;
-import org.apache.stanbol.entityhub.yard.solr.provider.SolrServerProvider.Type;
 import org.apache.stanbol.entityhub.yard.solr.query.IndexConstraintTypeEnum;
+import org.apache.stanbol.entityhub.yard.solr.utils.ConfigUtils;
 import org.apache.stanbol.entityhub.yard.solr.utils.SolrUtil;
 import org.osgi.service.cm.ConfigurationException;
 import org.osgi.service.component.ComponentContext;
@@ -235,6 +239,9 @@ public class SolrYard extends AbstractYa
      */
     @Reference
     private SolrServerProviderManager solrServerProviderManager;
+    
+    @Reference
+    private SolrDirectoryManager solrDirectoryManager;
     /**
      * Default constructor as used by the OSGI environment.<p> DO NOT USE to
      * manually create instances! The SolrYard instances do need to be configured.
@@ -265,10 +272,10 @@ public class SolrYard extends AbstractYa
     @SuppressWarnings("unchecked")
     @Activate
     protected final void activate(ComponentContext context) throws ConfigurationException,IOException,SolrServerException {
-        log.info("in "+SolrYard.class+" activate with context "+context);
         if(context == null){
             throw new IllegalStateException("No valid"+ComponentContext.class+" parsed in activate!");
         }
+        log.info("in "+SolrYard.class+" activate with config "+context.getProperties());
         activate(new SolrYardConfig((Dictionary<String, Object>)context.getProperties()));
     }
     /**
@@ -287,9 +294,30 @@ public class SolrYard extends AbstractYa
         if(solrServerProviderManager == null){ //not within an OSGI environment
             solrServerProviderManager = SolrServerProviderManager.getInstance();
         }
+        if(solrDirectoryManager == null) { //not within an OSGI environment
+            //init via java.util.ServiceLoader
+            Iterator<SolrDirectoryManager> providerIt = 
+                ServiceLoader.load(SolrDirectoryManager.class,SolrDirectoryManager.class.getClassLoader()).iterator();
+            if(providerIt.hasNext()){
+                solrDirectoryManager = providerIt.next();
+            } else {
+                throw new IllegalStateException("Unable to instantiate "+SolrDirectoryManager.class.getSimpleName()+" service by using "+ServiceLoader.class.getName()+"!");
+            }
+        }
+        String solrIndexLocation;
+        if(config.getSolrServerType() == Type.EMBEDDED){
+            File indexDirectory = ConfigUtils.toFile(config.getSolrServerLocation());
+            if(!indexDirectory.isAbsolute()){ //relative paths
+                // need to be resolved based on the internally managed Solr directory
+                indexDirectory = solrDirectoryManager.getSolrDirectory(indexDirectory.toString());
+            }
+            solrIndexLocation = indexDirectory.toString();
+        } else {
+            solrIndexLocation = config.getSolrServerLocation();
+        }
         server = solrServerProviderManager.getSolrServer(
             config.getSolrServerType(), 
-            config.getSolrServerLocation().toString());
+            solrIndexLocation);
         //test the server
         SolrPingResponse pingResponse = server.ping();
         log.info(String.format("Successful ping for SolrServer %s ( %d ms) Details: %s",config.getSolrServerLocation(),pingResponse.getElapsedTime(),pingResponse));

Modified: incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrYardConfig.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrYardConfig.java?rev=1085255&r1=1085254&r2=1085255&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrYardConfig.java (original)
+++ incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrYardConfig.java Fri Mar 25 05:12:03 2011
@@ -21,7 +21,7 @@ import java.util.Map;
 
 import org.apache.solr.client.solrj.SolrServer;
 import org.apache.stanbol.entityhub.core.yard.AbstractYard.YardConfig;
-import org.apache.stanbol.entityhub.yard.solr.provider.SolrServerProvider.Type;
+import org.apache.stanbol.entityhub.yard.solr.SolrServerProvider.Type;
 import org.osgi.service.cm.ConfigurationException;
 
 

Modified: incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/utils/ConfigUtils.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/utils/ConfigUtils.java?rev=1085255&r1=1085254&r2=1085255&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/utils/ConfigUtils.java (original)
+++ incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/utils/ConfigUtils.java Fri Mar 25 05:12:03 2011
@@ -19,6 +19,8 @@ package org.apache.stanbol.entityhub.yar
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.net.URL;
 import java.util.Enumeration;
 import java.util.zip.ZipEntry;
@@ -27,7 +29,7 @@ import java.util.zip.ZipFile;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
 import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
-import org.apache.stanbol.entityhub.yard.solr.embedded.EmbeddedSolrPorovider;
+import org.apache.stanbol.entityhub.yard.solr.impl.EmbeddedSolrPorovider;
 import org.osgi.framework.Bundle;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -77,7 +79,7 @@ public final class ConfigUtils {
      * information to set up an configuration 
      */
     @SuppressWarnings("unchecked") //Enumeration<URL> required by OSGI specification
-    public static File copyDefaultConfig(Bundle bundle, File rootDir,boolean override) throws IOException, NullPointerException, IllegalStateException, IllegalArgumentException {
+    public static File copyDefaultConfig(Bundle bundle, File rootDir,boolean override) throws IOException, IllegalStateException, IllegalArgumentException {
         if(bundle == null){
             throw new IllegalArgumentException("The parsed Bundle MUST NOT be NULL!");
         }
@@ -88,7 +90,7 @@ public final class ConfigUtils {
             throw new IllegalStateException("The parsed root directory "+rootDir.getAbsolutePath()+" extists but is not a directory!");
         }
         log.info(String.format("Copy Default Config from Bundle %s to %s (override=%s)",
-            (bundle.getSymbolicName()+bundle.getVersion()),rootDir.getAbsolutePath(),override));
+            bundle.getSymbolicName(),rootDir.getAbsolutePath(),override));
         Enumeration<URL> resources = (Enumeration<URL>) bundle.findEntries(CONFIG_DIR, "*.*", true);
         //TODO: check validity of config and thorw IllegalArgumentException if not valid
         while(resources.hasMoreElements()){
@@ -116,7 +118,7 @@ public final class ConfigUtils {
      * rootDir or if the parsed bundle does not contain the required information 
      * to set up an configuration 
      */
-    public static File copyDefaultConfig(Class<?> clazzInArchive,File rootDir,boolean override) throws IOException, NullPointerException, IllegalStateException, IllegalArgumentException {
+    public static File copyDefaultConfig(Class<?> clazzInArchive,File rootDir,boolean override) throws IOException, IllegalStateException, IllegalArgumentException {
         if(rootDir == null){
             throw new IllegalArgumentException("The parsed root directory MUST NOT be NULL!");
         }
@@ -357,4 +359,26 @@ public final class ConfigUtils {
             }
         }
     }
+    /**
+     * Converts a parsed String to a File instance. The parsed string can be
+     * formatted as file URL or as path
+     * @param uriOrPath the file location as URL or path
+     * @return the File
+     */
+    public static File toFile(String uriOrPath){
+        File file = null;
+        try {
+            URI fileUri = new URI(uriOrPath);
+            file = new File(fileUri);
+        } catch (URISyntaxException e) {
+            //not an URI -> ignore
+        } catch (IllegalArgumentException e){
+            //this happens if it is a URI but can not be converted to a file
+            //still we should try to work with the parsed file ...
+        }
+        if(file == null){
+            file = new File(uriOrPath);
+        }
+        return file;
+    }
 }

Added: incubator/stanbol/trunk/entityhub/yard/solr/src/main/resources/META-INF/services/org.apache.stanbol.entityhub.yard.solr.SolrDirectoryManager
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/yard/solr/src/main/resources/META-INF/services/org.apache.stanbol.entityhub.yard.solr.SolrDirectoryManager?rev=1085255&view=auto
==============================================================================
--- incubator/stanbol/trunk/entityhub/yard/solr/src/main/resources/META-INF/services/org.apache.stanbol.entityhub.yard.solr.SolrDirectoryManager (added)
+++ incubator/stanbol/trunk/entityhub/yard/solr/src/main/resources/META-INF/services/org.apache.stanbol.entityhub.yard.solr.SolrDirectoryManager Fri Mar 25 05:12:03 2011
@@ -0,0 +1 @@
+org.apache.stanbol.entityhub.yard.solr.impl.DefaultSolrDirectoryManager
\ No newline at end of file

Copied: incubator/stanbol/trunk/entityhub/yard/solr/src/main/resources/META-INF/services/org.apache.stanbol.entityhub.yard.solr.SolrServerProvider (from r1082929, incubator/stanbol/trunk/entityhub/yard/solr/src/main/resources/META-INF/services/org.apache.stanbol.entityhub.yard.solr.provider.SolrServerProvider)
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/yard/solr/src/main/resources/META-INF/services/org.apache.stanbol.entityhub.yard.solr.SolrServerProvider?p2=incubator/stanbol/trunk/entityhub/yard/solr/src/main/resources/META-INF/services/org.apache.stanbol.entityhub.yard.solr.SolrServerProvider&p1=incubator/stanbol/trunk/entityhub/yard/solr/src/main/resources/META-INF/services/org.apache.stanbol.entityhub.yard.solr.provider.SolrServerProvider&r1=1082929&r2=1085255&rev=1085255&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/yard/solr/src/main/resources/META-INF/services/org.apache.stanbol.entityhub.yard.solr.provider.SolrServerProvider (original)
+++ incubator/stanbol/trunk/entityhub/yard/solr/src/main/resources/META-INF/services/org.apache.stanbol.entityhub.yard.solr.SolrServerProvider Fri Mar 25 05:12:03 2011
@@ -1,2 +1,2 @@
 org.apache.stanbol.entityhub.yard.solr.impl.DefaultSolrServerProvider
-org.apache.stanbol.entityhub.yard.solr.embedded.EmbeddedSolrPorovider
\ No newline at end of file
+org.apache.stanbol.entityhub.yard.solr.impl.EmbeddedSolrPorovider
\ No newline at end of file

Modified: incubator/stanbol/trunk/entityhub/yard/solr/src/main/resources/OSGI-INF/metatype/metatype.properties
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/yard/solr/src/main/resources/OSGI-INF/metatype/metatype.properties?rev=1085255&r1=1085254&r2=1085255&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/yard/solr/src/main/resources/OSGI-INF/metatype/metatype.properties (original)
+++ incubator/stanbol/trunk/entityhub/yard/solr/src/main/resources/OSGI-INF/metatype/metatype.properties Fri Mar 25 05:12:03 2011
@@ -36,8 +36,8 @@ org.apache.stanbol.entityhub.yard.solr.m
 
 
 #Properties defined by the org.apache.stanbol.entityhub.yard.solr.embedded.EmbeddedSolrPorovider
-org.apache.stanbol.entityhub.yard.solr.embedded.EmbeddedSolrPorovider.name=Apache Stanbol Embedded Solr Server Provider
-org.apache.stanbol.entityhub.yard.solr.embedded.EmbeddedSolrPorovider.description=This provider enables the use of an embedded SolrServer with the SolrYard implementation. In addition it manages an embedded Solr Server instance that is used to dynamically initialise Solr Indexes for SolrYard instances that do not refer to an external SolrServer.
+org.apache.stanbol.entityhub.yard.solr.impl.DefaultSolrDirectoryManager.name=Apache Stanbol Entityhub Yard: Solr Directory Manager
+org.apache.stanbol.entityhub.yard.solr.impl.DefaultSolrDirectoryManager.description=Manages the Solr Indices used by the SolrYard in cases where no absolute path or an http URL is configured as SolrServer location.  
 
-org.apache.stanbol.entityhub.yard.solr.embedded.solrDataDir.name=Index Location
-org.apache.stanbol.entityhub.yard.solr.embedded.solrDataDir.description=The path to the directory used to store the Solr Index of the internally managed EmbeddedSolrServer. Relative paths will use the data directory of the SolrYard bundle as root folder.
\ No newline at end of file
+org.apache.stanbol.entityhub.yard.solr.embedded.solrDataDir.name=Managed Index Location
+org.apache.stanbol.entityhub.yard.solr.embedded.solrDataDir.description=The path to the directory used to store the managed Solr Indices. The user directory is used to resolve relative paths. Property substitution is supported. (e.g. ${user.home}/.stanbol/indices will create the managed indices within the "/.stanbol/indices" relative to the home directory of the user). 
\ No newline at end of file

Added: incubator/stanbol/trunk/entityhub/yard/solr/src/test/java/org/apache/stanbol/entityhub/yard/solr/SolrDirectoryManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/yard/solr/src/test/java/org/apache/stanbol/entityhub/yard/solr/SolrDirectoryManagerTest.java?rev=1085255&view=auto
==============================================================================
--- incubator/stanbol/trunk/entityhub/yard/solr/src/test/java/org/apache/stanbol/entityhub/yard/solr/SolrDirectoryManagerTest.java (added)
+++ incubator/stanbol/trunk/entityhub/yard/solr/src/test/java/org/apache/stanbol/entityhub/yard/solr/SolrDirectoryManagerTest.java Fri Mar 25 05:12:03 2011
@@ -0,0 +1,112 @@
+/*
+ * 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.stanbol.entityhub.yard.solr;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertTrue;
+
+import java.io.File;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.ServiceLoader;
+import java.util.Set;
+import java.util.Map.Entry;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SolrDirectoryManagerTest {
+
+    private static final Logger log = LoggerFactory.getLogger(SolrDirectoryManagerTest.class);
+    
+    private static SolrDirectoryManager solrDirectoryManager;
+    
+    private static File expectedManagedDirectory;
+    private static Collection<String> expectedIndexNames = Arrays.asList("entityhub","cache");
+    
+    @BeforeClass
+    public static void init(){
+        //set to "${basedir}/some/rel/path" to test if property substitution works!
+        String solrServerDir = "${basedir}"+SolrYardTest.TEST_INDEX_REL_PATH;
+        log.info("configured directory: "+solrServerDir);
+        System.setProperty(SolrDirectoryManager.MANAGED_SOLR_DIR_PROPERTY, solrServerDir);
+        //store the expected managed directory for later testing
+        expectedManagedDirectory = new File(System.getProperty("basedir"),SolrYardTest.TEST_INDEX_REL_PATH);
+        log.info("expected managed directory: "+expectedManagedDirectory);
+        //create the SolrDirectoryManager used for the tests
+        Iterator<SolrDirectoryManager> providerIt = 
+            ServiceLoader.load(SolrDirectoryManager.class,SolrDirectoryManager.class.getClassLoader()).iterator();
+        if(providerIt.hasNext()){
+            solrDirectoryManager = providerIt.next();
+        } else {
+            throw new IllegalStateException("Unable to instantiate "+SolrDirectoryManager.class.getSimpleName()+" service by using "+ServiceLoader.class.getName()+"!");
+        }
+    }
+    
+    @Test
+    public void testManagedDirectoryInitialisation(){
+        //the managed directory must be set based on the 
+        expectedManagedDirectory.equals(
+            solrDirectoryManager.getManagedDirectory());
+    }
+    
+    @Test(expected=IllegalArgumentException.class)
+    public void testNullIndexName(){
+        solrDirectoryManager.getSolrDirectory(null);
+    }
+
+    @Test(expected=IllegalArgumentException.class)
+    public void testEmptyIndexName(){
+        solrDirectoryManager.getSolrDirectory("");
+    }
+
+    @Test
+    public void testGetManagedIndexes(){
+        Set<String> expected = new HashSet<String>(expectedIndexNames);
+        for(Entry<String,File> index : solrDirectoryManager.getManagedIndices().entrySet()){
+            expected.remove(index.getKey());
+            //test that the index dir is the expected location
+            File expectedLocation = new File(expectedManagedDirectory,index.getKey());
+            assertEquals(expectedLocation, index.getValue());
+        }
+        //test that the expected indexes where returned
+        assertTrue(expected.isEmpty());
+    }
+    
+    @Test
+    public void testIsManagedIndex(){
+        for(String name : expectedIndexNames){
+            assertTrue(solrDirectoryManager.isManagedIndex(name));
+        }
+        assertFalse(solrDirectoryManager.isManagedIndex("notAnIndex"+System.currentTimeMillis()));
+    }
+    
+    @Test
+    public void testIndexInitialisation(){
+        //this is actually tested already by the initialisation of the
+        //SolrYardTest ...
+        String indexName = "testIndexInitialisation_"+System.currentTimeMillis();
+        File indexDir = solrDirectoryManager.getSolrDirectory(indexName);
+        assertEquals(new File(expectedManagedDirectory,indexName), indexDir);
+        assertTrue(indexDir.isDirectory());
+    }
+}

Propchange: incubator/stanbol/trunk/entityhub/yard/solr/src/test/java/org/apache/stanbol/entityhub/yard/solr/SolrDirectoryManagerTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/stanbol/trunk/entityhub/yard/solr/src/test/java/org/apache/stanbol/entityhub/yard/solr/SolrYardTest.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/yard/solr/src/test/java/org/apache/stanbol/entityhub/yard/solr/SolrYardTest.java?rev=1085255&r1=1085254&r2=1085255&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/yard/solr/src/test/java/org/apache/stanbol/entityhub/yard/solr/SolrYardTest.java (original)
+++ incubator/stanbol/trunk/entityhub/yard/solr/src/test/java/org/apache/stanbol/entityhub/yard/solr/SolrYardTest.java Fri Mar 25 05:12:03 2011
@@ -21,7 +21,6 @@ import java.io.File;
 import org.apache.stanbol.entityhub.servicesapi.yard.Yard;
 import org.apache.stanbol.entityhub.servicesapi.yard.YardException;
 import org.apache.stanbol.entityhub.test.yard.YardTest;
-import org.apache.stanbol.entityhub.yard.solr.embedded.EmbeddedSolrPorovider;
 import org.apache.stanbol.entityhub.yard.solr.impl.SolrYard;
 import org.apache.stanbol.entityhub.yard.solr.impl.SolrYardConfig;
 import org.junit.AfterClass;
@@ -34,18 +33,23 @@ import org.slf4j.LoggerFactory;
  * This test uses the system property "basedir" to configure an embedded Solr
  * Server. This property is set by the mvn surefire plugin. When using this
  * Unit Test within a build environment that does not set this property one need
- * to set it manually to the base directory of this module.
+ * to set it manually to the base directory of this module.<p>
  * @author Rupert Westenthaler
  *
  */
 public class SolrYardTest extends YardTest {
-    
+    /**
+     * The SolrYard used for the tests
+     */
     private static Yard yard;
+    /**
+     * The SolrDirectoryManager also tested within this unit test
+     */
     public static final String TEST_YARD_ID = "testYard";
     public static final String TEST_SOLR_CORE_NAME = "test";
-    private static final String TEST_INDEX_REL_PATH = 
+    protected static final String TEST_INDEX_REL_PATH = 
         File.separatorChar + "target"+
-        File.separatorChar + EmbeddedSolrPorovider.DEFAULT_SOLR_DATA_DIR;
+        File.separatorChar + SolrDirectoryManager.DEFAULT_SOLR_DATA_DIR;
     private static final Logger log = LoggerFactory.getLogger(SolrYardTest.class);
     
     @BeforeClass
@@ -54,10 +58,11 @@ public class SolrYardTest extends YardTe
         //use property substitution to test this feature!
         String solrServerDir = "${basedir}"+TEST_INDEX_REL_PATH;
         log.info("Test Solr Server Directory: "+solrServerDir);
-        System.setProperty(EmbeddedSolrPorovider.SOLR_DATA_DIR_PROPERTY, solrServerDir);
+        System.setProperty(SolrDirectoryManager.MANAGED_SOLR_DIR_PROPERTY, solrServerDir);
         SolrYardConfig config = new SolrYardConfig(TEST_YARD_ID,TEST_SOLR_CORE_NAME);
         config.setName("Solr Yard Test");
         config.setDescription("The Solr Yard instance used to execute the Unit Tests defined for the Yard Interface");
+        //create the Yard used for the tests
         yard = new SolrYard(config);
     }