Search in sources :

Example 1 with RDFBackend

use of org.apache.marmotta.ldpath.api.backend.RDFBackend in project stanbol by apache.

the class LdpathSourceProcessor method setConfiguration.

@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public void setConfiguration(Map<String, Object> config) {
    indexingConfig = (IndexingConfig) config.get(IndexingConfig.KEY_INDEXING_CONFIG);
    Object indexingSource;
    //we need to check for both EntityDataProvider and EntityDataIterator
    indexingSource = indexingConfig.getEntityDataProvider();
    if (indexingSource == null) {
        indexingSource = indexingConfig.getDataIterable();
    }
    if (indexingSource == null) {
        throw new IllegalStateException("Indexing Configuration does not contain" + "neither an EntityDataProvider nor an EntityIdIterator!");
    }
    if (indexingSource instanceof RDFBackend<?>) {
        //NOTE we use the EntityhubConfiguration to have the same pre-registered
        //     namespaces as the other components.
        this.backend = (RDFBackend) indexingSource;
        this.configuration = new EntityhubConfiguration(vf);
        this.transformer = configuration.getTransformers();
        this.ldPath = new LDPath(backend, configuration);
    } else {
        throw new IllegalArgumentException("The configured IndexingSource '" + indexingSource.getClass().getSimpleName() + "' does not support " + "LDPath (does not implement RDFBackend)! This Processor " + "can only be used with IndexingSources that support LDPath!");
    }
    Object value = config.get(PARAMETER_LD_PATH);
    final File ldpathFile;
    if (value != null && !value.toString().isEmpty()) {
        ldpathFile = indexingConfig.getConfigFile(value.toString());
        if (ldpathFile == null || !ldpathFile.exists()) {
            throw new IllegalArgumentException("Configured '" + PARAMETER_LD_PATH + "' file was not found!");
        }
        if (!ldpathFile.isFile()) {
            throw new IllegalArgumentException("Configured '" + PARAMETER_LD_PATH + "' file exists but is not a File!");
        }
    } else {
        throw new IllegalArgumentException("Missing required configuration '" + PARAMETER_LD_PATH + "' - the file containing the LDPath program used by this " + LdpathProcessor.class.getSimpleName() + "!");
    }
    //The backend needs not to be initialised to parse a program as
    //parsing only requires the "value converter" methods that need also to
    //work without initialising
    //if this is a Problem one can also move parsing to the init method
    parseLdPathProgram(ldpathFile);
    value = config.get(PARAMETER_APPEND);
    if (value instanceof Boolean) {
        this.appendMode = ((Boolean) value).booleanValue();
    } else if (value != null && !value.toString().isEmpty()) {
        this.appendMode = Boolean.parseBoolean(value.toString());
    } else {
        this.appendMode = DEFAULT_APPEND_MODE;
    }
}
Also used : EntityhubConfiguration(org.apache.stanbol.entityhub.ldpath.EntityhubLDPath.EntityhubConfiguration) LDPath(org.apache.marmotta.ldpath.LDPath) RDFBackend(org.apache.marmotta.ldpath.api.backend.RDFBackend) File(java.io.File)

Aggregations

File (java.io.File)1 LDPath (org.apache.marmotta.ldpath.LDPath)1 RDFBackend (org.apache.marmotta.ldpath.api.backend.RDFBackend)1 EntityhubConfiguration (org.apache.stanbol.entityhub.ldpath.EntityhubLDPath.EntityhubConfiguration)1