2 Copyright (C) 2000-2003 SKYRIX Software AG
4 This file is part of OGo
6 OGo 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 OGo 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 OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 #include "XmlRpcCoder.h"
24 #include "XmlRpcSaxHandler.h"
25 #include <SaxObjC/SaxXMLReaderFactory.h>
28 @implementation XmlRpcResponseDecoder
30 static id saxResponseHandler = nil;
31 static id responseParser = nil;
33 - (void)_ensureSaxAndParser {
34 if (saxResponseHandler == nil) {
35 if ((saxResponseHandler = [[XmlRpcSaxResponseHandler alloc] init])==nil) {
36 NSLog(@"%s: did not find sax handler ...", __PRETTY_FUNCTION__);
41 if (responseParser != nil) return;
44 [[SaxXMLReaderFactory standardXMLReaderFactory]
45 createXMLReaderForMimeType:@"text/xml"];
47 if (responseParser == nil) {
48 NSLog(@"%s: did not find an XML parser ...", __PRETTY_FUNCTION__);
52 responseParser = [responseParser retain];
53 [responseParser setContentHandler:saxResponseHandler];
54 [responseParser setDTDHandler:saxResponseHandler];
55 [responseParser setErrorHandler:saxResponseHandler];
58 - (id)decodeRootObject {
59 static Class ExceptionClass = Nil;
62 [self _ensureSaxAndParser];
64 if (ExceptionClass == Nil)
65 ExceptionClass = [NSException class];
67 [saxResponseHandler reset];
69 [responseParser parseFromSource:self->string systemId:nil];
71 result = [saxResponseHandler result];
73 if ([result isKindOfClass:ExceptionClass]) {
76 else { // => XmlRpcValue
77 XmlRpcValue *val = result;
81 [self->value autorelease];
82 self->value = [val retain];
84 if ((objClass = NSClassFromString([val className])) != Nil) {
85 obj = [objClass decodeObjectWithXmlRpcCoder:self];
93 @end /* XmlRpcResponseDecoder */