summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/IceGrid/DescriptorBuilder.cpp56
-rw-r--r--cpp/src/IceGrid/DescriptorBuilder.h3
-rw-r--r--cpp/src/IceGrid/DescriptorHelper.cpp32
-rw-r--r--cpp/src/IceGrid/DescriptorParser.cpp2
4 files changed, 81 insertions, 12 deletions
diff --git a/cpp/src/IceGrid/DescriptorBuilder.cpp b/cpp/src/IceGrid/DescriptorBuilder.cpp
index 5f73fcc2e86..18c959b7a8f 100644
--- a/cpp/src/IceGrid/DescriptorBuilder.cpp
+++ b/cpp/src/IceGrid/DescriptorBuilder.cpp
@@ -95,6 +95,52 @@ XmlAttributesHelper::asMap() const
return _attributes;
}
+bool
+XmlAttributesHelper::asBool(const string& name) const
+{
+ _used.insert(name);
+ IceXML::Attributes::const_iterator p = _attributes.find(name);
+ if(p == _attributes.end())
+ {
+ throw "missing attribute '" + name + "'";
+ }
+ else if(p->second == "true")
+ {
+ return true;
+ }
+ else if(p->second == "false")
+ {
+ return false;
+ }
+ else
+ {
+ throw "invalid attribute `" + name + "': value is not 'false' or 'true'";
+ }
+}
+
+bool
+XmlAttributesHelper::asBool(const string& name, bool def) const
+{
+ _used.insert(name);
+ IceXML::Attributes::const_iterator p = _attributes.find(name);
+ if(p == _attributes.end())
+ {
+ return def;
+ }
+ else if(p->second == "true")
+ {
+ return true;
+ }
+ else if(p->second == "false")
+ {
+ return false;
+ }
+ else
+ {
+ throw "invalid attribute `" + name + "': value is not 'false' or 'true'";
+ }
+}
+
void
DescriptorBuilder::addVariable(const XmlAttributesHelper&)
{
@@ -423,14 +469,14 @@ CommunicatorDescriptorBuilder::addAdapter(const XmlAttributesHelper& attrs)
desc.id = fqn + "." + desc.name;
}
desc.replicaGroupId = attrs("replica-group", "");
- desc.registerProcess = attrs("register-process", "false") == "true";
+ desc.registerProcess = attrs.asBool("register-process", false);
if(desc.id == "" && attrs.contains("wait-for-activation"))
{
throw "the attribute `wait-for-activation' can only be set if the adapter has an non empty id";
}
else
{
- desc.waitForActivation = attrs("wait-for-activation", "true") == "true";
+ desc.waitForActivation = attrs.asBool("wait-for-activation", true);
}
_descriptor->adapters.push_back(desc);
@@ -530,7 +576,7 @@ ServerDescriptorBuilder::init(const ServerDescriptorPtr& desc, const XmlAttribut
_descriptor->deactivationTimeout = attrs("deactivation-timeout", "");
_descriptor->pwd = attrs("pwd", "");
_descriptor->activation = attrs("activation", "manual");
- _descriptor->applicationDistrib = attrs("application-distrib", "true") != "false";
+ _descriptor->applicationDistrib = attrs.asBool("application-distrib", true);
}
ServiceDescriptorBuilder*
@@ -621,14 +667,14 @@ IceBoxDescriptorBuilder::addAdapter(const XmlAttributesHelper& attrs)
assert(desc.name == "IceBox.ServiceManager");
desc.id = attrs("id", desc.id);
desc.replicaGroupId = attrs("replica-group", desc.replicaGroupId);
- desc.registerProcess = attrs("register-process", desc.registerProcess ? "true" : "false") == "true";
+ desc.registerProcess = attrs.asBool("register-process", desc.registerProcess);
if(desc.id == "" && attrs.contains("wait-for-activation"))
{
throw "the attribute `wait-for-activation' can only be set if the adapter has an non empty id";
}
else
{
- desc.waitForActivation = attrs("wait-for-activation", desc.waitForActivation ? "true" : "false") == "true";
+ desc.waitForActivation = attrs.asBool("wait-for-activation", desc.waitForActivation);
}
if(attrs.contains("endpoints"))
diff --git a/cpp/src/IceGrid/DescriptorBuilder.h b/cpp/src/IceGrid/DescriptorBuilder.h
index 6b84af1b3fa..6139856287a 100644
--- a/cpp/src/IceGrid/DescriptorBuilder.h
+++ b/cpp/src/IceGrid/DescriptorBuilder.h
@@ -27,6 +27,9 @@ public:
bool contains(const std::string&) const;
std::map<std::string, std::string> asMap() const;
+ bool asBool(const std::string&) const;
+ bool asBool(const std::string&, bool) const;
+
std::string operator()(const std::string&) const;
std::string operator()(const std::string&, const std::string&) const;
diff --git a/cpp/src/IceGrid/DescriptorHelper.cpp b/cpp/src/IceGrid/DescriptorHelper.cpp
index 6d4767398c8..a85d3fbe3ec 100644
--- a/cpp/src/IceGrid/DescriptorHelper.cpp
+++ b/cpp/src/IceGrid/DescriptorHelper.cpp
@@ -309,20 +309,40 @@ Resolver::operator()(const string& value, const string& name, bool allowEmpty, b
{
try
{
- string val = substitute(value, useParams);
- if(!allowEmpty && val.empty())
+ string val;
+ try
{
- throw "empty value";
+ val = substitute(value, useParams);
+ }
+ catch(const string& reason)
+ {
+ throw "invalid variable `" + value + "': " + reason;
+ }
+ catch(const char* reason)
+ {
+ throw "invalid variable `" + value + "': " + reason;
+ }
+
+ if(!allowEmpty)
+ {
+ if(value.empty())
+ {
+ throw "empty string";
+ }
+ else if(val.empty())
+ {
+ throw "the value of the variable `" + value + "' is an empty string";
+ }
}
return val;
}
catch(const string& reason)
{
- exception("invalid value `" + value + "' for `" + name + "': " + reason);
+ exception("invalid value for attribute `" + name + "': " + reason);
}
catch(const char* reason)
{
- exception("invalid value `" + value + "' for `" + name + "': " + reason);
+ exception("invalid value for attribute `" + name + "': " + reason);
}
return ""; // To prevent compiler warning.
}
@@ -444,7 +464,7 @@ Resolver::substitute(const string& v, bool useParams) const
end = value.find("}", beg);
if(end == string::npos)
{
- throw "malformed variable name";
+ throw "malformed variable name `" + value + "'";
}
//
diff --git a/cpp/src/IceGrid/DescriptorParser.cpp b/cpp/src/IceGrid/DescriptorParser.cpp
index f4bed9e2f6a..a332d09bc05 100644
--- a/cpp/src/IceGrid/DescriptorParser.cpp
+++ b/cpp/src/IceGrid/DescriptorParser.cpp
@@ -172,7 +172,7 @@ DescriptorHandler::startElement(const string& name, const IceXML::Attributes& at
error("only one <application> element is allowed");
}
- if(_admin && attributes("import-default-templates", "false") == "true")
+ if(_admin && attributes.asBool("import-default-templates", false))
{
try
{