diff options
author | sb <sb@openoffice.org> | 2009-11-11 13:51:17 +0100 |
---|---|---|
committer | sb <sb@openoffice.org> | 2009-11-11 13:51:17 +0100 |
commit | 2e960eb1926080f6f98a3a7e886a45725eac7fe4 (patch) | |
tree | bb88a70b7ba01e82ba0ce9cdece3993eb53b4542 /configmgr | |
parent | 291b6d7e3b09ede5a589d5baf4c0effa13414e02 (diff) |
sb111: #i101955# fixed and cleaned up handling of oor:types of prop values
Diffstat (limited to 'configmgr')
-rw-r--r-- | configmgr/source/access.cxx | 12 | ||||
-rw-r--r-- | configmgr/source/childaccess.cxx | 4 | ||||
-rw-r--r-- | configmgr/source/localizedpropertynode.cxx | 10 | ||||
-rw-r--r-- | configmgr/source/localizedpropertynode.hxx | 8 | ||||
-rw-r--r-- | configmgr/source/propertynode.cxx | 10 | ||||
-rw-r--r-- | configmgr/source/propertynode.hxx | 8 | ||||
-rw-r--r-- | configmgr/source/type.cxx | 15 | ||||
-rw-r--r-- | configmgr/source/type.hxx | 2 | ||||
-rw-r--r-- | configmgr/source/writemodfile.cxx | 35 | ||||
-rw-r--r-- | configmgr/source/xcuparser.cxx | 48 |
10 files changed, 94 insertions, 58 deletions
diff --git a/configmgr/source/access.cxx b/configmgr/source/access.cxx index 032c3703c0ce..55d32f5d8ee9 100644 --- a/configmgr/source/access.cxx +++ b/configmgr/source/access.cxx @@ -361,7 +361,7 @@ void Access::checkValue(css::uno::Any const & value, Type type, bool nillable) { ok = false; break; case TYPE_ANY: - switch (mapType(value)) { + switch (getDynamicType(value)) { case TYPE_ANY: OSL_ASSERT(false); // fall through (cannot happen) @@ -396,7 +396,7 @@ void Access::insertLocalizedValueChild( OSL_ASSERT(localModifications != 0); LocalizedPropertyNode * locprop = dynamic_cast< LocalizedPropertyNode * >( getNode().get()); - checkValue(value, locprop->getType(), locprop->isNillable()); + checkValue(value, locprop->getStaticType(), locprop->isNillable()); rtl::Reference< ChildAccess > child( new ChildAccess( components_, getRootAccess(), this, name, @@ -1056,7 +1056,7 @@ css::uno::Type Access::getElementType() throw (css::uno::RuntimeException) { switch (p->kind()) { case Node::KIND_LOCALIZED_PROPERTY: return mapType( - dynamic_cast< LocalizedPropertyNode * >(p.get())->getType()); + dynamic_cast< LocalizedPropertyNode * >(p.get())->getStaticType()); case Node::KIND_GROUP: //TODO: Should a specific type be returned for a non-extensible group // with homogeneous members or for an extensible group that currently @@ -2041,7 +2041,7 @@ css::beans::Property Access::asProperty() { case Node::KIND_PROPERTY: { PropertyNode * prop = dynamic_cast< PropertyNode * >(p.get()); - type = mapType(prop->getType()); + type = mapType(prop->getStaticType()); nillable = prop->isNillable(); removable = prop->isExtension(); } @@ -2055,7 +2055,7 @@ css::beans::Property Access::asProperty() { //TODO: correct? removable = false; } else { - type = mapType(locprop->getType()); + type = mapType(locprop->getStaticType()); removable = false; //TODO ??? } nillable = locprop->isNillable(); @@ -2065,7 +2065,7 @@ css::beans::Property Access::asProperty() { { LocalizedPropertyNode * locprop = dynamic_cast< LocalizedPropertyNode * >(getParentNode().get()); - type = mapType(locprop->getType()); + type = mapType(locprop->getStaticType()); nillable = locprop->isNillable(); removable = false; //TODO ??? } diff --git a/configmgr/source/childaccess.cxx b/configmgr/source/childaccess.cxx index d5a8904679fb..11bb5b016789 100644 --- a/configmgr/source/childaccess.cxx +++ b/configmgr/source/childaccess.cxx @@ -234,7 +234,7 @@ void ChildAccess::setProperty( case Node::KIND_PROPERTY: { PropertyNode * prop = dynamic_cast< PropertyNode * >(node_.get()); - type = prop->getType(); + type = prop->getStaticType(); nillable = prop->isNillable(); } break; @@ -257,7 +257,7 @@ void ChildAccess::setProperty( { LocalizedPropertyNode * locprop = dynamic_cast< LocalizedPropertyNode * >(getParentNode().get()); - type = locprop->getType(); + type = locprop->getStaticType(); nillable = locprop->isNillable(); } break; diff --git a/configmgr/source/localizedpropertynode.cxx b/configmgr/source/localizedpropertynode.cxx index 185974e6d1fa..6f80411904dd 100644 --- a/configmgr/source/localizedpropertynode.cxx +++ b/configmgr/source/localizedpropertynode.cxx @@ -49,8 +49,8 @@ namespace css = com::sun::star; } LocalizedPropertyNode::LocalizedPropertyNode( - int layer, Type type, bool nillable): - Node(layer), type_(type), nillable_(nillable) + int layer, Type staticType, bool nillable): + Node(layer), staticType_(staticType), nillable_(nillable) {} rtl::Reference< Node > LocalizedPropertyNode::clone() const { @@ -61,8 +61,8 @@ NodeMap & LocalizedPropertyNode::getMembers() { return members_; } -Type LocalizedPropertyNode::getType() const { - return type_; +Type LocalizedPropertyNode::getStaticType() const { + return staticType_; } bool LocalizedPropertyNode::isNillable() const { @@ -71,7 +71,7 @@ bool LocalizedPropertyNode::isNillable() const { LocalizedPropertyNode::LocalizedPropertyNode( LocalizedPropertyNode const & other): - Node(other), type_(other.type_), nillable_(other.nillable_) + Node(other), staticType_(other.staticType_), nillable_(other.nillable_) { cloneNodeMap(other.members_, &members_); } diff --git a/configmgr/source/localizedpropertynode.hxx b/configmgr/source/localizedpropertynode.hxx index 4ac4fea36447..2fce6201b45e 100644 --- a/configmgr/source/localizedpropertynode.hxx +++ b/configmgr/source/localizedpropertynode.hxx @@ -47,13 +47,13 @@ namespace configmgr { class LocalizedPropertyNode: public Node { public: - LocalizedPropertyNode(int layer, Type type, bool nillable); + LocalizedPropertyNode(int layer, Type staticType, bool nillable); virtual rtl::Reference< Node > clone() const; virtual NodeMap & getMembers(); - Type getType() const; + Type getStaticType() const; bool isNillable() const; @@ -66,7 +66,9 @@ private: virtual void clear(); - Type type_; + Type staticType_; + // as specified in the component-schema (TYPE_ANY, ..., + // TYPE_HEXBINARY_LIST; not TYPE_ERROR or TYPE_NIL) bool nillable_; NodeMap members_; }; diff --git a/configmgr/source/propertynode.cxx b/configmgr/source/propertynode.cxx index b1035bd0b4ee..93aec170bfda 100644 --- a/configmgr/source/propertynode.cxx +++ b/configmgr/source/propertynode.cxx @@ -51,9 +51,9 @@ namespace css = com::sun::star; } PropertyNode::PropertyNode( - int layer, Type type, bool nillable, css::uno::Any const & value, + int layer, Type staticType, bool nillable, css::uno::Any const & value, bool extension): - Node(layer), type_(type), nillable_(nillable), value_(value), + Node(layer), staticType_(staticType), nillable_(nillable), value_(value), extension_(extension) {} @@ -61,8 +61,8 @@ rtl::Reference< Node > PropertyNode::clone() const { return new PropertyNode(*this); } -Type PropertyNode::getType() const { - return type_; +Type PropertyNode::getStaticType() const { + return staticType_; } bool PropertyNode::isNillable() const { @@ -98,7 +98,7 @@ bool PropertyNode::isExtension() const { } PropertyNode::PropertyNode(PropertyNode const & other): - Node(other), type_(other.type_), nillable_(other.nillable_), + Node(other), staticType_(other.staticType_), nillable_(other.nillable_), value_(other.value_), externalDescriptor_(other.externalDescriptor_), extension_(other.extension_) {} diff --git a/configmgr/source/propertynode.hxx b/configmgr/source/propertynode.hxx index 75e514ac8533..bd5c78f7786f 100644 --- a/configmgr/source/propertynode.hxx +++ b/configmgr/source/propertynode.hxx @@ -47,12 +47,12 @@ class Components; class PropertyNode: public Node { public: PropertyNode( - int layer, Type type, bool nillable, + int layer, Type staticType, bool nillable, com::sun::star::uno::Any const & value, bool extension); virtual rtl::Reference< Node > clone() const; - Type getType() const; + Type getStaticType() const; bool isNillable() const; @@ -71,7 +71,9 @@ private: virtual Kind kind() const; - Type type_; + Type staticType_; + // as specified in the component-schema (TYPE_ANY, ..., + // TYPE_HEXBINARY_LIST; not TYPE_ERROR or TYPE_NIL) bool nillable_; com::sun::star::uno::Any value_; rtl::OUString externalDescriptor_; diff --git a/configmgr/source/type.cxx b/configmgr/source/type.cxx index ccd9b7f18362..c1e6f118ca63 100644 --- a/configmgr/source/type.cxx +++ b/configmgr/source/type.cxx @@ -84,11 +84,7 @@ Type elementType(Type type) { css::uno::Type mapType(Type type) { switch (type) { - default: // TYPE_ERROR //TODO: can happen? - return cppu::UnoType< cppu::UnoVoidType >::get(); - case TYPE_NIL: //TODO: can happen? - return cppu::UnoType< cppu::UnoVoidType >::get(); - case TYPE_ANY: //TODO: can happen? + case TYPE_ANY: return cppu::UnoType< css::uno::Any >::get(); case TYPE_BOOLEAN: return cppu::UnoType< sal_Bool >::get(); @@ -119,11 +115,18 @@ css::uno::Type mapType(Type type) { case TYPE_HEXBINARY_LIST: return cppu::UnoType< css::uno::Sequence< css::uno::Sequence< sal_Int8 > > >::get(); + default: + OSL_ASSERT(false); + throw css::uno::RuntimeException( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("this cannot happen")), + css::uno::Reference< css::uno::XInterface >()); } } -Type mapType(css::uno::Any const & value) { +Type getDynamicType(css::uno::Any const & value) { switch (value.getValueType().getTypeClass()) { + case css::uno::TypeClass_VOID: + return TYPE_NIL; case css::uno::TypeClass_BOOLEAN: return TYPE_BOOLEAN; case css::uno::TypeClass_BYTE: diff --git a/configmgr/source/type.hxx b/configmgr/source/type.hxx index 46a16747dbc4..07d302f1592e 100644 --- a/configmgr/source/type.hxx +++ b/configmgr/source/type.hxx @@ -51,7 +51,7 @@ Type elementType(Type type); com::sun::star::uno::Type mapType(Type type); -Type mapType(com::sun::star::uno::Any const & value); +Type getDynamicType(com::sun::star::uno::Any const & value); } diff --git a/configmgr/source/writemodfile.cxx b/configmgr/source/writemodfile.cxx index b2fe14898658..1fcd5dec81fb 100644 --- a/configmgr/source/writemodfile.cxx +++ b/configmgr/source/writemodfile.cxx @@ -291,9 +291,6 @@ template< typename T > void writeItemListValue( void writeValue(oslFileHandle handle, Type type, css::uno::Any const & value) { switch (type) { - case TYPE_NIL: - writeData(handle, RTL_CONSTASCII_STRINGPARAM(" xsi:nil=\"true\"/>")); - break; case TYPE_BOOLEAN: writeSingleValue< sal_Bool >(handle, value); break; @@ -336,7 +333,7 @@ void writeValue(oslFileHandle handle, Type type, css::uno::Any const & value) { case TYPE_HEXBINARY_LIST: writeItemListValue< css::uno::Sequence< sal_Int8 > >(handle, value); break; - default: // TYPE_ERROR, TYPE_ANY + default: // TYPE_ERROR, TYPE_NIL, TYPE_ANY OSL_ASSERT(false); // this cannot happen } } @@ -369,10 +366,12 @@ void writeNode( writeData(handle, RTL_CONSTASCII_STRINGPARAM("<prop oor:name=\"")); writeAttributeValue(handle, name); writeData(handle, RTL_CONSTASCII_STRINGPARAM("\" oor:op=\"fuse\"")); - Type type = prop->getType(); + Type type = prop->getStaticType(); + Type dynType = getDynamicType(prop->getValue(components)); + OSL_ASSERT(dynType != TYPE_ERROR); if (type == TYPE_ANY) { - type = mapType(prop->getValue(components)); - if (type != TYPE_ERROR) { //TODO + type = dynType; + if (type != TYPE_NIL) { writeData( handle, RTL_CONSTASCII_STRINGPARAM(" oor:type=\"")); writeData( @@ -381,7 +380,12 @@ void writeNode( } } writeData(handle, "><value"); - writeValue(handle, type, prop->getValue(components)); + if (dynType == TYPE_NIL) { + writeData( + handle, RTL_CONSTASCII_STRINGPARAM(" xsi:nil=\"true\"/>")); + } else { + writeValue(handle, type, prop->getValue(components)); + } writeData(handle, "</prop>"); } break; @@ -405,12 +409,14 @@ void writeNode( writeData(handle, RTL_CONSTASCII_STRINGPARAM("\"")); } Type type = dynamic_cast< LocalizedPropertyNode * >(parent.get())-> - getType(); + getStaticType(); css::uno::Any value( dynamic_cast< LocalizedValueNode * >(node.get())->getValue()); + Type dynType = getDynamicType(value); + OSL_ASSERT(dynType != TYPE_ERROR); if (type == TYPE_ANY) { - type = mapType(value); - if (type != TYPE_ERROR) { // TODO + type = dynType; + if (type != TYPE_NIL) { writeData( handle, RTL_CONSTASCII_STRINGPARAM(" oor:type=\"")); writeData( @@ -418,7 +424,12 @@ void writeNode( writeData(handle, RTL_CONSTASCII_STRINGPARAM("\"")); } } - writeValue(handle, type, value); + if (dynType == TYPE_NIL) { + writeData( + handle, RTL_CONSTASCII_STRINGPARAM(" xsi:nil=\"true\"/>")); + } else { + writeValue(handle, type, value); + } } break; case Node::KIND_GROUP: diff --git a/configmgr/source/xcuparser.cxx b/configmgr/source/xcuparser.cxx index a26d24f5abc8..948ebffcdaeb 100644 --- a/configmgr/source/xcuparser.cxx +++ b/configmgr/source/xcuparser.cxx @@ -414,6 +414,19 @@ void XcuParser::handlePropValue(XmlReader & reader, PropertyNode * prop) { { nil = xmldata::parseBoolean(reader.getAttributeValue(true)); } else if (attrNs == XmlReader::NAMESPACE_OOR && + attrLn.equals(RTL_CONSTASCII_STRINGPARAM("type"))) + { + Type type = xmldata::parseType( + reader, reader.getAttributeValue(true)); + if (valueParser_.type_ != TYPE_ANY && type != valueParser_.type_) { + throw css::uno::RuntimeException( + (rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM("invalid value type in ")) + + reader.getUrl()), + css::uno::Reference< css::uno::XInterface >()); + } + valueParser_.type_ = type; + } else if (attrNs == XmlReader::NAMESPACE_OOR && attrLn.equals(RTL_CONSTASCII_STRINGPARAM("separator"))) { Span s(reader.getAttributeValue(false)); @@ -490,6 +503,19 @@ void XcuParser::handleLocpropValue( { nil = xmldata::parseBoolean(reader.getAttributeValue(true)); } else if (attrNs == XmlReader::NAMESPACE_OOR && + attrLn.equals(RTL_CONSTASCII_STRINGPARAM("type"))) + { + Type type = xmldata::parseType( + reader, reader.getAttributeValue(true)); + if (valueParser_.type_ != TYPE_ANY && type != valueParser_.type_) { + throw css::uno::RuntimeException( + (rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM("invalid value type in ")) + + reader.getUrl()), + css::uno::Reference< css::uno::XInterface >()); + } + valueParser_.type_ = type; + } else if (attrNs == XmlReader::NAMESPACE_OOR && attrLn.equals(RTL_CONSTASCII_STRINGPARAM("separator"))) { Span s(reader.getAttributeValue(false)); @@ -605,14 +631,6 @@ void XcuParser::handleGroupProp(XmlReader & reader, GroupNode * group) { reader.getUrl()), css::uno::Reference< css::uno::XInterface >()); } - if (type == TYPE_ANY) { - throw css::uno::RuntimeException( - (rtl::OUString( - RTL_CONSTASCII_USTRINGPARAM( - "invalid prop type attribute in ")) + - reader.getUrl()), - css::uno::Reference< css::uno::XInterface >()); - } NodeMap::iterator i(group->getMembers().find(name)); if (i == group->getMembers().end()) { handleUnknownGroupProp(reader, group, name, type, op, finalized); @@ -701,8 +719,8 @@ void XcuParser::handlePlainGroupProp( finalized ? valueParser_.getLayer() : Data::NO_LAYER, property->getFinalized()); property->setFinalized(finalizedLayer); - if (type != TYPE_ERROR && property->getType() != TYPE_ANY && - type != property->getType()) + if (type != TYPE_ERROR && property->getStaticType() != TYPE_ANY && + type != property->getStaticType()) { throw css::uno::RuntimeException( (rtl::OUString( @@ -711,7 +729,7 @@ void XcuParser::handlePlainGroupProp( reader.getUrl()), css::uno::Reference< css::uno::XInterface >()); } - valueParser_.type_ = type == TYPE_ERROR ? property->getType() : type; + valueParser_.type_ = type == TYPE_ERROR ? property->getStaticType() : type; switch (operation) { case OPERATION_MODIFY: case OPERATION_REPLACE: @@ -759,8 +777,8 @@ void XcuParser::handleLocalizedGroupProp( finalized ? valueParser_.getLayer() : Data::NO_LAYER, property->getFinalized()); property->setFinalized(finalizedLayer); - if (type != TYPE_ERROR && property->getType() != TYPE_ANY && - type != property->getType()) + if (type != TYPE_ERROR && property->getStaticType() != TYPE_ANY && + type != property->getStaticType()) { throw css::uno::RuntimeException( (rtl::OUString( @@ -769,7 +787,7 @@ void XcuParser::handleLocalizedGroupProp( reader.getUrl()), css::uno::Reference< css::uno::XInterface >()); } - valueParser_.type_ = type == TYPE_ERROR ? property->getType() : type; + valueParser_.type_ = type == TYPE_ERROR ? property->getStaticType() : type; switch (operation) { case OPERATION_MODIFY: case OPERATION_FUSE: @@ -786,7 +804,7 @@ void XcuParser::handleLocalizedGroupProp( { rtl::Reference< Node > replacement( new LocalizedPropertyNode( - valueParser_.getLayer(), property->getType(), + valueParser_.getLayer(), property->getStaticType(), property->isNillable())); replacement->setFinalized(property->getFinalized()); state_.push( |