public class LocatorConverter extends Object implements org.apache.commons.beanutils.Converter
A specialized Converter
implementation dealing with Locator
objects.
This converter implementation is able to transform text representations of
locators into concrete Locator
instances. This is pretty convenient,
especially for bean declarations; here a compact text representation for
locators is much more readable than a verbose declaration of a factory method
invocation.
This converter supports most of the standard Locator
implementations
provided by this package. A text representation of a locator starts with a
prefix, followed by a colon. Then the specific data of the concrete
Locator
subclass is appended. The following table lists the supported
prefixes with their meaning and examples:
Prefix | Description | Example |
---|---|---|
classpath | Creates a ClassPathLocator instance. The data is interpreted as a
resource name which is looked up on the current class path. Optionally, a
class loader name can be provided separated by a semicolon. If this is used,
the corresponding class loader is obtained from the
ClassLoaderProvider ; otherwise, the default class loader is used. |
classpath:myresource.properties classpath:myresource.properties;myClassLoader |
file | Creates a FileLocator instance. The data is interpreted as a
relative or absolute file name. It is directly passed to the
FileLocator instance to be created. |
file:target/data.txt |
url | Creates a URLLocator instance. The data is interpreted as a URL
in text form. It is directly passed to the URLLocator instance to be
created. |
url:http://www.mydomain.com/image.jpg |
Prefixes are not case sensitive. If an unknown prefix is encountered, a
ConversionException
is thrown. An instance of this class is
registered as base class converter by the form builder per default. Using the
data type conversion mechanism provided by the dependency injection
framework, it is possible to add further converters for custom
Locator
implementations.
This class does not have any internal state. Thus an instance can be shared between multiple components and called concurrently.
Modifier and Type | Field and Description |
---|---|
static char |
PREFIX_SEPARATOR
Constant for the prefix separator.
|
Constructor and Description |
---|
LocatorConverter()
Creates a new instance of
LocatorConverter without a class loader
provider. |
LocatorConverter(ClassLoaderProvider clp)
Creates a new instance of
LocatorConverter and initializes it
with the given ClassLoaderProvider . |
Modifier and Type | Method and Description |
---|---|
Object |
convert(Class type,
Object value)
Tries to convert the specified object to a
Locator . |
ClassLoaderProvider |
getClassLoaderProvider()
Returns the
ClassLoaderProvider used by this converter. |
public static final char PREFIX_SEPARATOR
public LocatorConverter(ClassLoaderProvider clp)
LocatorConverter
and initializes it
with the given ClassLoaderProvider
. Class loaders for class path
locators are obtained from this provider.clp
- the ClassLoaderProvider
public LocatorConverter()
LocatorConverter
without a class loader
provider. A converter constructed this way cannot resolve any class
loader names. This constructor exists for reasons of backwards
compatibility. It is recommended to always provide a
ClassLoaderProvider
.public ClassLoaderProvider getClassLoaderProvider()
ClassLoaderProvider
used by this converter. This
object is used to determine class loaders when locators for class path
resources are to be created. Result may be null if no
ClassLoaderProvider
has been set.ClassLoaderProvider
public Object convert(Class type, Object value)
Locator
. The
conversion is based on prefixes as described in the class comment.convert
in interface org.apache.commons.beanutils.Converter
type
- the target classvalue
- the object to be converted (must not be null)Locator
interfaceorg.apache.commons.beanutils.ConversionException
- if conversion is not possibleCopyright © 2016 The JGUIraffe Team. All rights reserved.