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 <XmlRpc/XmlRpcCoder.h>
23 #include <XmlRpc/XmlRpcSaxHandler.h>
24 #include <XmlRpc/XmlRpcMethodCall.h>
25 #include <XmlRpc/XmlRpcValue.h>
26 #include <SaxObjC/SaxXMLReaderFactory.h>
29 @implementation XmlRpcRequestDecoder
31 static id saxRequestHandler = nil;
32 static id requestParser = nil;
33 static BOOL doDebug = NO;
35 - (void)_ensureSaxAndParser {
36 if (saxRequestHandler == nil) {
37 static Class clazz = Nil;
40 clazz = NSClassFromString(@"XmlRpcSaxRequestHandler");
42 if ((saxRequestHandler = [[clazz alloc] init]) == nil) {
43 NSLog(@"%s: did not find sax handler ...", __PRETTY_FUNCTION__);
48 if (requestParser != nil) return;
51 [[SaxXMLReaderFactory standardXMLReaderFactory] createXMLReader];
53 if (requestParser == nil) {
54 NSLog(@"%s: did not find an XML parser ...", __PRETTY_FUNCTION__);
58 [requestParser setContentHandler:saxRequestHandler];
59 [requestParser setDTDHandler:saxRequestHandler];
60 [requestParser setErrorHandler:saxRequestHandler];
62 [requestParser retain];
65 - (XmlRpcMethodCall *)decodeRootObject {
66 XmlRpcMethodCall *methodCall;
67 NSEnumerator *paramEnum;
68 NSMutableArray *params;
71 if (doDebug) NSLog(@"%s: begin", __PRETTY_FUNCTION__);
72 [self _ensureSaxAndParser];
74 [saxRequestHandler reset];
76 [requestParser parseFromSource:self->string systemId:nil];
78 methodCall = [saxRequestHandler methodCall];
80 // the methodCall's parameters is an array of XmlRpcValues!!!
82 paramEnum = [[methodCall parameters] objectEnumerator];
83 params = [[NSMutableArray alloc] initWithCapacity:
84 [[methodCall parameters] count]];
86 while ((param = [paramEnum nextObject])) {
90 [self->value autorelease];
91 self->value = [param retain];
93 if ((objClass = NSClassFromString([param className])) != Nil) {
94 if ((obj = [objClass decodeObjectWithXmlRpcCoder:self])) {
95 [params addObject:obj];
98 NSLog(@"%s: Warning: try to add 'nil' object to params (class='%@')",
104 [methodCall setParameters:params];
108 if (doDebug) NSLog(@"%s: done: %@", __PRETTY_FUNCTION__, methodCall);
112 @end /* XmlRpcRequestDecoder */