@@ -22,25 +22,56 @@ #import "OFString.h" #import "OFXMLElement.h" #import "OFAutoreleasePool.h" #import "OFEnumerationMutationException.h" +#import "OFInvalidArgumentException.h" #import "macros.h" @implementation OFList + list { return [[[self alloc] init] autorelease]; } -- init +- initWithSerialization: (OFXMLElement*)element { - self = [super init]; + self = [self init]; - firstListObject = NULL; - lastListObject = NULL; + @try { + OFAutoreleasePool *pool, *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: [isa className]]) + @throw [OFInvalidArgumentException newWithClass: isa + selector: _cmd]; + + enumerator = [[element + elementsForName: @"object" + namespace: OF_SERIALIZATION_NS] objectEnumerator]; + pool2 = [[OFAutoreleasePool alloc] init]; + while ((child = [enumerator nextObject]) != nil) { + id object = [OFSerialization + objectByDeserializingXMLElement: child]; + + [self appendObject: object]; + + [pool2 releaseObjects]; + } + + [pool release]; + } @catch (id e) { + [self release]; + @throw e; + } return self; } - (void)dealloc @@ -175,22 +206,16 @@ [self freeMemory: listObject]; } - (id)firstObject { - if (firstListObject != NULL) - return firstListObject->object; - - return nil; + return (firstListObject != NULL ? firstListObject->object : nil); } - (id)lastObject { - if (lastListObject != NULL) - return lastListObject->object; - - return nil; + return (lastListObject != NULL ? lastListObject->object : nil); } - (size_t)count { return count;