M
- the kind of resource producedpublic abstract class ResourceObjectProviderBase<M> extends Object implements HasResourceMetadata
A component using such a provider sets defaults and overrides. The defaults should be set to
sensible values with which the component should be able to work out of the box. For example the
LOCATION
may be set to "classpath:/resources/${language}/model.ser.gz".
The overrides should only be set if the user explicitly wants to override some settings.
Finally, parameters that may change, e.g. depending on the CAS content should be returned from
getProperties()
.
The LOCATION
may contain variables referring to any of the other settings, e.g.
"${language}"
.
It is possible a different default variant needs to be used depending on the language. This can
be configured by placing a properties file in the classpath and setting its location using
setDefaultVariantsLocation(String)
or by using setDefaultVariants(Properties)
.
The key in the properties is the language and the value is used a default variant.
Modifier and Type | Field and Description |
---|---|
static String |
ARTIFACT_ID
The artifact ID of the Maven artifact containing a resource.
|
static String |
CATCH_ALL |
static String |
FORCE_AUTO_LOAD |
static String |
GROUP_ID
The group ID of the Maven artifact containing a resource.
|
static String |
LANGUAGE
The language.
|
static String |
LOCATION
The location from which the resource should be read.
|
static String |
NOT_REQUIRED |
static String |
PACKAGE |
static String |
PROP_REPO_CACHE |
static String |
PROP_REPO_ID |
static String |
PROP_REPO_OFFLINE |
static String |
PROP_REPO_URL |
static String |
SHARABLE
If this property is set to
true , resources loaded through this provider are
remembered by the provider using a weak reference. |
static String |
VARIANT
The variant.
|
static String |
VERSION
The version of the Maven artifact containing a resource.
|
Constructor and Description |
---|
ResourceObjectProviderBase() |
Modifier and Type | Method and Description |
---|---|
void |
addAutoOverride(String aParameter,
String aProperty) |
void |
addImport(String aString,
HasResourceMetadata aSource) |
void |
applyAutoOverrides(Object aObject) |
void |
configure()
Configure a resource using the current configuration.
|
protected URL |
followRedirects(URL aUrl) |
protected Properties |
getAggregatedProperties()
Builds the aggregated configuration from defaults and overrides.
|
Map<String,String> |
getAutoOverrides() |
de.tudarmstadt.ukp.dkpro.core.api.resources.ResourceObjectProviderBase.ExtensibleURLClassLoader |
getClassLoader() |
Class<?> |
getContextClass() |
String |
getDefault(String aKey) |
protected String |
getLastModelLocation() |
protected String |
getModelLocation()
For use in test cases.
|
protected String |
getModelLocation(Properties aProperties) |
protected org.apache.ivy.plugins.resolver.DependencyResolver |
getModelResolver() |
protected String |
getModelVersionFromMavenPom()
Tries to get the version of the required model from the dependency management section of the
Maven POM belonging to the context object.
|
String |
getOverride(String aKey) |
protected abstract Properties |
getProperties() |
M |
getResource()
Get the currently configured resources.
|
Properties |
getResourceMetaData() |
protected void |
init() |
protected void |
loadMetadata() |
protected void |
loadResource(Properties aProperties) |
protected void |
mergeProperties(Properties aTarget,
Properties aSource)
Copy all properties that not already exist in target from source.
|
protected abstract M |
produceResource(URL aUrl) |
void |
removeDefault(String aKey) |
void |
removeImport(String aString) |
void |
removeOverride(String aKey) |
void |
setContextClass(Class<?> aClass)
Set a class which can be used to try finding a Maven POM from which resource version
information could be extracted.
|
void |
setContextObject(Object aObject)
Set an object which can be used to try finding a Maven POM from which resource version
information could be extracted.
|
void |
setDefault(String aKey,
String aValue) |
void |
setDefaultVariants(Properties aDefaultVariants)
Sets language-dependent default variants.
|
void |
setDefaultVariantsLocation(String aLocation)
Set the location in the classpath from where to load the language-dependent default variants
properties file.
|
void |
setOverride(String aKey,
String aValue) |
public static final String PROP_REPO_OFFLINE
public static final String PROP_REPO_ID
public static final String PROP_REPO_URL
public static final String PROP_REPO_CACHE
public static final String FORCE_AUTO_LOAD
public static final String NOT_REQUIRED
public static final String LANGUAGE
public static final String VARIANT
public static final String LOCATION
configure()
is called.public static final String GROUP_ID
configure()
is called. (optional)public static final String ARTIFACT_ID
configure()
is called. (optional)public static final String VERSION
configure()
is called. (optional)public static final String PACKAGE
public static final String SHARABLE
true
, resources loaded through this provider are
remembered by the provider using a weak reference. If the same resource is requested by
another instance of this provider class, the same resource is returned.public static final String CATCH_ALL
protected void init()
public void removeOverride(String aKey)
public void removeDefault(String aKey)
public void addImport(String aString, HasResourceMetadata aSource)
public void removeImport(String aString)
public void setDefaultVariantsLocation(String aLocation)
aLocation
- a location in the form "some/package/name/tool-default-variants.properties". This
is always a classpath location. This location may not contain variables.public void setDefaultVariants(Properties aDefaultVariants)
aDefaultVariants
- the default variant per languagepublic void setContextObject(Object aObject)
aObject
- a context object, usually the object creating the provider.public void setContextClass(Class<?> aClass)
aClass
- a context class, usually the class creating the provider.public Class<?> getContextClass()
public void applyAutoOverrides(Object aObject)
protected String getModelVersionFromMavenPom() throws IOException
IOException
- if there was a problem loading the POM fileFileNotFoundException
- if no POM could be foundIllegalStateException
- if more than one POM was found, if the version information could not be found in
the POM, or if no context object was set.protected String getModelLocation() throws IOException
IOException
- if the language-dependent default variants location is set but cannot be read.protected String getLastModelLocation()
protected String getModelLocation(Properties aProperties) throws IOException
IOException
public void configure() throws IOException
getResource()
.
Call this method after all configurations have been made. A already configured resource will only be recreated if the URL from which the resource is generated has changed due to configuration changes.
IOException
- if the resource cannot be created.protected URL followRedirects(URL aUrl) throws IOException
IOException
protected void loadMetadata() throws IOException
IOException
protected void loadResource(Properties aProperties) throws IOException
IOException
protected org.apache.ivy.plugins.resolver.DependencyResolver getModelResolver()
public M getResource()
configure()
needs
to be called once or whenever the configuration changes. Mind that sub-classes may provide
alternative configuration methods that may need to be used instead of configure()
.public de.tudarmstadt.ukp.dkpro.core.api.resources.ResourceObjectProviderBase.ExtensibleURLClassLoader getClassLoader()
protected Properties getAggregatedProperties() throws IOException
IOException
- if the language-dependent default variants location is set but cannot be read.protected abstract Properties getProperties()
protected abstract M produceResource(URL aUrl) throws IOException
IOException
public Properties getResourceMetaData()
getResourceMetaData
in interface HasResourceMetadata
protected void mergeProperties(Properties aTarget, Properties aSource)
aTarget
- the properties to merge into.aSource
- the properties to merge from.Copyright © 2007–2018 Ubiquitous Knowledge Processing (UKP) Lab, Technische Universität Darmstadt. All rights reserved.