|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object magoffin.matt.meta.MetadataResourceFactoryManager
public class MetadataResourceFactoryManager
A simple manager of MetadataResourceFactory
instances.
This class manages finding MetadataResourceFactory
implementations
for files based on a classpath Properties
resource. When
isDisableSearchPath()
is false (the default setting)
then this class will search in the following locations:
getManagerProperties()
If the isDisableSearchPath()
is true then
only the getManagerProperties()
path will be used. The
properties are searched until the first suitable key is found. The
properties resource is loaded via the same ClassLoader that loaded this class, i.e.
getClass().getClassLoader().getResource()
is used. The properties
file must have the format
smeta.factory.KEY = CLASS
where KEY
is either a file suffix or a MIME type, and
CLASS
is a fully-qualified class name for a class that
implements MetadataResourceFactory
. This class must provide a default
no-argument constructor. The class will be loaded in the same ClassLoader that
loaded this class, i.e. getClass().getClassLoader().loadClass()
is used.
Field Summary | |
---|---|
static java.lang.String |
CUSTOM_MANAGER_PROPERTIES
A custom class-path properties file. |
static java.lang.String |
DEFAULT_MANAGER_PROPERTIES
The default class-path properties file. |
static java.lang.String |
FACTORY_PROPERTY_KEY_PREFIX
The prefix used for MetadataResourceFactory configuration properties. |
Constructor Summary | |
---|---|
MetadataResourceFactoryManager()
|
Method Summary | |
---|---|
protected MetadataResourceFactory |
findFactory(java.io.File file,
java.lang.String key)
Find a MetadataResourceFactory for a given file and key. |
static MetadataResourceFactoryManager |
getDefaultManagerInstance()
Get the default MetadataResourceFactoryManager instance. |
java.lang.String |
getManagerProperties()
Get the resource path of the manager Properties resource. |
MetadataResourceFactory |
getMetadataResourceFactory(java.io.File file)
Get a MetadataResourceFactory instance for a particular file. |
MetadataResourceFactory |
getMetadataResourceFactory(java.lang.String mime)
Get a MetadataResourceFactory instance for a particular MIME type. |
boolean |
isDisableSearchPath()
Return the search path flag. |
void |
setDisableSearchPath(boolean disableSearchPath)
Set the search path flag. |
void |
setManagerProperties(java.lang.String managerProperties)
Set the resource path of the manager Properties resource. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String CUSTOM_MANAGER_PROPERTIES
public static final java.lang.String DEFAULT_MANAGER_PROPERTIES
public static final java.lang.String FACTORY_PROPERTY_KEY_PREFIX
MetadataResourceFactory
configuration properties.
Constructor Detail |
---|
public MetadataResourceFactoryManager()
Method Detail |
---|
public static MetadataResourceFactoryManager getDefaultManagerInstance()
MetadataResourceFactoryManager
instance.
public MetadataResourceFactory getMetadataResourceFactory(java.io.File file) throws MetadataConfigurationException
The file suffix (anything after the last period in the file name) is used as the key to lookup the factory implementation to use.
file
- the file
MetadataConfigurationException
- if unable to load configurationpublic MetadataResourceFactory getMetadataResourceFactory(java.lang.String mime) throws MetadataConfigurationException
The MIME type itself is used as the key to lookup the factory implementation to use.
mime
- the MIME type of the resource
MetadataConfigurationException
- if unable to load configurationprotected MetadataResourceFactory findFactory(java.io.File file, java.lang.String key) throws MetadataConfigurationException
MetadataResourceFactory
for a given file and key.
This method will use a search path of up to three locations in
the class path to look for a Properties
file with sMeta
configuration settings. The first configuration setting found will
be used. The three locations are:
getManagerProperties()
If the isDisableSearchPath()
returns true then
only the getManagerProperties()
path will be used.
The Properties resource will be queried for a key in the form of
smeta.factory.KEY
where KEY
is the value
of the key parameter passed to this method. The property
value must be the fully qualified class name of something that
implements MetadataResourceFactory
, which must provide a
no-argument constructor to be instantiated by this class.
Extending classes can override this method to provide more functionality.
file
- the File being queried (if available)key
- the key to look up, eg. a file extension or MIME type
MetadataConfigurationException
- if a configuration error occurspublic java.lang.String getManagerProperties()
public void setManagerProperties(java.lang.String managerProperties)
If configured, this will be the first properties resource to look
for while searching for MetadataResourceFactory
instances. If
isDisableSearchPath()
returns true then this will
be the only properties resource looked in.
managerProperties
- the managerProperties to setpublic boolean isDisableSearchPath()
If this returns true then this instance will not search for
MetadataResourceFactory
implementations as described in
findFactory(File, String)
. Rather it will use only the configured
properties resource set via setManagerProperties(String)
. This
property defaults to false, meaning searching will be enabled.
public void setDisableSearchPath(boolean disableSearchPath)
If set to true then this instance will not search for
MetadataResourceFactory
implementations as described in
findFactory(File, String)
. Rather it will use only the configured
properties resource set via setManagerProperties(String)
.
disableSearchPath
- the disableSearchPath to set
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |