]> err.no Git - sope/blob - sope-xml/XmlRpc/XmlRpcMethodResponse.m
fixed Xcode build
[sope] / sope-xml / XmlRpc / XmlRpcMethodResponse.m
1 /*
2   Copyright (C) 2000-2003 SKYRIX Software AG
3
4   This file is part of OGo
5
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
9   later version.
10
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.
15
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
19   02111-1307, USA.
20 */
21 // $Id$
22
23 #include "XmlRpcMethodResponse.h"
24 #include "XmlRpcCoder.h"
25 #include "common.h"
26
27 @interface XmlRpcMethodResponse(PrivateMethodes)
28 - (NSString *)_encodeXmlRpcMethodResponse;
29 @end
30
31 @implementation XmlRpcMethodResponse
32
33 - (id)initWithXmlRpcString:(NSString *)_string {
34   XmlRpcDecoder        *coder;
35   XmlRpcMethodResponse *baseResponse;
36   
37   if ([_string length] == 0) {
38     [self release];
39     return nil;
40   }
41
42   coder        = [[XmlRpcDecoder alloc] initForReadingWithString:_string];
43   baseResponse = [coder decodeMethodResponse];
44   [coder release];
45
46   if (baseResponse == nil) {
47     [self release];
48     return nil;
49   }
50   
51   self = [self initWithResult:[baseResponse result]];
52   
53   return self;
54 }
55 - (id)initWithXmlRpcData:(NSData *)_data {
56   XmlRpcDecoder        *coder;
57   XmlRpcMethodResponse *baseResponse;
58   
59   if ([_data length] == 0) {
60     [self release];
61     return nil;
62   }
63
64   coder        = [[XmlRpcDecoder alloc] initForReadingWithData:_data];
65   baseResponse = [coder decodeMethodResponse];
66   [coder release];
67
68   if (baseResponse == nil) {
69     [self release];
70     return nil;
71   }
72   
73   self = [self initWithResult:[baseResponse result]];
74   
75   return self;
76 }
77
78 - (id)initWithResult:(id)_result {
79   if ((self = [super init])) {
80     self->result = [_result retain];
81   }
82   return self;
83 }
84
85 - (void)dealloc {
86   [self->result release];
87   [super dealloc];
88 }
89
90 /* accessors */
91
92 - (void)setResult:(id)_result {
93   [self->result autorelease];
94   self->result = [_result retain];
95 }
96 - (id)result {
97   return self->result;
98 }
99
100 - (NSString *)xmlRpcString {
101   return [self _encodeXmlRpcMethodResponse];
102 }
103
104 /* description */
105
106 - (NSString *)description {
107   NSMutableString *ms;
108   
109   ms = [NSMutableString stringWithCapacity:64];
110   [ms appendFormat:@"<0x%08X[%@]:", self, NSStringFromClass([self class])];
111
112   if (result)
113     [ms appendFormat:@" %@", self->result];
114   else
115     [ms appendString:@" no result"];
116   
117   [ms appendString:@">"];
118   return ms;
119 }
120
121 @end /* XmlRpcMethodResponse */
122
123 @implementation XmlRpcMethodResponse(PrivateMethodes)
124
125 - (NSString *)_encodeXmlRpcMethodResponse {
126   XmlRpcEncoder   *encoder = nil;
127   NSMutableString *str     = nil;
128
129   str = [NSMutableString stringWithCapacity:512];
130
131   encoder = [[XmlRpcEncoder alloc] initForWritingWithMutableString:str];
132   [encoder encodeMethodResponse:self];
133   [encoder release];
134
135   return str;
136 }
137
138 @end /* XmlRpcMethodResponse(PrivateMethodes) */