|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcds.util.Parameters
Parameter objects.
Parameters are contained in files. Their syntax is described below.
The files may have any extension. If there is no extension, the default
extension '.prm' is used.
The data model is made of:
- sections gathering several parameters
- parameters made of a name and a value (syntax: name = value)
A section entry can also contain a pathname whose parameters will be loaded under this section (include). The section can afterwards be completed by regular local parameters. An anonymous include (without section name) requires that the called file contains its own section names.
The syntax will primarily be the one of windows .ini files.
[section]A special section is [system] . It can contain currently the following entries:
param1=value
param2 = value
[section = pathname]
otherparam=value
[section=pathname2]
[= pathname]
...
[macro] and [gmacro] are special setions containing variable definitions.
macros are local to one parameter file, gmacro are global macros available
for all parameter files loaded after the macro definitions.
A macro is written:
[macro] ROOT=/usr/local VERSION=1.3 ...and is used in any parameter definition like a variable in a shell:
myfile = $ROOT/xfile number = ${VERSION}a
[macro = /home/macros/mymacro]mymacro being a parameter file (default extension .prm)
Comments are lines beginning with a # char
Long lines can be split in several lines, provided that each non final
line is ended by a '\'. The convention is to keep any space before the '\',
and suppress any space beginning the line. So the following:
param = first part + \ second partwill be read like :
param = first part + second part
The parameter objects are made of two levels of HashMaps: a first HashMap manages the sections, each section being one HashMap containing the parameters.
Parameters pathnames can be either regular filenames or URLs. The default extension of these files is '.prm'. But any extension name is accepted if it exists.
Field Summary | |
protected static java.lang.String |
BACKUP_EXTENSION
|
protected static java.lang.String |
CONTINUATION_CHAR
|
protected static java.lang.String |
CREATION_NAME
|
protected static java.lang.String |
DEFAULT_EXTENSION
|
protected static java.lang.String |
GLOBAL_MACRO_NAME
|
private static Macro |
globalMacroDic
|
protected static java.lang.String |
MACRO_NAME
|
private Macro |
macroDic
|
protected java.lang.String |
name
|
protected static java.lang.String |
NAME_NAME
|
protected static SortedHashMap |
paramList
|
protected SortedHashMap |
params
|
protected java.lang.String |
pathname
|
protected static char |
SECTION_BEGIN_CHAR
|
protected static java.lang.String |
SECTION_DELIM_NAME
|
protected static char |
SECTION_END_CHAR
|
private char |
sectionBeginChar
|
private char |
sectionEndChar
|
protected java.lang.String |
sectionName
|
protected SortedHashMap |
sections
|
protected static java.lang.String |
SYSTEM_SECTION_NAME
|
static java.lang.String |
UNKNOWN_PARAM
|
protected static char |
VAR_VAL_SEP
|
private char |
varValSep
|
protected static java.lang.String |
VARVALSEP_NAME
|
Constructor Summary | |
Parameters()
Empty constructor : creates a Parameters object for memory only usage. |
|
Parameters(java.lang.String pathname)
Constructor. |
|
Parameters(java.lang.String pathname,
java.lang.String name)
Constructor. |
Method Summary | |
java.lang.String |
add(java.lang.String sectionName,
boolean create,
java.lang.String name,
java.lang.String value)
adds a parameter to a particular section If the section does not yet exist, it will be created if the create variable is true. |
void |
add(java.lang.String name,
java.lang.String value)
adds a parameter to the unnamed section. |
private java.lang.String |
completeName(java.lang.String pathname)
Computes the full pathname, including an eventual extension |
void |
delete()
Deletes the whole Parameters object |
java.lang.String |
get(java.lang.String name)
returns the value of a parameter, without specifying the section. |
java.lang.String |
get(java.lang.String section,
java.lang.String name)
returns the value for a particular parameter |
static java.lang.String |
get(java.lang.String pname,
java.lang.String section,
java.lang.String name)
returns the value for a particular parameter |
java.lang.String |
getName()
returns the name of a parameters object. |
static Parameters |
getParameters(java.lang.String name)
Returns the Parameters object corresponding to its name |
static java.util.Iterator |
getParametersIterator()
Returns an iterator to browse the Parameters object list |
private java.lang.String |
getPath(java.lang.String sname,
java.lang.String name)
Returns the full path of a parameter in the current object |
private static java.lang.String |
getPath(java.lang.String pname,
java.lang.String sname,
java.lang.String name)
Returns the full path of a parameter |
java.util.HashMap |
getTopic(java.lang.String name)
returns the HashMap corresponding to a section |
private void |
init(java.lang.String pathname,
java.lang.String name)
Initializes and loads a Parameters file |
java.util.Iterator |
iterator()
Returns an Iterator object for the list of sections usage is: while(iter.hasNext()) { String sectionname = (String) iter.next()); ... } |
java.util.Iterator |
iterator(java.lang.String sectionName)
Returns an Iterator object for the parameters of the given section |
java.util.Iterator |
iteratorCreate(java.lang.String sectionName)
Retourne un iterateur sur les parametres d'une section donnee Les parametres concernes sont ceux sans valeur, avec valeur differente de listes ou composees et les parametres presents dans les listes ou composees |
java.util.Iterator |
iteratorGet(java.lang.String sectionName)
Retourne un iterateur sur les parametres d'une section donnee Les parametres concernes sont ceux sans valeur et ceux ayant pour valeur des listes ou composees |
java.util.Iterator |
iteratorInsert(java.lang.String sectionName)
Retourne un iterateur sur les parametres d'une section donnee Les parametres concernes sont ceux sans valeur et les parametres presents dans les listes ou composees |
protected boolean |
load(java.lang.String pathname)
load the parameters from the designated file or URL |
static void |
main(java.lang.String[] args)
|
boolean |
paramExists(java.lang.String section,
java.lang.String param)
Methode qui permet de savoir si un parametre est contenu dans une section |
boolean |
sectionExists(java.lang.String section)
Methode qui permet de savoir si une section existe dans le fichier de parametre |
void |
setName(java.lang.String name)
Sets a name to the Parameters object. |
void |
setPathName(java.lang.String path)
Sets the pathname for a created parameters set |
java.lang.String |
toString()
Edition of a parameter set in a String. |
void |
update(java.lang.String sectionName,
java.lang.String name,
java.lang.String value)
updates a Parameters object: the parameter is written (whether it exists or not) in the given section and the Parameters object is written down |
void |
write(boolean backup)
write the parameter file |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final java.lang.String UNKNOWN_PARAM
protected static final java.lang.String DEFAULT_EXTENSION
protected static final java.lang.String BACKUP_EXTENSION
protected static final java.lang.String CONTINUATION_CHAR
protected static final char VAR_VAL_SEP
protected static final char SECTION_BEGIN_CHAR
protected static final char SECTION_END_CHAR
private char varValSep
private char sectionBeginChar
private char sectionEndChar
protected static final java.lang.String SYSTEM_SECTION_NAME
protected static final java.lang.String CREATION_NAME
protected static final java.lang.String NAME_NAME
protected static final java.lang.String VARVALSEP_NAME
protected static final java.lang.String SECTION_DELIM_NAME
protected static final java.lang.String MACRO_NAME
protected static final java.lang.String GLOBAL_MACRO_NAME
private static Macro globalMacroDic
private Macro macroDic
protected static SortedHashMap paramList
protected java.lang.String pathname
protected java.lang.String name
protected SortedHashMap sections
protected java.lang.String sectionName
protected SortedHashMap params
Constructor Detail |
public Parameters()
public Parameters(java.lang.String pathname)
pathname
- filename or URL of the file containing the parameters to loadpublic Parameters(java.lang.String pathname, java.lang.String name)
pathname
- filename or URL of the file containing the parameters to loadname
- name of the Parameters object. Needed to retrieve it easily
through a static method.Method Detail |
private void init(java.lang.String pathname, java.lang.String name)
pathname
- filepath for the parameter file. If it ends with an
extension, it is kept. If it is without extension, the default
extension '.prm' is appended.name
- forcing a name for the parameter set. This name may be
overriden by the 'name' parameter in the [system] section.private java.lang.String completeName(java.lang.String pathname)
pathname
- original name
protected boolean load(java.lang.String pathname) throws java.io.IOException
pathname
- name of the file or URL containing the parameters to load
The file should have 'prm' as extension. If the string pathname has not
this extension, it will be added
java.io.IOException
public void setName(java.lang.String name)
name
- name to give to the Parameters objectpublic void setPathName(java.lang.String path)
path
- pathname (without the final filename)public java.lang.String getName()
public static Parameters getParameters(java.lang.String name)
name
- name of the Parameters object to retrieve
public static java.util.Iterator getParametersIterator()
public java.util.HashMap getTopic(java.lang.String name)
name
- name of the section
public static java.lang.String get(java.lang.String pname, java.lang.String section, java.lang.String name)
pname
- parameter object namesection
- name of the sectionname
- name of the parameter
public java.lang.String get(java.lang.String section, java.lang.String name)
section
- name of the sectionname
- name of the parameter
public java.lang.String get(java.lang.String name)
name
- name of the parameter to find
public java.lang.String add(java.lang.String sectionName, boolean create, java.lang.String name, java.lang.String value)
sectionName
- name of the section to which the parameter should be addedcreate
- if true, create a not yet existing sectionname
- parameter namevalue
- parameter value
public void update(java.lang.String sectionName, java.lang.String name, java.lang.String value)
sectionName
- name of the section to which the parameter should be addedname
- parameter namevalue
- parameter valuepublic void add(java.lang.String name, java.lang.String value)
name
- parameter namevalue
- parameter valueprivate static java.lang.String getPath(java.lang.String pname, java.lang.String sname, java.lang.String name)
pname
- Parameters object namesname
- Section namename
- parameter name. It can be replaced by null to display a section path.
private java.lang.String getPath(java.lang.String sname, java.lang.String name)
sname
- Section namename
- parameter name. It can be replaced by null to display a section path.
public java.util.Iterator iterator()
while(iter.hasNext()) { String sectionname = (String) iter.next()); ... }
public java.util.Iterator iterator(java.lang.String sectionName)
sectionName
- name of the section whose elements will be accessed by
the iterator. Browsing through all parameters is done with the
following sequence:
Iterator itop = params.iterator(); while (itop.hasNext()) { String topname = (String) itop.next(); System.out.println("== "+topname+":"); Enumeration iparm = params.itarator(topname); while (iparm.hasNext()) { String parmname = (String) iparm.next(); System.out.println("\t"+parmname+" = "+params.get(topname,parmname)); } }
public java.util.Iterator iteratorCreate(java.lang.String sectionName)
sectionName
- nom de la section
public java.util.Iterator iteratorInsert(java.lang.String sectionName)
sectionName
- nom de la section
public java.util.Iterator iteratorGet(java.lang.String sectionName)
sectionName
- nom de la section
public void write(boolean backup)
backup
- if truepublic java.lang.String toString()
public void delete()
public boolean paramExists(java.lang.String section, java.lang.String param)
section
- nom de la sectionparam
- nom du parametre
public boolean sectionExists(java.lang.String section)
section
- nom de la section
public static void main(java.lang.String[] args)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |