2 Copyright (C) 2000-2005 SKYRIX Software AG
4 This file is part of SOPE.
6 SOPE is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 SOPE is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with SOPE; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #include "XmlRpcCoder.h"
23 #include "XmlRpcSaxHandler.h"
24 #include <SaxObjC/SaxXMLReaderFactory.h>
27 @implementation XmlRpcResponseDecoder
29 static id saxResponseHandler = nil;
30 static id responseParser = nil;
32 - (void)_ensureSaxAndParser {
33 if (saxResponseHandler == nil) {
34 if ((saxResponseHandler = [[XmlRpcSaxResponseHandler alloc] init])==nil) {
35 NSLog(@"%s: did not find sax handler ...", __PRETTY_FUNCTION__);
40 if (responseParser != nil) return;
43 [[SaxXMLReaderFactory standardXMLReaderFactory]
44 createXMLReaderForMimeType:@"text/xml"];
46 if (responseParser == nil) {
47 NSLog(@"%s: did not find an XML parser ...", __PRETTY_FUNCTION__);
51 responseParser = [responseParser retain];
52 [responseParser setContentHandler:saxResponseHandler];
53 [responseParser setDTDHandler:saxResponseHandler];
54 [responseParser setErrorHandler:saxResponseHandler];
57 - (id)decodeRootObject {
58 static Class ExceptionClass = Nil;
61 [self _ensureSaxAndParser];
63 if (ExceptionClass == Nil)
64 ExceptionClass = [NSException class];
66 [saxResponseHandler reset];
68 [responseParser parseFromSource:self->string systemId:nil];
70 result = [saxResponseHandler result];
72 if ([result isKindOfClass:ExceptionClass]) {
75 else { // => XmlRpcValue
76 XmlRpcValue *val = result;
80 [self->value autorelease];
81 self->value = [val retain];
83 if ((objClass = NSClassFromString([val className])) != Nil) {
84 obj = [objClass decodeObjectWithXmlRpcCoder:self];
92 @end /* XmlRpcResponseDecoder */