@@ -36,17 +36,10 @@ #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFMalformedXMLException.h" #import "OFUnboundNamespaceException.h" -/* References for static linking */ -void -_references_to_categories_of_OFXMLElement(void) -{ - _OFXMLElement_Serialization_reference = 1; -} - @interface OFXMLElementElementBuilderDelegate: OFObject { @public OFXMLElement *_element; @@ -265,108 +258,10 @@ [_namespaces release]; _namespaces = [element->_namespaces retain]; [_children release]; _children = [element->_children retain]; - objc_autoreleasePoolPop(pool); - } @catch (id e) { - [self release]; - @throw e; - } - - return self; -} - -- (instancetype)initWithSerialization: (OFXMLElement *)element -{ - void *pool; - OFString *name, *namespace; - - @try { - pool = objc_autoreleasePoolPush(); - - if (![element.name isEqual: self.className] || - ![element.namespace isEqual: OFSerializationNS]) - @throw [OFInvalidArgumentException exception]; - - name = [element attributeForName: @"name"].stringValue; - namespace = - [element attributeForName: @"namespace"].stringValue; - } @catch (id e) { - [self release]; - @throw e; - } - - self = [self initWithName: name namespace: namespace]; - - @try { - OFXMLElement *attributesElement, *namespacesElement; - OFXMLElement *childrenElement; - OFEnumerator *keyEnumerator, *objectEnumerator; - OFString *key, *object; - - attributesElement = [[element - elementForName: @"attributes" - namespace: OFSerializationNS] - elementsForNamespace: OFSerializationNS].firstObject; - namespacesElement = [[element - elementForName: @"namespaces" - namespace: OFSerializationNS] - elementsForNamespace: OFSerializationNS].firstObject; - childrenElement = [[element - elementForName: @"children" - namespace: OFSerializationNS] - elementsForNamespace: OFSerializationNS].firstObject; - - [_attributes release]; - _attributes = nil; - _attributes = [attributesElement.objectByDeserializing - mutableCopy]; - - [_namespaces release]; - _namespaces = nil; - _namespaces = [namespacesElement.objectByDeserializing - mutableCopy]; - - [_children release]; - _children = nil; - _children = [childrenElement.objectByDeserializing - mutableCopy]; - - /* Sanity checks */ - if ((_attributes != nil && ![_attributes isKindOfClass: - [OFMutableArray class]]) || (_namespaces != nil && - ![_namespaces isKindOfClass: - [OFMutableDictionary class]]) || (_children != nil && - ![_children isKindOfClass: [OFMutableArray class]])) - @throw [OFInvalidArgumentException exception]; - - for (OFXMLAttribute *attribute in _attributes) - if (![attribute isKindOfClass: [OFXMLAttribute class]]) - @throw [OFInvalidArgumentException exception]; - - keyEnumerator = [_namespaces keyEnumerator]; - objectEnumerator = [_namespaces objectEnumerator]; - while ((key = [keyEnumerator nextObject]) != nil && - (object = [objectEnumerator nextObject]) != nil) - if (![key isKindOfClass: [OFString class]] || - ![object isKindOfClass: [OFString class]]) - @throw [OFInvalidArgumentException exception]; - - for (object in _children) - if (![object isKindOfClass: [OFXMLNode class]]) - @throw [OFInvalidArgumentException exception]; - - if (_namespaces == nil) - _namespaces = [[OFMutableDictionary alloc] init]; - - [_namespaces - setObject: @"xml" - forKey: @"http://www.w3.org/XML/1998/namespace"]; - [_namespaces setObject: @"xmlns" - forKey: @"http://www.w3.org/2000/xmlns/"]; - objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } @@ -666,73 +561,10 @@ namespaces: nil indentation: indentation level: 0]; } -- (OFXMLElement *)XMLElementBySerializing -{ - void *pool = objc_autoreleasePoolPush(); - OFXMLElement *element; - - element = [OFXMLElement elementWithName: self.className - namespace: OFSerializationNS]; - - if (_name != nil) - [element addAttributeWithName: @"name" stringValue: _name]; - - if (_namespace != nil) - [element addAttributeWithName: @"namespace" - stringValue: _namespace]; - - if (_attributes != nil) { - OFXMLElement *attributesElement; - - attributesElement = - [OFXMLElement elementWithName: @"attributes" - namespace: OFSerializationNS]; - [attributesElement addChild: - _attributes.XMLElementBySerializing]; - [element addChild: attributesElement]; - } - - if (_namespaces != nil) { - OFXMLElement *namespacesElement; - OFMutableDictionary *namespacesCopy = - [[_namespaces mutableCopy] autorelease]; - - [namespacesCopy removeObjectForKey: - @"http://www.w3.org/XML/1998/namespace"]; - [namespacesCopy removeObjectForKey: - @"http://www.w3.org/2000/xmlns/"]; - - if (namespacesCopy.count > 0) { - namespacesElement = - [OFXMLElement elementWithName: @"namespaces" - namespace: OFSerializationNS]; - [namespacesElement addChild: - namespacesCopy.XMLElementBySerializing]; - [element addChild: namespacesElement]; - } - } - - if (_children != nil) { - OFXMLElement *childrenElement; - - childrenElement = - [OFXMLElement elementWithName: @"children" - namespace: OFSerializationNS]; - [childrenElement addChild: _children.XMLElementBySerializing]; - [element addChild: childrenElement]; - } - - [element retain]; - - objc_autoreleasePoolPop(pool); - - return [element autorelease]; -} - - (void)addAttribute: (OFXMLAttribute *)attribute { if (![attribute isKindOfClass: [OFXMLAttribute class]]) @throw [OFInvalidArgumentException exception];