Public Types | |
typedef std::map< std::string, std::string, std::less< std::string > > | MapType |
Public Member Functions | |
Property (int args=0, const char *const argv[]=0) | |
The default constructor allocate the storage std::map for the properties and parses the command line properties. | |
Property (MapType propMap) | |
Initialize with the given key/value std::map. | |
void | loadPropertyFile () |
~Property () | |
void | replaceVariables (bool env) |
Replace all ${. | |
const MapType & | getPropertyMap () const |
int | readPropertyFile (const std::string &filename, bool overwrite=true) |
Reads the file specified in filename. | |
int | writePropertyFile (const char *filename) const |
writes the properties to a file specified in the argument list. | |
std::string | getProperty (const std::string &name, bool env=true) |
Gets the propety with the specified name. | |
bool | Exists (const std::string &name, bool env=true) |
int | get (const std::string &name, int def) |
int | getIntProperty (const std::string &name, int def, bool env=true) |
long | get (const std::string &name, long def) |
long | getLongProperty (const std::string &name, long def, bool env=true) |
org::xmlBlaster::util::Timestamp | getTimestampProperty (const std::string &name, org::xmlBlaster::util::Timestamp def, bool env=true) |
bool | get (const std::string &name, bool def) |
bool | getBoolProperty (const std::string &name, bool def, bool env=true) |
std::string | get (const std::string &name, const char *def) |
std::string | get (const std::string &name, const std::string &def) |
std::string | getStringProperty (const std::string &name, const std::string &def, bool env=true) |
bool | getTypedProperty (const std::string &name, std::string &value, bool env=true) |
To allow templatized getting of properties. | |
bool | getTypedProperty (const std::string &name, int &value, bool env=true) |
bool | getTypedProperty (const std::string &name, long &value, bool env=true) |
bool | getTypedProperty (const std::string &name, bool &value, bool env=true) |
bool | getTypedProperty (const std::string &name, org::xmlBlaster::util::Timestamp &value, bool env=true) |
bool | setProperty (const std::string &name, const std::string &value, bool overwrite=true) |
int | loadCommandLineProps (int args, const char *const argv[], const std::string &sep="-D", bool javaStyle=true) |
Loads the properties read from the command line (or another array). | |
int | findArgument (int args, const char *const argv[], const std::string &name) |
It searches in the argument list specified by argv the argument specified by name. | |
std::string | toXml (const std::string &extraOffset="") |
Protected Member Functions | |
bool | isComment (const std::string &line) const |
returns true if the line is a comment, or if it is empty. | |
std::string | filter (const std::string &line) const |
Filters (throws away) all whitespaces from the specified std::string. | |
std::pair< const std::string, std::string > | getPair (const std::string &line) const |
gets the property in the line specified in the argument list. |
It does not throw any exception. Errors in file-reading, writing etc. are handled by returning a special value (which for integers is zero and for bool is false and empty std::strings for std::strings.
When reading or writing, comments and empty lines are ignored. When writing, properties are written in alphabetical order (of the property name).
In properties like SomeValue-${xy}-somePostValue
the ${}
are replaced by the value of xy
.
Fills during construction the properties user.home
and file.separator
and path.separator
and others as described at method initializeDefaultProperties()
. This simplifies the reuse of the xmlBlaster.properties which uses those settings from the Java environment.
Definition at line 36 of file Property.h.
typedef std::map<std::string, std::string, std::less<std::string> > org::xmlBlaster::util::Property::MapType |
Definition at line 38 of file Property.h.
org::xmlBlaster::util::Property::Property | ( | int | args = 0 , |
|
const char *const | argv[] = 0 | |||
) |
The default constructor allocate the storage std::map for the properties and parses the command line properties.
NOTE: You have to call loadPropertyFile() separatly
args | Length of argv | |
argv | The command line arguments, for example "-protocol SOCKET" |
Property::Property | ( | MapType | propMap | ) |
Initialize with the given key/value std::map.
NOTE: You have to call loadPropertyFile() separately
propertyMap | A std::map which contains key and values pairs, for example key="protocol" and value="SOCKET" |
Definition at line 33 of file Property.cpp.
References replaceVariables().
org::xmlBlaster::util::Property::~Property | ( | ) |
Definition at line 146 of file Property.h.
bool org::xmlBlaster::util::Property::isComment | ( | const std::string & | line | ) | const [protected] |
returns true if the line is a comment, or if it is empty.
Returns false if the line is a possible property line. "Possible" in the sense that its validity is not checked yet.
Definition at line 77 of file Property.h.
std::string org::xmlBlaster::util::Property::filter | ( | const std::string & | line | ) | const [protected] |
Filters (throws away) all whitespaces from the specified std::string.
Definition at line 85 of file Property.h.
std::pair<const std::string, std::string> org::xmlBlaster::util::Property::getPair | ( | const std::string & | line | ) | const [protected] |
gets the property in the line specified in the argument list.
It returns this property as a pair name,value. If the line does not contain a valid property(for example if the = sign is not present) then a pair of empty std::strings is returned.
Definition at line 100 of file Property.h.
void Property::loadPropertyFile | ( | ) |
Definition at line 185 of file Property.cpp.
References FILE_SEP, getProperty(), getStringProperty(), readPropertyFile(), and replaceVariables().
Referenced by org::xmlBlaster::util::Global::initialize(), and org::xmlBlaster::test::TestProperty::testLoadPropertyFile().
void Property::replaceVariables | ( | bool | env | ) |
Replace all ${.
..} variables in value.
env | If true the environment is scanned as well |
Definition at line 458 of file Property.cpp.
Referenced by loadPropertyFile(), and Property().
const MapType& org::xmlBlaster::util::Property::getPropertyMap | ( | ) | const |
int org::xmlBlaster::util::Property::readPropertyFile | ( | const std::string & | filename, | |
bool | overwrite = true | |||
) |
Reads the file specified in filename.
If the name is not valid, or if the system can not write to the specified file, then -1 is returned. If you specify overwrite=true (the default) then the properties read from the file are inserted into the properties even if a property with the same name has been defined earlier.
Note: The ${...} tokens are not replaced in this method
Referenced by loadPropertyFile().
int org::xmlBlaster::util::Property::writePropertyFile | ( | const char * | filename | ) | const |
writes the properties to a file specified in the argument list.
If it could not write to the file, a zero is returned. Returns the number of properties written to the file.
std::string org::xmlBlaster::util::Property::getProperty | ( | const std::string & | name, | |
bool | env = true | |||
) |
Gets the propety with the specified name.
If no such property exists, an empty std::string is returned. If the std::string is not found, it searches in among the environment variables (only if env is set to true which is the default). In the property is not found there either, it returns an empty std::string.
Referenced by loadPropertyFile().
bool org::xmlBlaster::util::Property::Exists | ( | const std::string & | name, | |
bool | env = true | |||
) |
int org::xmlBlaster::util::Property::get | ( | const std::string & | name, | |
int | def | |||
) |
Definition at line 193 of file Property.h.
Referenced by MultiConnectDemo::execute(), HelloWorld2::execute(), SubscribeDemo::initEnvironment(), PublishDemo::initEnvironment(), Leak::Leak(), main(), org::xmlBlaster::util::queue::SQLiteQueuePlugin::SQLiteQueuePlugin(), org::xmlBlaster::test::TestProperty::testDefault(), org::xmlBlaster::test::TestThread::testRecursiveThread(), and org::xmlBlaster::test::TestProperty::testReplace().
int org::xmlBlaster::util::Property::getIntProperty | ( | const std::string & | name, | |
int | def, | |||
bool | env = true | |||
) |
long org::xmlBlaster::util::Property::get | ( | const std::string & | name, | |
long | def | |||
) |
Definition at line 196 of file Property.h.
long org::xmlBlaster::util::Property::getLongProperty | ( | const std::string & | name, | |
long | def, | |||
bool | env = true | |||
) |
org::xmlBlaster::util::Timestamp org::xmlBlaster::util::Property::getTimestampProperty | ( | const std::string & | name, | |
org::xmlBlaster::util::Timestamp | def, | |||
bool | env = true | |||
) |
bool org::xmlBlaster::util::Property::get | ( | const std::string & | name, | |
bool | def | |||
) |
Definition at line 201 of file Property.h.
bool org::xmlBlaster::util::Property::getBoolProperty | ( | const std::string & | name, | |
bool | def, | |||
bool | env = true | |||
) |
std::string org::xmlBlaster::util::Property::get | ( | const std::string & | name, | |
const char * | def | |||
) |
Definition at line 205 of file Property.h.
std::string org::xmlBlaster::util::Property::get | ( | const std::string & | name, | |
const std::string & | def | |||
) |
Definition at line 206 of file Property.h.
std::string org::xmlBlaster::util::Property::getStringProperty | ( | const std::string & | name, | |
const std::string & | def, | |||
bool | env = true | |||
) |
Referenced by org::xmlBlaster::util::qos::AccessFilterQos::AccessFilterQos(), org::xmlBlaster::client::XmlBlasterAccess::connect(), org::xmlBlaster::util::Global::getBootstrapHostname(), org::xmlBlaster::util::Global::getCbHostname(), org::xmlBlaster::util::parser::ParserFactory::getLocale(), org::xmlBlaster::client::protocol::corba::CorbaConnection::initAuthenticationService(), org::xmlBlaster::util::Log::initialize(), loadPropertyFile(), org::xmlBlaster::util::parser::Sax2Parser::Sax2Parser(), org::xmlBlaster::test::TestDoubleGlobal::sessionQos(), org::xmlBlaster::test::TestConnectQos::testSessionQos(), org::xmlBlaster::test::TestSuite::TestSuite(), and org::xmlBlaster::client::XmlBlasterAccess::usage().
bool org::xmlBlaster::util::Property::getTypedProperty | ( | const std::string & | name, | |
std::string & | value, | |||
bool | env = true | |||
) |
To allow templatized getting of properties.
It returns true if the property has been found. In that case, the return value is put into the 'value' argument.
Referenced by org::xmlBlaster::util::Prop< bool >::setValue().
bool org::xmlBlaster::util::Property::getTypedProperty | ( | const std::string & | name, | |
int & | value, | |||
bool | env = true | |||
) |
bool org::xmlBlaster::util::Property::getTypedProperty | ( | const std::string & | name, | |
long & | value, | |||
bool | env = true | |||
) |
bool org::xmlBlaster::util::Property::getTypedProperty | ( | const std::string & | name, | |
bool & | value, | |||
bool | env = true | |||
) |
bool org::xmlBlaster::util::Property::getTypedProperty | ( | const std::string & | name, | |
org::xmlBlaster::util::Timestamp & | value, | |||
bool | env = true | |||
) |
bool org::xmlBlaster::util::Property::setProperty | ( | const std::string & | name, | |
const std::string & | value, | |||
bool | overwrite = true | |||
) |
int org::xmlBlaster::util::Property::loadCommandLineProps | ( | int | args, | |
const char *const | argv[], | |||
const std::string & | sep = "-D" , |
|||
bool | javaStyle = true | |||
) |
Loads the properties read from the command line (or another array).
The syntax for passing properties is the same as in java if the switch javaStyle is true (default). That is "-Dprop1=val1" is then equivalent as prop1=val1 in a property file. If the switch javaStyle is false, then the Corba style is chosen, i.e. the following is correct syntax: "-ORBNameService whatever" (so no equality sign between name and value). Errors in syntax are silently ignored (the property just isn't load).
args | The length of argv[] | |
argv | The command line arguments, argv[0] is the executable name, for example { "HelloWorld2" "-trace" "true" } | |
sep | The property praefix, for example "-" for "-trace true" |
int org::xmlBlaster::util::Property::findArgument | ( | int | args, | |
const char *const | argv[], | |||
const std::string & | name | |||
) |
It searches in the argument list specified by argv the argument specified by name.
If nothing is found it returns -1, otherwise it returns the index of argv corresponding to what specified in name.
Definition at line 251 of file Property.h.
std::string org::xmlBlaster::util::Property::toXml | ( | const std::string & | extraOffset = "" |
) |