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 <XmlRpc/XmlRpcCoder.h>
24 #include <XmlRpc/XmlRpcSaxHandler.h>
25 #include <XmlRpc/XmlRpcMethodCall.h>
26 #include <XmlRpc/XmlRpcValue.h>
27 #include <SaxObjC/SaxXMLReaderFactory.h>
30 @implementation XmlRpcRequestDecoder
32 static id saxRequestHandler = nil;
33 static id requestParser = nil;
34 static BOOL doDebug = NO;
36 - (void)_ensureSaxAndParser {
37 if (saxRequestHandler == nil) {
38 static Class clazz = Nil;
41 clazz = NSClassFromString(@"XmlRpcSaxRequestHandler");
43 if ((saxRequestHandler = [[clazz alloc] init]) == nil) {
44 NSLog(@"%s: did not find sax handler ...", __PRETTY_FUNCTION__);
49 if (requestParser != nil) return;
52 [[SaxXMLReaderFactory standardXMLReaderFactory] createXMLReader];
54 if (requestParser == nil) {
55 NSLog(@"%s: did not find an XML parser ...", __PRETTY_FUNCTION__);
59 [requestParser setContentHandler:saxRequestHandler];
60 [requestParser setDTDHandler:saxRequestHandler];
61 [requestParser setErrorHandler:saxRequestHandler];
63 [requestParser retain];
66 - (XmlRpcMethodCall *)decodeRootObject {
67 XmlRpcMethodCall *methodCall;
68 NSEnumerator *paramEnum;
69 NSMutableArray *params;
72 if (doDebug) NSLog(@"%s: begin", __PRETTY_FUNCTION__);
73 [self _ensureSaxAndParser];
75 [saxRequestHandler reset];
77 [requestParser parseFromSource:self->string systemId:nil];
79 methodCall = [saxRequestHandler methodCall];
81 // the methodCall's parameters is an array of XmlRpcValues!!!
83 paramEnum = [[methodCall parameters] objectEnumerator];
84 params = [[NSMutableArray alloc] initWithCapacity:
85 [[methodCall parameters] count]];
87 while ((param = [paramEnum nextObject])) {
91 [self->value autorelease];
92 self->value = [param retain];
94 if ((objClass = NSClassFromString([param className])) != Nil) {
95 if ((obj = [objClass decodeObjectWithXmlRpcCoder:self])) {
96 [params addObject:obj];
99 NSLog(@"%s: Warning: try to add 'nil' object to params (class='%@')",
105 [methodCall setParameters:params];
109 if (doDebug) NSLog(@"%s: done: %@", __PRETTY_FUNCTION__, methodCall);
113 @end /* XmlRpcRequestDecoder */