public class CheckConfigurationFile extends Object
ConfigurationFile
. The source
is specified with either a file, URL, or standard input, as well as with
override options. The checks include syntax and static type checking, and
require access to any application types mentioned in the source. The following items are discussed below:
Properties
source file, where each key is the fully qualified name
of an entry (component.name
) and each value
specifies the expected type for that entry. Types should be specified in
normal source code format, except that whitespace is not permitted between
tokens. Types in the java.lang
package may be unqualified, but
fully qualified names must be used for other types (import
statements are not supported). If any entry description files are supplied,
then any public entry that appears in the source being checked, whose fully
qualified name does not appear in any entry description file, or whose
actual type is not assignable to the expected type, is treated as an
error.
Entry description files for all of the River-Internet release services and utilities
are provided in the configentry
subdirectory beneath the
top-level directory of the River-Internet release installation.
Here is a sample entry description file:
Here is an associated sample configuration file:comp.foo Integer[] comp.bar net.jini.core.constraint.MethodConstraints comp.baz long
import net.jini.constraint.*; import net.jini.core.constraint.*; comp { foo = new Integer[] { Integer.valueOf(3) }; bar = new BasicMethodConstraints( new InvocationConstraints(Integrity.YES, null)); baz = 33L; }
check(String, ClassLoader, String[], String,
PrintStream)
or check(ConfigurationFile, Properties, ClassLoader,
PrintStream)
methods. An example command line usage is:
where install_dir is the directory where the River-Internet release is installed, and your-norm.config is a configuration source file intended for use with the transient Norm service implementation. This command will print out any problems that it detects in the configuration file, including entries that are not recognized or have the wrong type for the Norm service.java -jar install_dir/lib/checkconfigurationfile.jar \ -cp install_dir/lib/norm.jar:install_dir/lib/jsk-platform.jar \ -entries install_dir/configentry/norm-transient \ your-norm.config
ConfigurationFile
Modifier and Type | Method and Description |
---|---|
static boolean |
check(ConfigurationFile config,
Properties entries,
ClassLoader loader,
PrintStream err)
Checks the format of a
ConfigurationFile . |
static boolean |
check(String classPath,
ClassLoader loader,
String[] configOptions,
String entriesPath,
PrintStream err)
Checks the format of a configuration source file.
|
static void |
main(String[] args)
Command line interface for checking the format of source and override
options for a
ConfigurationFile , printing messages to
System.err for any errors found. |
public static void main(String[] args)
ConfigurationFile
, printing messages to
System.err
for any errors found. If errors are found,
continues to check the rest of the source and overrides, and then calls
System.exit
with a non-zero
argument. The command line arguments are:
[ -cp classpath ] [ -entries entrydescs ] location [ option... ]or
[ -cp classpath ] [ -entries entrydescs ] -stdin [ location [ option... ] ]or
-helpIf the only argument is
-help
, a usage message is
printed.
The classpath value for the -cp
option
specifies one or more directories and zip/JAR files, separated by the
path separator character, where the
application classes are located. A class loader that loads classes from
this path will be created, with the extension class loader as its
parent. If this option is not specified, the system class loader is used
instead.
The entrydescs value for the -entries
option specifies one or more entry description files, separated by the
path separator character.
The location argument specifies the source file to be
checked. If the -stdin
option is used, then the actual
source data will be read from standard input, and any
location argument is simply used for identification
purposes in error messages.
The remaining arguments specify any entry override values that should be
passed to the ConfigurationFile
constructor.
The class loader obtained above is used to resolve all expected types
specified in the entry description files, and to obtain the
configuration provider. The configuration provider class is found from
the class loader in the same manner as specified by ConfigurationProvider
. The resulting class must be ConfigurationFile
or a subclass; if it is a subclass, it must have a
public constructor with three parameters of type: Reader
,
String[]
, and ClassLoader
. An instance of the
provider is created by passing that constructor a Reader
for the source file to be checked, the location and entry override
values, and the class loader.
args
- array of string arguments.public static boolean check(String classPath, ClassLoader loader, String[] configOptions, String entriesPath, PrintStream err)
true
if there are no errors, and false
otherwise.
The classPath
argument specifies one or more directories
and zip/JAR files, separated by the path separator character, where the application classes are located. A
class loader that loads classes from this path will be created, with
loader
as its parent. The ConfigurationFile
is
created with this class loader, and all expected types specified in
entry description files are resolved in this class loader. If
classPath
is null
, then loader
is
used instead.
The class loader is used to resolve all expected types specified in the
entry description files, and to obtain the configuration provider. The
configuration provider class is found from the class loader in the same
manner as specified by ConfigurationProvider
. The resulting
class must be ConfigurationFile
or a subclass; if it is a
subclass, it must have a public constructor with three parameters of
type: Reader
, String[]
, and ClassLoader
. An instance of the provider is created by passing that
constructor a Reader
for the source file to be checked,
the location and entry override values, and the class loader.
classPath
- the search path for application classes, or
null
to use the specified class loaderloader
- the parent class loader to use for application classes if
classPath
is not null
, otherwise the class
loader to use for resolving application classesconfigOptions
- the configuration source file to check, plus any
entry overridesentriesPath
- one or more entry description files, separated by the
path separator character, or null
err
- the stream to use for printing errorstrue
if there are no errors, false
otherwiseNullPointerException
- if loader
,
configOptions
, or err
is null
check(ConfigurationFile, Properties, ClassLoader, PrintStream)
public static boolean check(ConfigurationFile config, Properties entries, ClassLoader loader, PrintStream err)
ConfigurationFile
. Returns
true
if there are no errors, and false
otherwise.config
- the ConfigurationFile
to checkentries
- the entry descriptions to use (where each key is a fully
qualified entry name and each value is the expected type), or
null
loader
- the class loader to use for resolving type names used in
the entry descriptionserr
- the stream to use for printing errorstrue
if there are no errors, false
otherwiseNullPointerException
- if config
,
loader
, or err
is null
check(String, ClassLoader, String[], String, PrintStream)
Copyright 2007-2013, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.