Index: ObjFW.xcodeproj/project.pbxproj ================================================================== --- ObjFW.xcodeproj/project.pbxproj +++ ObjFW.xcodeproj/project.pbxproj @@ -232,11 +232,16 @@ 4B90B7A4133AD87D00BD33CB /* OFConnectionFailedException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B90B79A133AD87D00BD33CB /* OFConnectionFailedException.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B90B7A5133AD87D00BD33CB /* OFConnectionFailedException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B90B79B133AD87D00BD33CB /* OFConnectionFailedException.m */; }; 4B90B7A6133AD87D00BD33CB /* OFListenFailedException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B90B79C133AD87D00BD33CB /* OFListenFailedException.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B90B7A7133AD87D00BD33CB /* OFListenFailedException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B90B79D133AD87D00BD33CB /* OFListenFailedException.m */; }; 4B989C2F13771A3700109A30 /* OFSerialization.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B989C2E13771A3700109A30 /* OFSerialization.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 4BC5E7D6137F0D0E0076F962 /* OFSerialization.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BC5E7D5137F0D0E0076F962 /* OFSerialization.m */; }; + 4BB25E88139C388A00F574EA /* OFObject+Serialization.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BB25E82139C388A00F574EA /* OFObject+Serialization.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 4BB25E89139C388A00F574EA /* OFObject+Serialization.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BB25E83139C388A00F574EA /* OFObject+Serialization.m */; }; + 4BB25E8A139C388A00F574EA /* OFString+Serialization.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BB25E84139C388A00F574EA /* OFString+Serialization.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 4BB25E8B139C388A00F574EA /* OFString+Serialization.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BB25E85139C388A00F574EA /* OFString+Serialization.m */; }; + 4BB25E8C139C388A00F574EA /* OFXMLElement+Serialization.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BB25E86139C388A00F574EA /* OFXMLElement+Serialization.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 4BB25E8D139C388A00F574EA /* OFXMLElement+Serialization.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BB25E87139C388A00F574EA /* OFXMLElement+Serialization.m */; }; 4BD98C03133814220048DD5B /* objfw-defs.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BD98C011338140B0048DD5B /* objfw-defs.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4BDF37B51338055600F9A81A /* config.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BDF37B41338055600F9A81A /* config.h */; }; 4BF33AFB133807590059CEF7 /* ObjFW.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4B3D23761337FBC800DD29B8 /* ObjFW.framework */; }; 4BF33AFC133807A20059CEF7 /* OFArrayTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B6EF66E1235358D0076B512 /* OFArrayTests.m */; }; 4BF33AFD133807A20059CEF7 /* OFBlockTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BE5F0E412DF4259005C7A0C /* OFBlockTests.m */; }; @@ -525,15 +530,20 @@ 4BAF5F46123460C900F4E111 /* OFCollection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFCollection.h; path = src/OFCollection.h; sourceTree = ""; }; 4BAF5F47123460C900F4E111 /* OFStreamObserver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFStreamObserver.h; path = src/OFStreamObserver.h; sourceTree = ""; }; 4BAF5F48123460C900F4E111 /* OFStreamObserver.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFStreamObserver.m; path = src/OFStreamObserver.m; sourceTree = ""; }; 4BAF5F49123460C900F4E111 /* OFStreamSocket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFStreamSocket.h; path = src/OFStreamSocket.h; sourceTree = ""; }; 4BAF5F4A123460C900F4E111 /* OFStreamSocket.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFStreamSocket.m; path = src/OFStreamSocket.m; sourceTree = ""; }; + 4BB25E82139C388A00F574EA /* OFObject+Serialization.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "OFObject+Serialization.h"; path = "src/OFObject+Serialization.h"; sourceTree = ""; }; + 4BB25E83139C388A00F574EA /* OFObject+Serialization.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "OFObject+Serialization.m"; path = "src/OFObject+Serialization.m"; sourceTree = ""; }; + 4BB25E84139C388A00F574EA /* OFString+Serialization.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "OFString+Serialization.h"; path = "src/OFString+Serialization.h"; sourceTree = ""; }; + 4BB25E85139C388A00F574EA /* OFString+Serialization.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "OFString+Serialization.m"; path = "src/OFString+Serialization.m"; sourceTree = ""; }; + 4BB25E86139C388A00F574EA /* OFXMLElement+Serialization.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "OFXMLElement+Serialization.h"; path = "src/OFXMLElement+Serialization.h"; sourceTree = ""; }; + 4BB25E87139C388A00F574EA /* OFXMLElement+Serialization.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "OFXMLElement+Serialization.m"; path = "src/OFXMLElement+Serialization.m"; sourceTree = ""; }; 4BB50DCF12F863C700C9393F /* of_asprintf.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = of_asprintf.h; path = src/of_asprintf.h; sourceTree = SOURCE_ROOT; }; 4BB50DD012F863C700C9393F /* of_asprintf.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = of_asprintf.m; path = src/of_asprintf.m; sourceTree = SOURCE_ROOT; }; 4BBA36C411406AB700CBA3AC /* atomic.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = atomic.h; path = src/atomic.h; sourceTree = ""; }; 4BBA36C511406AB700CBA3AC /* macros.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = macros.h; path = src/macros.h; sourceTree = ""; }; - 4BC5E7D5137F0D0E0076F962 /* OFSerialization.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFSerialization.m; path = src/OFSerialization.m; sourceTree = ""; }; 4BD86D801237A6C600ED9912 /* OFBlock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFBlock.h; path = src/OFBlock.h; sourceTree = SOURCE_ROOT; }; 4BD86D811237A6C600ED9912 /* OFBlock.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFBlock.m; path = src/OFBlock.m; sourceTree = SOURCE_ROOT; }; 4BD98C011338140B0048DD5B /* objfw-defs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "objfw-defs.h"; path = "src/objfw-defs.h"; sourceTree = SOURCE_ROOT; }; 4BDF37B41338055600F9A81A /* config.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = config.h; sourceTree = SOURCE_ROOT; }; 4BE17AD812FD744C002CEB0B /* foundation-compat.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "foundation-compat.m"; path = "src/foundation-compat.m"; sourceTree = SOURCE_ROOT; }; @@ -794,16 +804,17 @@ 4B511B7B139C0A34003764A5 /* OFNull.m */, 4B6799751099E7C50041064A /* OFNumber.h */, 4B6799761099E7C50041064A /* OFNumber.m */, 4B6799771099E7C50041064A /* OFObject.h */, 4B6799781099E7C50041064A /* OFObject.m */, + 4BB25E82139C388A00F574EA /* OFObject+Serialization.h */, + 4BB25E83139C388A00F574EA /* OFObject+Serialization.m */, 4B6799791099E7C50041064A /* OFPlugin.h */, 4B67997A1099E7C50041064A /* OFPlugin.m */, 4B981CDE116F71DD00294DB7 /* OFSeekableStream.h */, 4B981CDF116F71DD00294DB7 /* OFSeekableStream.m */, 4B989C2E13771A3700109A30 /* OFSerialization.h */, - 4BC5E7D5137F0D0E0076F962 /* OFSerialization.m */, 4BF1BCC411C9663F0025511F /* OFSHA1Hash.h */, 4BF1BCC511C9663F0025511F /* OFSHA1Hash.m */, 4B67997D1099E7C50041064A /* OFStream.h */, 4B67997E1099E7C50041064A /* OFStream.m */, 4BAF5F47123460C900F4E111 /* OFStreamObserver.h */, @@ -812,10 +823,12 @@ 4BAF5F4A123460C900F4E111 /* OFStreamSocket.m */, 4B67997F1099E7C50041064A /* OFString.h */, 4B6799801099E7C50041064A /* OFString.m */, 4BF1BCC611C9663F0025511F /* OFString+Hashing.h */, 4BF1BCC711C9663F0025511F /* OFString+Hashing.m */, + 4BB25E84139C388A00F574EA /* OFString+Serialization.h */, + 4BB25E85139C388A00F574EA /* OFString+Serialization.m */, 4BF1BCC811C9663F0025511F /* OFString+URLEncoding.h */, 4BF1BCC911C9663F0025511F /* OFString+URLEncoding.m */, 4BF1BCCA11C9663F0025511F /* OFString+XMLEscaping.h */, 4BF1BCCB11C9663F0025511F /* OFString+XMLEscaping.m */, 4BF1BCCC11C9663F0025511F /* OFString+XMLUnescaping.h */, @@ -828,10 +841,12 @@ 4B4A61F312DF5EA20048F3F2 /* OFURL.m */, 4BF1BCCE11C9663F0025511F /* OFXMLAttribute.h */, 4BF1BCCF11C9663F0025511F /* OFXMLAttribute.m */, 4B6799871099E7C50041064A /* OFXMLElement.h */, 4B6799881099E7C50041064A /* OFXMLElement.m */, + 4BB25E86139C388A00F574EA /* OFXMLElement+Serialization.h */, + 4BB25E87139C388A00F574EA /* OFXMLElement+Serialization.m */, 4B0D249411DFAA3D00ED6FFC /* OFXMLElementBuilder.h */, 4B0D249511DFAA3D00ED6FFC /* OFXMLElementBuilder.m */, 4B6799891099E7C50041064A /* OFXMLParser.h */, 4B67998A1099E7C50041064A /* OFXMLParser.m */, 4B6AF97310A8D4450003FB0A /* ObjFW.h */, @@ -959,27 +974,30 @@ 4B3D23CE1337FCB000DD29B8 /* OFMutableDictionary.h in Headers */, 4B3D23CF1337FCB000DD29B8 /* OFMutableString.h in Headers */, 4B511B7C139C0A34003764A5 /* OFNull.h in Headers */, 4B3D23D01337FCB000DD29B8 /* OFNumber.h in Headers */, 4B3D23D11337FCB000DD29B8 /* OFObject.h in Headers */, + 4BB25E88139C388A00F574EA /* OFObject+Serialization.h in Headers */, 4B3D23D21337FCB000DD29B8 /* OFPlugin.h in Headers */, 4B3D23D31337FCB000DD29B8 /* OFSeekableStream.h in Headers */, 4B989C2F13771A3700109A30 /* OFSerialization.h in Headers */, 4B3D23D41337FCB000DD29B8 /* OFSHA1Hash.h in Headers */, 4B3D23D51337FCB000DD29B8 /* OFStream.h in Headers */, 4B3D23D61337FCB000DD29B8 /* OFStreamObserver.h in Headers */, 4B3D23D71337FCB000DD29B8 /* OFStreamSocket.h in Headers */, 4B3D23D81337FCB000DD29B8 /* OFString.h in Headers */, 4B3D23D91337FCB000DD29B8 /* OFString+Hashing.h in Headers */, + 4BB25E8A139C388A00F574EA /* OFString+Serialization.h in Headers */, 4B3D23DA1337FCB000DD29B8 /* OFString+URLEncoding.h in Headers */, 4B3D23DB1337FCB000DD29B8 /* OFString+XMLEscaping.h in Headers */, 4B3D23DC1337FCB000DD29B8 /* OFString+XMLUnescaping.h in Headers */, 4B3D23DD1337FCB000DD29B8 /* OFTCPSocket.h in Headers */, 4B3D23DE1337FCB000DD29B8 /* OFThread.h in Headers */, 4B3D23DF1337FCB000DD29B8 /* OFURL.h in Headers */, 4B3D23E01337FCB000DD29B8 /* OFXMLAttribute.h in Headers */, 4B3D23E11337FCB000DD29B8 /* OFXMLElement.h in Headers */, + 4BB25E8C139C388A00F574EA /* OFXMLElement+Serialization.h in Headers */, 4B3D23E21337FCB000DD29B8 /* OFXMLElementBuilder.h in Headers */, 4B3D23E31337FCB000DD29B8 /* OFXMLParser.h in Headers */, 4B3D23E41337FCB000DD29B8 /* ObjFW.h in Headers */, 4B3D23E51337FCB000DD29B8 /* asprintf.h in Headers */, 4B3D23E61337FCB000DD29B8 /* atomic.h in Headers */, @@ -1204,28 +1222,32 @@ 4B3D23991337FC0D00DD29B8 /* OFList.m in Sources */, 4B3D239A1337FC0D00DD29B8 /* OFMD5Hash.m in Sources */, 4B3D239B1337FC0D00DD29B8 /* OFMutableArray.m in Sources */, 4B3D239C1337FC0D00DD29B8 /* OFMutableDictionary.m in Sources */, 4B3D239D1337FC0D00DD29B8 /* OFMutableString.m in Sources */, + 4B511B7D139C0A34003764A5 /* OFNull.m in Sources */, 4B3D239E1337FC0D00DD29B8 /* OFNumber.m in Sources */, 4B3D239F1337FC0D00DD29B8 /* OFObject.m in Sources */, + 4BB25E89139C388A00F574EA /* OFObject+Serialization.m in Sources */, 4B3D23A01337FC0D00DD29B8 /* OFPlugin.m in Sources */, 4B3D23A11337FC0D00DD29B8 /* OFSeekableStream.m in Sources */, 4B3D23A21337FC0D00DD29B8 /* OFSHA1Hash.m in Sources */, 4B3D23A31337FC0D00DD29B8 /* OFStream.m in Sources */, 4B3D23A41337FC0D00DD29B8 /* OFStreamObserver.m in Sources */, 4B3D23A51337FC0D00DD29B8 /* OFStreamSocket.m in Sources */, 4B3D23A61337FC0D00DD29B8 /* OFString.m in Sources */, 4B3D23A71337FC0D00DD29B8 /* OFString+Hashing.m in Sources */, + 4BB25E8B139C388A00F574EA /* OFString+Serialization.m in Sources */, 4B3D23A81337FC0D00DD29B8 /* OFString+URLEncoding.m in Sources */, 4B3D23A91337FC0D00DD29B8 /* OFString+XMLEscaping.m in Sources */, 4B3D23AA1337FC0D00DD29B8 /* OFString+XMLUnescaping.m in Sources */, 4B3D23AB1337FC0D00DD29B8 /* OFTCPSocket.m in Sources */, 4B3D23AC1337FC0D00DD29B8 /* OFThread.m in Sources */, 4B3D23AD1337FC0D00DD29B8 /* OFURL.m in Sources */, 4B3D23AE1337FC0D00DD29B8 /* OFXMLAttribute.m in Sources */, 4B3D23AF1337FC0D00DD29B8 /* OFXMLElement.m in Sources */, + 4BB25E8D139C388A00F574EA /* OFXMLElement+Serialization.m in Sources */, 4B3D23B01337FC0D00DD29B8 /* OFXMLElementBuilder.m in Sources */, 4B3D23B11337FC0D00DD29B8 /* OFXMLParser.m in Sources */, 4B3D23B31337FC0D00DD29B8 /* base64.m in Sources */, 4B3D23B41337FC0D00DD29B8 /* iso_8859_15.m in Sources */, 4B3D23B51337FC0D00DD29B8 /* foundation-compat.m in Sources */, @@ -1281,12 +1303,10 @@ 4B55A104133ABEA900B58A93 /* OFThreadStillRunningException.m in Sources */, 4B17FFAA133A34E7003E6DCD /* OFTruncatedDataException.m in Sources */, 4B17FFB6133A375B003E6DCD /* OFUnboundNamespaceException.m in Sources */, 4B17FFB2133A3664003E6DCD /* OFUnsupportedProtocolException.m in Sources */, 4B55A117133AC24600B58A93 /* OFWriteFailedException.m in Sources */, - 4BC5E7D6137F0D0E0076F962 /* OFSerialization.m in Sources */, - 4B511B7D139C0A34003764A5 /* OFNull.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; 4BF33AEC133807310059CEF7 /* Sources */ = { isa = PBXSourcesBuildPhase; Index: src/Makefile ================================================================== --- src/Makefile +++ src/Makefile @@ -5,56 +5,59 @@ LIB = ${OBJFW_SHARED_LIB} LIB_MAJOR = ${OBJFW_LIB_MAJOR} LIB_MINOR = ${OBJFW_LIB_MINOR} STATIC_LIB = ${OBJFW_STATIC_LIB} -SRCS = OFApplication.m \ - OFArray.m \ - OFAutoreleasePool.m \ - OFBlock.m \ - OFConstantString.m \ - OFDataArray.m \ - OFDataArray+Hashing.m \ - OFDate.m \ - OFDictionary.m \ - OFFile.m \ - OFHash.m \ - OFHTTPRequest.m \ - OFEnumerator.m \ - OFList.m \ - OFMD5Hash.m \ - OFMutableArray.m \ - OFMutableDictionary.m \ - OFMutableString.m \ - OFNull.m \ - OFNumber.m \ - OFObject.m \ - ${OFPLUGIN_M} \ - OFSeekableStream.m \ - OFSerialization.m \ - OFSHA1Hash.m \ - OFStream.m \ - OFStreamObserver.m \ - OFStreamSocket.m \ - OFString.m \ - OFString+Hashing.m \ - OFString+URLEncoding.m \ - OFString+XMLEscaping.m \ - OFString+XMLUnescaping.m \ - OFTCPSocket.m \ - ${OFTHREAD_M} \ - OFURL.m \ - OFXMLAttribute.m \ - OFXMLElement.m \ - OFXMLElementBuilder.m \ - OFXMLParser.m \ - base64.m \ - of_asprintf.m \ +SRCS = OFApplication.m \ + OFArray.m \ + OFAutoreleasePool.m \ + OFBlock.m \ + OFConstantString.m \ + OFDataArray.m \ + OFDataArray+Hashing.m \ + OFDate.m \ + OFDictionary.m \ + OFFile.m \ + OFHash.m \ + OFHTTPRequest.m \ + OFEnumerator.m \ + OFList.m \ + OFMD5Hash.m \ + OFMutableArray.m \ + OFMutableDictionary.m \ + OFMutableString.m \ + OFNull.m \ + OFNumber.m \ + OFObject.m \ + OFObject+Serialization.m \ + ${OFPLUGIN_M} \ + OFSeekableStream.m \ + OFSHA1Hash.m \ + OFStream.m \ + OFStreamObserver.m \ + OFStreamSocket.m \ + OFString.m \ + OFString+Hashing.m \ + OFString+Serialization.m \ + OFString+URLEncoding.m \ + OFString+XMLEscaping.m \ + OFString+XMLUnescaping.m \ + OFTCPSocket.m \ + ${OFTHREAD_M} \ + OFURL.m \ + OFXMLAttribute.m \ + OFXMLElement.m \ + OFXMLElement+Serialization.m \ + OFXMLElementBuilder.m \ + OFXMLParser.m \ + base64.m \ + of_asprintf.m \ unicode.m INCLUDES := ${SRCS:.m=.h} \ OFCollection.h \ + OFSerialization.h \ ObjFW.h \ asprintf.h \ ${ATOMIC_H} \ macros.h \ objfw-defs.h \ Index: src/OFArray.m ================================================================== --- src/OFArray.m +++ src/OFArray.m @@ -247,12 +247,11 @@ enumerator = [[element elementsForName: @"object" namespace: OF_SERIALIZATION_NS] objectEnumerator]; pool2 = [[OFAutoreleasePool alloc] init]; while ((child = [enumerator nextObject]) != nil) { - id object = [OFSerialization - objectByDeserializingXMLElement: child]; + id object = [child objectByDeserializing]; [array addItem: &object]; [object retain]; [pool2 releaseObjects]; Index: src/OFDictionary.m ================================================================== --- src/OFDictionary.m +++ src/OFDictionary.m @@ -513,17 +513,17 @@ 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]]; + key = [[keyElement elementForName: @"object" + namespace: OF_SERIALIZATION_NS] + objectByDeserializing]; + object = [[valueElement + elementForName: @"object" + namespace: OF_SERIALIZATION_NS] + objectByDeserializing]; [dictionary setObject: object forKey: key]; [pool2 releaseObjects]; Index: src/OFList.m ================================================================== --- src/OFList.m +++ src/OFList.m @@ -55,12 +55,11 @@ enumerator = [[element elementsForName: @"object" namespace: OF_SERIALIZATION_NS] objectEnumerator]; pool2 = [[OFAutoreleasePool alloc] init]; while ((child = [enumerator nextObject]) != nil) { - id object = [OFSerialization - objectByDeserializingXMLElement: child]; + id object = [child objectByDeserializing]; [self appendObject: object]; [pool2 releaseObjects]; } ADDED src/OFObject+Serialization.h Index: src/OFObject+Serialization.h ================================================================== --- src/OFObject+Serialization.h +++ src/OFObject+Serialization.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011 + * Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#import "OFObject.h" + +@class OFString; + +#ifdef __cplusplus +extern "C" { +#endif +extern int _OFObject_Serialization_reference; +#ifdef __cplusplus +} +#endif + +/** + * \brief A category that provides methods for serializing objects. + */ +@interface OFObject (OFSerialization) +/** + * \brief Creates a string by serializing the receiver. + * + * \return The object serialized as a string + */ +- (OFString*)stringBySerializing; +@end ADDED src/OFObject+Serialization.m Index: src/OFObject+Serialization.m ================================================================== --- src/OFObject+Serialization.m +++ src/OFObject+Serialization.m @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011 + * Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#import "OFObject.h" +#import "OFObject+Serialization.h" +#import "OFSerialization.h" +#import "OFString.h" +#import "OFXMLElement.h" +#import "OFAutoreleasePool.h" + +#import "OFNotImplementedException.h" + +int _OFObject_Serialization_reference; + +@implementation OFObject (Serialization) +- (OFString*)stringBySerializing +{ + OFAutoreleasePool *pool; + OFXMLElement *element; + OFXMLElement *root; + OFString *ret; + + if (![self conformsToProtocol: @protocol(OFSerialization)]) + @throw [OFNotImplementedException + newWithClass: isa + selector: @selector(stringBySerializing)]; + + pool = [[OFAutoreleasePool alloc] init]; + element = [(id)self XMLElementBySerializing]; + + root = [OFXMLElement elementWithName: @"serialization" + namespace: OF_SERIALIZATION_NS]; + [root addChild: element]; + + ret = [@"\n" + stringByAppendingString: [root XMLString]]; + [ret retain]; + + @try { + [pool release]; + } @catch (id e) { + [ret release]; + } + + return [ret autorelease]; +} +@end Index: src/OFObject.h ================================================================== --- src/OFObject.h +++ src/OFObject.h @@ -528,10 +528,12 @@ * \param object An object to compare the object to * \return The result of the comparison */ - (of_comparison_result_t)compare: (id)object; @end + +#import "OFObject+Serialization.h" #ifdef __cplusplus extern "C" { #endif extern id objc_getProperty(id, SEL, ptrdiff_t, BOOL); Index: src/OFObject.m ================================================================== --- src/OFObject.m +++ src/OFObject.m @@ -119,10 +119,16 @@ const char* _NSPrintForDebugger(id object) { return [[object description] cString]; } + +/* References for static linking */ +void _references_to_categories_of_OFObject(void) +{ + _OFObject_Serialization_reference = 1; +} @implementation OFObject + (void)load { #ifdef NEED_OBJC_SYNC_INIT Index: src/OFSerialization.h ================================================================== --- src/OFSerialization.h +++ src/OFSerialization.h @@ -14,14 +14,13 @@ * file. */ #import "OFObject.h" -@class OFString; -@class OFXMLElement; +#define OF_SERIALIZATION_NS @"https://webkeks.org/objfw/serialization" -#define OF_SERIALIZATION_NS @"https://webkeks.org/objfw/serialization" +@class OFXMLElement; /** * \brief A protocol for serializing objects. */ @protocol OFSerialization @@ -38,35 +37,5 @@ * * \return The object serialized into an XML element */ - (OFXMLElement*)XMLElementBySerializing; @end - -/** - * \brief A class that provides class methods for serializing and deserializing - * objects. - */ -@interface OFSerialization: OFObject -/** - * \brief Creates a string by serializing the specified object. - * - * \param object The object to serialize - * \return The object serialized as a string - */ -+ (OFString*)stringBySerializingObject: (id )object; - -/** - * \brief Deserializes the specified string into an object. - * - * \param string The string describing the serialized object - * \return The deserialized object - */ -+ (id)objectByDeserializingString: (OFString*)string; - -/** - * \brief Deserializes the specified XML element into an object. - * - * \param string The XML element describing the serialized object - * \return The deserialized object - */ -+ (id)objectByDeserializingXMLElement: (OFXMLElement*)element; -@end DELETED src/OFSerialization.m Index: src/OFSerialization.m ================================================================== --- src/OFSerialization.m +++ src/OFSerialization.m @@ -1,136 +0,0 @@ -/* - * Copyright (c) 2008, 2009, 2010, 2011 - * Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#include "config.h" - -#if defined(OF_APPLE_RUNTIME) || defined(OF_GNU_RUNTIME) -# import -#elif defined(OF_OLD_GNU_RUNTIME) -# import -#endif - -#import "OFSerialization.h" -#import "OFString.h" -#import "OFArray.h" -#import "OFXMLElement.h" -#import "OFAutoreleasePool.h" - -#import "OFInvalidArgumentException.h" -#import "OFInvalidFormatException.h" -#import "OFNotImplementedException.h" - -#if defined(OF_OBJFW_RUNTIME) || defined(OF_OLD_GNU_RUNTIME) -# define objc_lookUpClass objc_lookup_class -#endif - -@implementation OFSerialization -+ (OFString*)stringBySerializingObject: (id )object -{ - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; - OFXMLElement *element = [object XMLElementBySerializing]; - OFXMLElement *root; - OFString *ret; - - root = [OFXMLElement elementWithName: @"serialization" - namespace: OF_SERIALIZATION_NS]; - [root addChild: element]; - - ret = [@"\n" - stringByAppendingString: [root XMLString]]; - [ret retain]; - - @try { - [pool release]; - } @catch (id e) { - [ret release]; - } - - return [ret autorelease]; -} - -+ (id)objectByDeserializingString: (OFString*)string -{ - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; - OFXMLElement *root = [OFXMLElement elementWithXMLString: string]; - OFArray *elements; - id object; - - elements = [root elementsForName: @"object" - namespace: OF_SERIALIZATION_NS]; - - if ([elements count] != 1) - @throw [OFInvalidArgumentException newWithClass: self - selector: _cmd]; - - object = [[self objectByDeserializingXMLElement: [elements firstObject]] - retain]; - - @try { - [pool release]; - } @catch (id e) { - [object release]; - @throw e; - } - - return [object autorelease]; -} - -+ (id)objectByDeserializingXMLElement: (OFXMLElement*)element -{ - OFAutoreleasePool *pool; - OFString *className; - Class class; - id object; - - if (element == nil) - return nil; - - pool = [[OFAutoreleasePool alloc] init]; - className = [[element attributeForName: @"class"] stringValue]; - if (className == nil) - @throw [OFInvalidArgumentException newWithClass: self - selector: _cmd]; - - class = objc_lookUpClass([className cString]); - if (class == Nil) - @throw [OFNotImplementedException newWithClass: Nil]; - - if (![class instancesRespondToSelector: - @selector(initWithSerialization:)]) - @throw [OFNotImplementedException - newWithClass: class - selector: @selector(initWithSerialization:)]; - - object = [[class alloc] initWithSerialization: element]; - - @try { - [pool release]; - } @catch (id e) { - [object release]; - @throw e; - } - - return [object autorelease]; -} - -- init -{ - Class c = isa; - [self release]; - @throw [OFNotImplementedException newWithClass: c - selector: _cmd]; -} -@end ADDED src/OFString+Serialization.h Index: src/OFString+Serialization.h ================================================================== --- src/OFString+Serialization.h +++ src/OFString+Serialization.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011 + * Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#import "OFString.h" + +#ifdef __cplusplus +extern "C" { +#endif +extern int _OFString_Serialization_reference; +#ifdef __cplusplus +} +#endif + +/** + * \brief A category that provides methods for deserializing objects. + */ +@interface OFString (OFSerialization) +/** + * \brief Deserializes the receiver into an object. + * + * \return The deserialized object + */ +- (id)objectByDeserializing; +@end ADDED src/OFString+Serialization.m Index: src/OFString+Serialization.m ================================================================== --- src/OFString+Serialization.m +++ src/OFString+Serialization.m @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011 + * Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#import "OFString.h" +#import "OFString+Serialization.h" +#import "OFSerialization.h" +#import "OFArray.h" +#import "OFXMLElement.h" +#import "OFAutoreleasePool.h" + +#import "OFInvalidArgumentException.h" + +int _OFString_Serialization_reference; + +@implementation OFString (Serialization) +- (id)objectByDeserializing +{ + OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + OFXMLElement *root = [OFXMLElement elementWithXMLString: self]; + OFArray *elements; + id object; + + elements = [root elementsForName: @"object" + namespace: OF_SERIALIZATION_NS]; + + if ([elements count] != 1) + @throw [OFInvalidArgumentException newWithClass: isa + selector: _cmd]; + + object = [[[elements firstObject] objectByDeserializing] retain]; + + @try { + [pool release]; + } @catch (id e) { + [object release]; + @throw e; + } + + return [object autorelease]; +} +@end Index: src/OFString.h ================================================================== --- src/OFString.h +++ src/OFString.h @@ -701,8 +701,9 @@ @end #import "OFConstantString.h" #import "OFMutableString.h" #import "OFString+Hashing.h" +#import "OFString+Serialization.h" #import "OFString+URLEncoding.h" #import "OFString+XMLEscaping.h" #import "OFString+XMLUnescaping.h" Index: src/OFString.m ================================================================== --- src/OFString.m +++ src/OFString.m @@ -57,10 +57,11 @@ /* References for static linking */ void _references_to_categories_of_OFString(void) { _OFString_Hashing_reference = 1; + _OFString_Serialization_reference = 1; _OFString_URLEncoding_reference = 1; _OFString_XMLEscaping_reference = 1; _OFString_XMLUnescaping_reference = 1; } ADDED src/OFXMLElement+Serialization.h Index: src/OFXMLElement+Serialization.h ================================================================== --- src/OFXMLElement+Serialization.h +++ src/OFXMLElement+Serialization.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011 + * Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#import "OFXMLElement.h" + +#ifdef __cplusplus +extern "C" { +#endif +extern int _OFXMLElement_Serialization_reference; +#ifdef __cplusplus +} +#endif + +/** + * \brief A category that provides methods for deserializing objects. + */ +@interface OFXMLElement (OFSerialization) +/** + * \brief Deserializes the receiver into an object. + * + * \return The deserialized object + */ +- (id)objectByDeserializing; +@end ADDED src/OFXMLElement+Serialization.m Index: src/OFXMLElement+Serialization.m ================================================================== --- src/OFXMLElement+Serialization.m +++ src/OFXMLElement+Serialization.m @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011 + * Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#if defined(OF_APPLE_RUNTIME) || defined(OF_GNU_RUNTIME) +# import +#elif defined(OF_OLD_GNU_RUNTIME) +# import +#endif + +#import "OFXMLElement.h" +#import "OFXMLElement+Serialization.h" +#import "OFSerialization.h" +#import "OFString.h" +#import "OFAutoreleasePool.h" + +#import "OFInvalidArgumentException.h" +#import "OFNotImplementedException.h" + +#if defined(OF_OBJFW_RUNTIME) || defined(OF_OLD_GNU_RUNTIME) +# define objc_lookUpClass objc_lookup_class +#endif + +int _OFXMLElement_Serialization_reference; + +@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) + @throw [OFNotImplementedException newWithClass: Nil]; + + if (![class conformsToProtocol: @protocol(OFSerialization)]) + @throw [OFNotImplementedException + newWithClass: class + selector: @selector(initWithSerialization:)]; + + object = [[class alloc] initWithSerialization: self]; + + @try { + [pool release]; + } @catch (id e) { + [object release]; + @throw e; + } + + return [object autorelease]; +} +@end Index: src/OFXMLElement.h ================================================================== --- src/OFXMLElement.h +++ src/OFXMLElement.h @@ -384,5 +384,7 @@ * \return The child elements with the specified name and namespace */ - (OFArray*)elementsForName: (OFString*)elementName namespace: (OFString*)elementNS; @end + +#import "OFXMLElement+Serialization.h" Index: src/OFXMLElement.m ================================================================== --- src/OFXMLElement.m +++ src/OFXMLElement.m @@ -32,10 +32,16 @@ #import "OFMalformedXMLException.h" #import "OFNotImplementedException.h" #import "OFUnboundNamespaceException.h" #import "macros.h" + +/* References for static linking */ +void _references_to_categories_of_OFXMLElement(void) +{ + _OFXMLElement_Serialization_reference = 1; +} @interface OFXMLElement_OFXMLElementBuilderDelegate: OFObject { @public OFXMLElement *element; @@ -319,21 +325,21 @@ elementForName: @"namespaces" namespace: OF_SERIALIZATION_NS]; childrenElement = [element elementForName: @"children" namespace: OF_SERIALIZATION_NS]; - attributes = [[OFSerialization objectByDeserializingXMLElement: - [attributesElement elementForName: @"object" - namespace: OF_SERIALIZATION_NS]] - retain]; - namespaces = [[OFSerialization objectByDeserializingXMLElement: - [namespacesElement elementForName: @"object" - namespace: OF_SERIALIZATION_NS]] - retain]; - children = [[OFSerialization objectByDeserializingXMLElement: - [childrenElement elementForName: @"object" - 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]; if (!((name != nil || ns != nil || defaultNamespace != nil || [attributes count] > 0 || [namespaces count] > 0 || [children count] > 0) ^ (characters != nil) ^ Index: tests/OFSerializationTests.m ================================================================== --- tests/OFSerializationTests.m +++ tests/OFSerializationTests.m @@ -87,15 +87,14 @@ [l appendObject: [OFXMLElement elementWithXMLString: @""]]; [d setObject: @"list" forKey: l]; - TEST(@"Serialization", - (s = [OFSerialization stringBySerializingObject: d]) && - [s isEqual: expected]) + TEST(@"-[stringBySerializing]", + (s = [d stringBySerializing]) && [s isEqual: expected]) - TEST(@"Deserialization", - [[OFSerialization objectByDeserializingString: s] isEqual: d]) + TEST(@"-[objectByDeserializing]", + [[s objectByDeserializing] isEqual: d]) [pool drain]; } @end