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