summaryrefslogtreecommitdiff
path: root/cpp/src/XMLTransform/XMLTransform.cpp
diff options
context:
space:
mode:
authorBenoit Foucher <benoit@zeroc.com>2002-11-18 23:06:07 +0000
committerBenoit Foucher <benoit@zeroc.com>2002-11-18 23:06:07 +0000
commit38c62a0cffe000e9f0a732aa2a6dd91a4d81f650 (patch)
treed3ce130d4aaed7a669764bc3cf59f5b13cd0c4cf /cpp/src/XMLTransform/XMLTransform.cpp
parentfix (diff)
downloadice-38c62a0cffe000e9f0a732aa2a6dd91a4d81f650.tar.bz2
ice-38c62a0cffe000e9f0a732aa2a6dd91a4d81f650.tar.xz
ice-38c62a0cffe000e9f0a732aa2a6dd91a4d81f650.zip
- Improved InvalidSchema exception message for exception raised if an
imported schema can't be found. - Added basic support for xsd:boolean (transformation from other types is not allowed). - Don't fail anymore when reading an exception type element from the schema. - Correctly handle cases where reference to an object is null (check if the xsi:nil attribute is true, if yes, just write the node as-is).
Diffstat (limited to 'cpp/src/XMLTransform/XMLTransform.cpp')
-rw-r--r--cpp/src/XMLTransform/XMLTransform.cpp43
1 files changed, 39 insertions, 4 deletions
diff --git a/cpp/src/XMLTransform/XMLTransform.cpp b/cpp/src/XMLTransform/XMLTransform.cpp
index 0f321e28c2b..5eef0c79cd7 100644
--- a/cpp/src/XMLTransform/XMLTransform.cpp
+++ b/cpp/src/XMLTransform/XMLTransform.cpp
@@ -923,6 +923,16 @@ public:
return;
}
+ //
+ // If the object is null simply emit the node as-is.
+ //
+ string nil = getAttributeByName(node, "xsi:nil");
+ if(!nil.empty() && nil == "true")
+ {
+ os << node;
+ return;
+ }
+
//
// Otherwise, xsi:type must be present.
//
@@ -1097,6 +1107,7 @@ private:
enum Type
{
+ TypeBoolean,
TypeInteger, // byte, short, int, long
TypeFloat, // float, double
TypeString,
@@ -1249,6 +1260,7 @@ const TransformFactory::StringTypeTable* TransformFactory::itemsEnd = &items[siz
const TransformFactory::StringTypeTable TransformFactory::itemsByName[] =
{
+ { "xs:boolean", TransformFactory::TypeBoolean },
{ "xs:byte", TransformFactory::TypeInteger },
{ "xs:short", TransformFactory::TypeInteger },
{ "xs:int", TransformFactory::TypeInteger },
@@ -1474,13 +1486,13 @@ XMLTransform::TransformFactory::import(DocumentMap& documents, const string& ns,
catch(const XMLException& ex)
{
InvalidSchema e(__FILE__, __LINE__);
- e.reason = "XML exception while importing " + loc + ": " + toString(ex.getMessage());
+ e.reason = "XML exception while importing " + loc + ":\n" + toString(ex.getMessage());
throw e;
}
catch(const SAXParseException& ex)
{
InvalidSchema e(__FILE__, __LINE__);
- e.reason = "SAX exception while importing " + loc + ": " + toString(ex.getMessage());
+ e.reason = "SAX exception while importing " + loc + ":\n" + toString(ex.getMessage());
throw e;
}
catch(...)
@@ -1493,7 +1505,7 @@ XMLTransform::TransformFactory::import(DocumentMap& documents, const string& ns,
if(errorReporter.getSawErrors())
{
InvalidSchema ex(__FILE__, __LINE__);
- ex.reason = errorReporter.getErrors();
+ ex.reason = "errors while importing " + loc + ":\n" + errorReporter.getErrors();
throw ex;
}
@@ -1797,6 +1809,14 @@ XMLTransform::TransformFactory::createTransform(const DocumentInfoPtr& fromTypeI
{
switch(fromType)
{
+ case TypeBoolean:
+ {
+ //
+ // Don't cache this transform.
+ //
+ return new NilTransform();
+ }
+
case TypeInteger:
{
//
@@ -1988,10 +2008,21 @@ XMLTransform::TransformFactory::createTransform(const DocumentInfoPtr& fromTypeI
}
case TypeException:
+ {
+ //
+ // TODO: BENOIT: Is this correct? We can't throw an IllegalTransform here because it's possible
+ // that the schema have exception elements, even if these elements don't take part in any
+ // transformations. Maybe we could return a null transformation here since this transformation
+ // will never be used anyway.
+ //
+ transform = new NilTransform();
+ break;
+ }
+
default:
{
IllegalTransform ex(__FILE__, __LINE__);
- ex.reason = "invalid type";
+ ex.reason = "invalid type";
throw ex;
}
}
@@ -2274,6 +2305,10 @@ XMLTransform::TransformFactory::createDefaultInitializedTransform(const Document
TransformPtr transform = 0;
switch(type)
{
+ case TypeBoolean:
+ transform = new EmitStringTransform("false");
+ break;
+
case TypeInteger:
transform = new EmitStringTransform("0");
break;