Index: src/OFArray.m ================================================================== --- src/OFArray.m +++ src/OFArray.m @@ -235,24 +235,25 @@ OFEnumerator *enumerator; OFXMLElement *child; pool = [[OFAutoreleasePool alloc] init]; - if (![[element name] isEqual: @"object"] || - ![[element namespace] isEqual: OF_SERIALIZATION_NS] || - ![[[element attributeForName: @"class"] stringValue] - isEqual: [self className]]) + if (![[element name] isEqual: [self className]] || + ![[element namespace] isEqual: OF_SERIALIZATION_NS]) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; - enumerator = [[element - elementsForName: @"object" - namespace: OF_SERIALIZATION_NS] objectEnumerator]; + enumerator = [[element children] objectEnumerator]; pool2 = [[OFAutoreleasePool alloc] init]; + while ((child = [enumerator nextObject]) != nil) { - id object = [child objectByDeserializing]; + id object; + if (![[child namespace] isEqual: OF_SERIALIZATION_NS]) + continue; + + object = [child objectByDeserializing]; [array addItem: &object]; [object retain]; [pool2 releaseObjects]; } @@ -502,28 +503,33 @@ return ret; } - (OFXMLElement*)XMLElementBySerializing { - OFAutoreleasePool *pool; + OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + OFAutoreleasePool *pool2; OFXMLElement *element; id *cArray = [array cArray]; size_t i, count = [array count]; - element = [OFXMLElement elementWithName: @"object" - namespace: OF_SERIALIZATION_NS]; + element = [[OFXMLElement alloc] initWithName: [self className] + namespace: OF_SERIALIZATION_NS]; - pool = [[OFAutoreleasePool alloc] init]; - [element addAttributeWithName: @"class" - stringValue: [self className]]; + pool2 = [[OFAutoreleasePool alloc] init]; for (i = 0; i < count; i++) { [element addChild: [cArray[i] XMLElementBySerializing]]; - [pool releaseObjects]; + + [pool2 releaseObjects]; } - [pool release]; + [element retain]; + @try { + [pool release]; + } @finally { + [element autorelease]; + } return element; } - (void)makeObjectsPerformSelector: (SEL)selector Index: src/OFDate.m ================================================================== --- src/OFDate.m +++ src/OFDate.m @@ -248,31 +248,27 @@ { self = [super init]; @try { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; - OFXMLElement *secondsElement, *microsecondsElement; + OFXMLAttribute *secondsAttribute, *microsecondsAttribute; - if (![[element name] isEqual: @"object"] || - ![[element namespace] isEqual: OF_SERIALIZATION_NS] || - ![[[element attributeForName: @"class"] stringValue] - isEqual: [self className]]) + if (![[element name] isEqual: [self className]] || + ![[element namespace] isEqual: OF_SERIALIZATION_NS]) + @throw [OFInvalidArgumentException newWithClass: isa + selector: _cmd]; + + secondsAttribute = [element attributeForName: @"seconds"]; + microsecondsAttribute = + [element attributeForName: @"microseconds"]; + + if (secondsAttribute == nil || microsecondsAttribute == nil) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; - secondsElement = [element elementForName: @"seconds" - namespace: OF_SERIALIZATION_NS]; - microsecondsElement = [element - elementForName: @"microseconds" - namespace: OF_SERIALIZATION_NS]; - - if (secondsElement == nil || microsecondsElement == nil) - @throw [OFInvalidArgumentException newWithClass: isa - selector: _cmd]; - - seconds = (int64_t)[secondsElement decimalValue]; - microseconds = (uint32_t)[microsecondsElement decimalValue]; + seconds = (int64_t)[secondsAttribute decimalValue]; + microseconds = (uint32_t)[microsecondsAttribute decimalValue]; [pool release]; } @catch (id e) { [self release]; @throw e; @@ -344,32 +340,32 @@ return [self dateStringWithFormat: @"%Y-%m-%dT%H:%M:%SZ"]; } - (OFXMLElement*)XMLElementBySerializing { - OFAutoreleasePool *pool; + OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFXMLElement *element; + OFString *secondsString, *microsecondsString; - element = [OFXMLElement elementWithName: @"object" + element = [OFXMLElement elementWithName: [self className] namespace: OF_SERIALIZATION_NS]; - pool = [[OFAutoreleasePool alloc] init]; - [element addAttributeWithName: @"class" - stringValue: [self className]]; - - [element addChild: - [OFXMLElement elementWithName: @"seconds" - namespace: OF_SERIALIZATION_NS - stringValue: [OFString stringWithFormat: - @"%" @PRId64, seconds]]]; - [element addChild: - [OFXMLElement elementWithName: @"microseconds" - namespace: OF_SERIALIZATION_NS - stringValue: [OFString stringWithFormat: - @"%" @PRIu32, microseconds]]]; - - [pool release]; + secondsString = [OFString stringWithFormat: @"%" @PRId64, seconds]; + microsecondsString = [OFString stringWithFormat: @"%" @PRId64, + microseconds]; + + [element addAttributeWithName: @"seconds" + stringValue: secondsString]; + [element addAttributeWithName: @"microseconds" + stringValue: microsecondsString]; + + [element retain]; + @try { + [pool release]; + } @finally { + [element autorelease]; + } return element; } - (uint32_t)microsecond Index: src/OFDictionary.m ================================================================== --- src/OFDictionary.m +++ src/OFDictionary.m @@ -25,10 +25,11 @@ #import "OFXMLElement.h" #import "OFAutoreleasePool.h" #import "OFEnumerationMutationException.h" #import "OFInvalidArgumentException.h" +#import "OFInvalidFormatException.h" #import "OFOutOfRangeException.h" #import "macros.h" struct of_dictionary_bucket of_dictionary_deleted_bucket = {}; @@ -476,57 +477,51 @@ } - initWithSerialization: (OFXMLElement*)element { @try { - OFAutoreleasePool *pool, *pool2; + OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + OFAutoreleasePool *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: [self className]]) + OFArray *keys, *objects; + OFEnumerator *keyEnumerator, *objectEnumerator; + OFXMLElement *keyElement, *objectElement; + + if (![[element name] isEqual: [self className]] || + ![[element namespace] isEqual: OF_SERIALIZATION_NS]) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; dictionary = [OFMutableDictionary dictionary]; - pairs = [element elementsForName: @"pair" - namespace: OF_SERIALIZATION_NS]; - enumerator = [pairs objectEnumerator]; + keys = [element elementsForName: @"key" + namespace: OF_SERIALIZATION_NS]; + objects = [element elementsForName: @"object" + namespace: OF_SERIALIZATION_NS]; + + if ([keys count] != [objects count]) + @throw [OFInvalidFormatException newWithClass: isa]; + + keyEnumerator = [keys objectEnumerator]; + objectEnumerator = [objects 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 = [[keyElement elementForName: @"object" - namespace: OF_SERIALIZATION_NS] - objectByDeserializing]; - object = [[valueElement - elementForName: @"object" - namespace: OF_SERIALIZATION_NS] - objectByDeserializing]; - - [dictionary setObject: object - forKey: key]; + + while ((keyElement = [keyEnumerator nextObject]) != nil && + (objectElement = [objectEnumerator nextObject]) != nil) { + OFXMLElement *key, *object; + + key = [[keyElement elementsForNamespace: + OF_SERIALIZATION_NS] firstObject]; + object = [[objectElement elementsForNamespace: + OF_SERIALIZATION_NS] firstObject]; + + if (key == nil || object == nil) + @throw [OFInvalidFormatException + newWithClass: isa]; + + [dictionary setObject: [object objectByDeserializing] + forKey: [key objectByDeserializing]]; [pool2 releaseObjects]; } self = [self initWithDictionary: dictionary]; @@ -824,51 +819,49 @@ return ret; } - (OFXMLElement*)XMLElementBySerializing { - OFAutoreleasePool *pool, *pool2; + OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + OFAutoreleasePool *pool2; OFXMLElement *element; OFEnumerator *keyEnumerator, *objectEnumerator; id key, object; - element = [OFXMLElement elementWithName: @"object" + element = [OFXMLElement elementWithName: [self className] namespace: OF_SERIALIZATION_NS]; - pool = [[OFAutoreleasePool alloc] init]; - [element addAttributeWithName: @"class" - stringValue: [self className]]; - keyEnumerator = [self keyEnumerator]; objectEnumerator = [self objectEnumerator]; - pool2 = [[OFAutoreleasePool alloc] init]; + while ((key = [keyEnumerator nextObject]) != nil && (object = [objectEnumerator nextObject]) != nil) { - OFXMLElement *pair, *keyElement, *valueElement; - - pair = [OFXMLElement elementWithName: @"pair" - namespace: OF_SERIALIZATION_NS]; + OFXMLElement *keyElement, *objectElement; keyElement = [OFXMLElement elementWithName: @"key" namespace: OF_SERIALIZATION_NS]; [keyElement addChild: [key XMLElementBySerializing]]; - [pair addChild: keyElement]; - valueElement = [OFXMLElement - elementWithName: @"value" + objectElement = [OFXMLElement + elementWithName: @"object" namespace: OF_SERIALIZATION_NS]; - [valueElement addChild: [object XMLElementBySerializing]]; - [pair addChild: valueElement]; + [objectElement addChild: [object XMLElementBySerializing]]; - [element addChild: pair]; + [element addChild: keyElement]; + [element addChild: objectElement]; [pool2 releaseObjects]; } - [pool release]; + [element retain]; + @try { + [pool release]; + } @finally { + [element autorelease]; + } return element; } @end Index: src/OFList.m ================================================================== --- src/OFList.m +++ src/OFList.m @@ -38,31 +38,28 @@ - initWithSerialization: (OFXMLElement*)element { self = [self init]; @try { - OFAutoreleasePool *pool, *pool2; + OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + OFAutoreleasePool *pool2; OFEnumerator *enumerator; OFXMLElement *child; - pool = [[OFAutoreleasePool alloc] init]; - - if (![[element name] isEqual: @"object"] || - ![[element namespace] isEqual: OF_SERIALIZATION_NS] || - ![[[element attributeForName: @"class"] stringValue] - isEqual: [self className]]) + if (![[element name] isEqual: [self className]] || + ![[element namespace] isEqual: OF_SERIALIZATION_NS]) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; - enumerator = [[element - elementsForName: @"object" - namespace: OF_SERIALIZATION_NS] objectEnumerator]; + enumerator = [[element children] objectEnumerator]; pool2 = [[OFAutoreleasePool alloc] init]; + while ((child = [enumerator nextObject]) != nil) { - id object = [child objectByDeserializing]; + if (![[child namespace] isEqual: OF_SERIALIZATION_NS]) + continue; - [self appendObject: object]; + [self appendObject: [child objectByDeserializing]]; [pool2 releaseObjects]; } [pool release]; @@ -365,27 +362,32 @@ return ret; } - (OFXMLElement*)XMLElementBySerializing { - OFAutoreleasePool *pool; + OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + OFAutoreleasePool *pool2; OFXMLElement *element; of_list_object_t *iter; - element = [OFXMLElement elementWithName: @"object" + element = [OFXMLElement elementWithName: [self className] namespace: OF_SERIALIZATION_NS]; - pool = [[OFAutoreleasePool alloc] init]; - [element addAttributeWithName: @"class" - stringValue: [self className]]; + pool2 = [[OFAutoreleasePool alloc] init]; for (iter = firstListObject; iter != NULL; iter = iter->next) { [element addChild: [iter->object XMLElementBySerializing]]; - [pool releaseObjects]; + + [pool2 releaseObjects]; } - [pool release]; + [element retain]; + @try { + [pool release]; + } @finally { + [element autorelease]; + } return element; } - (int)countByEnumeratingWithState: (of_fast_enumeration_state_t*)state Index: src/OFNull.m ================================================================== --- src/OFNull.m +++ src/OFNull.m @@ -43,14 +43,12 @@ [self release]; pool = [[OFAutoreleasePool alloc] init]; - if (![[element name] isEqual: @"object"] || - ![[element namespace] isEqual: OF_SERIALIZATION_NS] || - ![[[element attributeForName: @"class"] stringValue] - isEqual: [self className]]) + if (![[element name] isEqual: [self className]] || + ![[element namespace] isEqual: OF_SERIALIZATION_NS]) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; [pool release]; @@ -67,16 +65,22 @@ return self; } - (OFXMLElement*)XMLElementBySerializing { + OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFXMLElement *element; - element = [OFXMLElement elementWithName: @"object" + element = [OFXMLElement elementWithName: [self className] namespace: OF_SERIALIZATION_NS]; - [element addAttributeWithName: @"class" - stringValue: [self className]]; + + [element retain]; + @try { + [pool release]; + } @finally { + [element autorelease]; + } return element; } - autorelease Index: src/OFNumber.m ================================================================== --- src/OFNumber.m +++ src/OFNumber.m @@ -714,14 +714,12 @@ @try { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFString *typeString; - if (![[element name] isEqual: @"object"] || - ![[element namespace] isEqual: OF_SERIALIZATION_NS] || - ![[[element attributeForName: @"class"] stringValue] - isEqual: [self className]]) + if (![[element name] isEqual: [self className]] || + ![[element namespace] isEqual: OF_SERIALIZATION_NS]) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; typeString = [[element attributeForName: @"type"] stringValue]; @@ -1175,21 +1173,16 @@ } } - (OFXMLElement*)XMLElementBySerializing { - OFAutoreleasePool *pool; + OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFXMLElement *element; - element = [OFXMLElement elementWithName: @"object" - namespace: OF_SERIALIZATION_NS]; - - pool = [[OFAutoreleasePool alloc] init]; - - [element addAttributeWithName: @"class" - stringValue: [self className]]; - [element setStringValue: [self description]]; + element = [OFXMLElement elementWithName: [self className] + namespace: OF_SERIALIZATION_NS + stringValue: [self description]]; switch (type) { case OF_NUMBER_BOOL: [element addAttributeWithName: @"type" stringValue: @"boolean"]; @@ -1253,10 +1246,15 @@ break; default: @throw [OFInvalidFormatException newWithClass: isa]; } - [pool release]; + [element retain]; + @try { + [pool release]; + } @finally { + [element autorelease]; + } return element; } @end Index: src/OFObject+Serialization.m ================================================================== --- src/OFObject+Serialization.m +++ src/OFObject+Serialization.m @@ -43,20 +43,22 @@ pool = [[OFAutoreleasePool alloc] init]; element = [(id)self XMLElementBySerializing]; root = [OFXMLElement elementWithName: @"serialization" namespace: OF_SERIALIZATION_NS]; + [root addAttributeWithName: @"version" + stringValue: @"0"]; [root addChild: element]; ret = [@"\n" stringByAppendingString: [root XMLStringWithIndentation: 2]]; - [ret retain]; + [ret retain]; @try { [pool release]; - } @catch (id e) { - [ret release]; + } @finally { + [ret autorelease]; } - return [ret autorelease]; + return ret; } @end Index: src/OFString+Serialization.m ================================================================== --- src/OFString+Serialization.m +++ src/OFString+Serialization.m @@ -33,12 +33,11 @@ OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFXMLElement *root = [OFXMLElement elementWithXMLString: self]; OFArray *elements; id object; - elements = [root elementsForName: @"object" - namespace: OF_SERIALIZATION_NS]; + elements = [root elementsForNamespace: OF_SERIALIZATION_NS]; if ([elements count] != 1) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; Index: src/OFString.m ================================================================== --- src/OFString.m +++ src/OFString.m @@ -1079,14 +1079,12 @@ - initWithSerialization: (OFXMLElement*)element { @try { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; - if (![[element name] isEqual: @"object"] || - ![[element namespace] isEqual: OF_SERIALIZATION_NS] || - ![[[element attributeForName: @"class"] stringValue] - isEqual: [self className]]) + if (![[element name] isEqual: [self className]] || + ![[element namespace] isEqual: OF_SERIALIZATION_NS]) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; self = [self initWithString: [element stringValue]]; @@ -1271,27 +1269,29 @@ return [[self copy] autorelease]; } - (OFXMLElement*)XMLElementBySerializing { - OFAutoreleasePool *pool; + OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFXMLElement *element; + OFString *className; - element = [OFXMLElement elementWithName: @"object" + if ([self isKindOfClass: [OFConstantString class]]) + className = @"OFString"; + else + className = [self className]; + + element = [OFXMLElement elementWithName: className namespace: OF_SERIALIZATION_NS stringValue: self]; - pool = [[OFAutoreleasePool alloc] init]; - - if ([self isKindOfClass: [OFConstantString class]]) - [element addAttributeWithName: @"class" - stringValue: @"OFString"]; - else - [element addAttributeWithName: @"class" - stringValue: [self className]]; - - [pool release]; + [element retain]; + @try { + [pool release]; + } @finally { + [element autorelease]; + } return element; } - (of_unichar_t)characterAtIndex: (size_t)index Index: src/OFURL.m ================================================================== --- src/OFURL.m +++ src/OFURL.m @@ -287,14 +287,12 @@ - initWithSerialization: (OFXMLElement*)element { @try { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; - if (![[element name] isEqual: @"object"] || - ![[element namespace] isEqual: OF_SERIALIZATION_NS] || - ![[[element attributeForName: @"class"] stringValue] - isEqual: [self className]]) + if (![[element name] isEqual: [self className]] || + ![[element namespace] isEqual: OF_SERIALIZATION_NS]) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; self = [self initWithString: [element stringValue]]; @@ -548,22 +546,22 @@ return [self string]; } - (OFXMLElement*)XMLElementBySerializing { - OFAutoreleasePool *pool; + OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFXMLElement *element; - element = [OFXMLElement elementWithName: @"object" - namespace: OF_SERIALIZATION_NS]; - - pool = [[OFAutoreleasePool alloc] init]; - - [element addAttributeWithName: @"class" - stringValue: [self className]]; - [element setStringValue: [self string]]; - - [pool release]; + element = [OFXMLElement elementWithName: [self className] + namespace: OF_SERIALIZATION_NS + stringValue: [self string]]; + + [element retain]; + @try { + [pool release]; + } @finally { + [element autorelease]; + } return element; } @end Index: src/OFXMLAttribute.m ================================================================== --- src/OFXMLAttribute.m +++ src/OFXMLAttribute.m @@ -59,26 +59,21 @@ self = [super init]; @try { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; - if (![[element name] isEqual: @"object"] || - ![[element namespace] isEqual: OF_SERIALIZATION_NS] || - ![[[element attributeForName: @"class"] stringValue] - isEqual: [self className]]) + if (![[element name] isEqual: [self className]] || + ![[element namespace] isEqual: OF_SERIALIZATION_NS]) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; - name = [[[element - elementForName: @"name" - namespace: OF_SERIALIZATION_NS] stringValue] retain]; - ns = [[[element - elementForName: @"namespace" - namespace: OF_SERIALIZATION_NS] stringValue] retain]; - stringValue = [[[element - elementForName: @"stringValue" - namespace: OF_SERIALIZATION_NS] stringValue] retain]; + name = [[[element attributeForName: @"name"] stringValue] + copy]; + ns = [[[element attributeForName: @"namespace"] stringValue] + copy]; + stringValue = [[[element attributeForName: @"stringValue"] + stringValue] copy]; [pool release]; } @catch (id e) { [self release]; @throw e; @@ -165,35 +160,31 @@ return hash; } - (OFXMLElement*)XMLElementBySerializing { - OFAutoreleasePool *pool; + OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFXMLElement *element; - element = [OFXMLElement elementWithName: @"object" + element = [OFXMLElement elementWithName: [self className] namespace: OF_SERIALIZATION_NS]; - pool = [[OFAutoreleasePool alloc] init]; - - [element addAttributeWithName: @"class" - stringValue: [self className]]; - - [element addChild: - [OFXMLElement elementWithName: @"name" - namespace: OF_SERIALIZATION_NS - stringValue: name]]; + [element addAttributeWithName: @"name" + stringValue: name]; + if (ns != nil) - [element addChild: - [OFXMLElement elementWithName: @"namespace" - namespace: OF_SERIALIZATION_NS - stringValue: ns]]; - [element addChild: - [OFXMLElement elementWithName: @"stringValue" - namespace: OF_SERIALIZATION_NS - stringValue: stringValue]]; - - [pool release]; + [element addAttributeWithName: @"namespace" + stringValue: ns]; + + [element addAttributeWithName: @"stringValue" + stringValue: stringValue]; + + [element retain]; + @try { + [pool release]; + } @finally { + [element autorelease]; + } return element; } @end Index: src/OFXMLElement+Serialization.m ================================================================== --- src/OFXMLElement+Serialization.m +++ src/OFXMLElement+Serialization.m @@ -39,23 +39,16 @@ @implementation OFXMLElement (Serialization) - (id)objectByDeserializing { OFAutoreleasePool *pool; - OFString *className; Class class; id object; pool = [[OFAutoreleasePool alloc] init]; - className = [[self attributeForName: @"class"] stringValue]; - if (className == nil) - @throw [OFNotImplementedException - newWithClass: nil - selector: @selector(initWithSerialization:)]; - - class = objc_lookUpClass([className cString]); - if (class == Nil) + + if ((class = objc_lookUpClass([name cString])) == Nil) @throw [OFNotImplementedException newWithClass: Nil]; if (![class conformsToProtocol: @protocol(OFSerialization)]) @throw [OFNotImplementedException newWithClass: class @@ -63,13 +56,12 @@ object = [[class alloc] initWithSerialization: self]; @try { [pool release]; - } @catch (id e) { - [object release]; - @throw e; + } @finally { + [object autorelease]; } - return [object autorelease]; + return object; } @end Index: src/OFXMLElement.m ================================================================== --- src/OFXMLElement.m +++ src/OFXMLElement.m @@ -27,10 +27,11 @@ #import "OFXMLParser.h" #import "OFXMLElementBuilder.h" #import "OFAutoreleasePool.h" #import "OFInvalidArgumentException.h" +#import "OFInvalidFormatException.h" #import "OFMalformedXMLException.h" #import "OFNotImplementedException.h" #import "OFUnboundNamespaceException.h" #import "macros.h" @@ -290,26 +291,20 @@ @try { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFXMLElement *attributesElement, *namespacesElement; OFXMLElement *childrenElement; - if (![[element name] isEqual: @"object"] || - ![[element namespace] isEqual: OF_SERIALIZATION_NS] || - ![[[element attributeForName: @"class"] stringValue] - isEqual: [self className]]) + if (![[element name] isEqual: [self className]] || + ![[element namespace] isEqual: OF_SERIALIZATION_NS]) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; - name = [[[element - elementForName: @"name" - namespace: OF_SERIALIZATION_NS] stringValue] copy]; - ns = [[[element - elementForName: @"namespace" - namespace: OF_SERIALIZATION_NS] stringValue] copy]; - defaultNamespace = [[[element - elementForName: @"defaultNamespace" - namespace: OF_SERIALIZATION_NS] stringValue] copy]; + name = [[[element attributeForName: @"name"] stringValue] copy]; + ns = [[[element attributeForName: @"namespace"] stringValue] + copy]; + defaultNamespace = [[[element attributeForName: + @"defaultNamespace"] stringValue] copy]; characters = [[[element elementForName: @"characters" namespace: OF_SERIALIZATION_NS] stringValue] copy]; CDATA = [[[element elementForName: @"CDATA" @@ -316,31 +311,26 @@ namespace: OF_SERIALIZATION_NS] stringValue] copy]; comment = [[[element elementForName: @"comment" namespace: OF_SERIALIZATION_NS] stringValue] copy]; - attributesElement = [element + attributesElement = [[[element elementForName: @"attributes" - namespace: OF_SERIALIZATION_NS]; - namespacesElement = [element + namespace: OF_SERIALIZATION_NS] elementsForNamespace: + OF_SERIALIZATION_NS] firstObject]; + namespacesElement = [[[element elementForName: @"namespaces" - namespace: OF_SERIALIZATION_NS]; - childrenElement = [element elementForName: @"children" - namespace: OF_SERIALIZATION_NS]; - - attributes = [[[attributesElement - elementForName: @"object" - namespace: OF_SERIALIZATION_NS] objectByDeserializing] - retain]; - namespaces = [[[namespacesElement - elementForName: @"object" - namespace: OF_SERIALIZATION_NS] objectByDeserializing] - retain]; - children = [[[childrenElement - elementForName: @"object" - namespace: OF_SERIALIZATION_NS] objectByDeserializing] - retain]; + namespace: OF_SERIALIZATION_NS] elementsForNamespace: + OF_SERIALIZATION_NS] firstObject]; + childrenElement = [[[element + elementForName: @"children" + namespace: OF_SERIALIZATION_NS] elementsForNamespace: + OF_SERIALIZATION_NS] firstObject]; + + attributes = [[attributesElement objectByDeserializing] copy]; + namespaces = [[namespacesElement objectByDeserializing] copy]; + children = [[childrenElement objectByDeserializing] copy]; if (!((name != nil || ns != nil || defaultNamespace != nil || [attributes count] > 0 || [namespaces count] > 0 || [children count] > 0) ^ (characters != nil) ^ (CDATA != nil) ^ (comment != nil))) @@ -736,38 +726,27 @@ return [self XMLStringWithIndentation: 2]; } - (OFXMLElement*)XMLElementBySerializing { - OFAutoreleasePool *pool; + OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFXMLElement *element; - element = [OFXMLElement elementWithName: @"object" + element = [OFXMLElement elementWithName: [self className] namespace: OF_SERIALIZATION_NS]; - pool = [[OFAutoreleasePool alloc] init]; - - [element addAttributeWithName: @"class" - stringValue: [self className]]; - if (name != nil) - [element addChild: - [OFXMLElement elementWithName: @"name" - namespace: OF_SERIALIZATION_NS - stringValue: name]]; + [element addAttributeWithName: @"name" + stringValue: name]; if (ns != nil) - [element addChild: - [OFXMLElement elementWithName: @"namespace" - namespace: OF_SERIALIZATION_NS - stringValue: ns]]; + [element addAttributeWithName: @"namespace" + stringValue: ns]; if (defaultNamespace != nil) - [element addChild: - [OFXMLElement elementWithName: @"defaultNamespace" - namespace: OF_SERIALIZATION_NS - stringValue: defaultNamespace]]; + [element addAttributeWithName: @"defaultNamespace" + stringValue: defaultNamespace]; if (attributes != nil) { OFXMLElement *attributesElement; attributesElement = @@ -803,23 +782,30 @@ [element addChild: [OFXMLElement elementWithName: @"characters" namespace: OF_SERIALIZATION_NS stringValue: characters]]; - if (CDATA != nil) - [element addChild: + if (CDATA != nil) { + OFXMLElement *CDATAElement = [OFXMLElement elementWithName: @"CDATA" - namespace: OF_SERIALIZATION_NS - stringValue: CDATA]]; + namespace: OF_SERIALIZATION_NS]; + [CDATAElement addChild: [OFXMLElement elementWithCDATA: CDATA]]; + [element addChild: CDATAElement]; + } if (comment != nil) [element addChild: [OFXMLElement elementWithName: @"comment" namespace: OF_SERIALIZATION_NS stringValue: comment]]; - [pool release]; + [element retain]; + @try { + [pool release]; + } @finally { + [element autorelease]; + } return element; } - (void)addAttribute: (OFXMLAttribute*)attribute Index: tests/OFSerializationTests.m ================================================================== --- tests/OFSerializationTests.m +++ tests/OFSerializationTests.m @@ -52,11 +52,12 @@ forKey: @"Blub"]; [l appendObject: @"Hello"]; [l appendObject: @"Wo\rld!\nHow are you?"]; [l appendObject: [OFURL URLWithString: @"https://webkeks.org/"]]; - [l appendObject: [OFXMLElement elementWithXMLString: @""]]; + [l appendObject: + [OFXMLElement elementWithXMLString: @""]]; [d setObject: @"list" forKey: l]; TEST(@"-[stringBySerializing]", Index: tests/serialization.xml ================================================================== --- tests/serialization.xml +++ tests/serialization.xml @@ -1,93 +1,77 @@ - - - - - - Qu"xbar -test - 1234 - asd - - 1234 - 5678 - - - - - Hello - - - - - Blub - - - B"la - - - - - - Hello - Wo ld! -How are you? - https://webkeks.org/ - - x - - - - - http://www.w3.org/2000/xmlns/ - - - xmlns - - - - - http://www.w3.org/XML/1998/namespace - - - xml - - - - - - - - y - - - - - http://www.w3.org/2000/xmlns/ - - - xmlns - - - - - http://www.w3.org/XML/1998/namespace - - - xml - - - - - - - - - - - - list - - - + + + + + Qu"xbar +test + 1234 + asd + + + + + Hello + + + + Hello + Wo ld! +How are you? + https://webkeks.org/ + + + + + http://www.w3.org/2000/xmlns/ + + + xmlns + + + http://www.w3.org/XML/1998/namespace + + + xml + + + + + + + + + + http://www.w3.org/2000/xmlns/ + + + xmlns + + + http://www.w3.org/XML/1998/namespace + + + xml + + + + + + + + + + + + + + list + + + Blub + + + B"la + +