@@ -464,10 +464,75 @@ @throw e; } data[j]->object = object; } + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- initWithSerialization: (OFXMLElement*)element +{ + @try { + OFAutoreleasePool *pool, *pool2; + OFMutableDictionary *dictionary; + OFArray *pairs; + OFEnumerator *enumerator; + OFXMLElement *pair; + + pool = [[OFAutoreleasePool alloc] init]; + + if (![[element name] isEqual: @"object"] || + ![[element namespace] isEqual: OF_SERIALIZATION_NS] || + ![[[element attributeForName: @"class"] stringValue] + isEqual: [isa className]]) + @throw [OFInvalidArgumentException newWithClass: isa + selector: _cmd]; + + dictionary = [OFMutableDictionary dictionary]; + pairs = [element elementsForName: @"pair" + namespace: OF_SERIALIZATION_NS]; + + enumerator = [pairs objectEnumerator]; + pool2 = [[OFAutoreleasePool alloc] init]; + while ((pair = [enumerator nextObject]) != nil) { + OFXMLElement *keyElement, *valueElement; + id key; + id object; + + keyElement = [pair elementForName: @"key" + namespace: OF_SERIALIZATION_NS]; + valueElement = [pair + elementForName: @"value" + namespace: OF_SERIALIZATION_NS]; + + if (keyElement == nil || valueElement == nil) + @throw [OFInvalidArgumentException + newWithClass: isa + selector: _cmd]; + + key = [OFSerialization objectByDeserializingXMLElement: + [keyElement elementForName: @"object" + namespace: OF_SERIALIZATION_NS]]; + object = [OFSerialization + objectByDeserializingXMLElement: + [valueElement elementForName: @"object" + namespace: OF_SERIALIZATION_NS]]; + + [dictionary setObject: object + forKey: key]; + + [pool2 releaseObjects]; + } + + self = [self initWithDictionary: dictionary]; + + [pool release]; } @catch (id e) { [self release]; @throw e; }