]> err.no Git - sope/blob - sope-xml/XmlRpc/XmlRpcCoder.h
more code directory reorganizations
[sope] / sope-xml / XmlRpc / XmlRpcCoder.h
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 #ifndef __XmlRpc_XmlRpcCoder_H__
24 #define __XmlRpc_XmlRpcCoder_H__
25
26 #import <Foundation/NSObject.h>
27
28 @class NSDictionary, NSArray, NSNumber, NSString, NSCalendarDate, NSData;
29 @class NSMutableArray, NSMutableString, NSTimeZone, NSDate;
30 @class XmlRpcValue, XmlRpcMethodCall, XmlRpcMethodResponse;
31
32 /*"
33   The XmlRpcEncoder is used to encode XML-RPC objects. It's pretty much like
34   NSArchiver, only for XML-RPC.
35   
36   Encoder example: 
37
38    NSMutableString *str;                 // asume that exists
39    XmlRpcMethodResponse *methodResponse; // asume that exists
40    XmlRpcMethodCall     *methodCall;     // asume that exists
41  
42    coder = [[XmlRpcEncoder alloc] initForWritingWithMutableString:str];
43    
44    [coder encodeMethodCall:methodCall];
45
46    // or
47
48    [coder encodeMethodResponse:methodResponse];
49 "*/
50 @interface XmlRpcEncoder : NSObject
51 {
52   NSMutableString *string;
53   
54   NSMutableArray  *objectStack;
55   NSMutableArray  *objectHasStructStack;
56   NSTimeZone      *timeZone;
57 }
58
59 - (id)initForWritingWithMutableString:(NSMutableString *)_string;
60
61 - (void)encodeMethodCall:(XmlRpcMethodCall *)_methodCall;
62 - (void)encodeMethodResponse:(XmlRpcMethodResponse *)_methodResponse;
63
64 - (void)encodeStruct:(NSDictionary *)_struct;
65 - (void)encodeArray:(NSArray *)_array;
66 - (void)encodeBase64:(NSData *)_data;
67 - (void)encodeBoolean:(BOOL)_number;
68 - (void)encodeInt:(int)_number;
69 - (void)encodeDouble:(double)_number;
70 - (void)encodeString:(NSString *)_string;
71 - (void)encodeDateTime:(NSDate *)_date;
72 - (void)encodeObject:(id)_object;
73
74 - (void)encodeStruct:(NSDictionary *)_struct   forKey:(NSString *)_key;
75 - (void)encodeArray:(NSArray *)_array          forKey:(NSString *)_key;
76 - (void)encodeBase64:(NSData *)_data           forKey:(NSString *)_key;
77 - (void)encodeBoolean:(BOOL)_number            forKey:(NSString *)_key;
78 - (void)encodeInt:(int)_number                 forKey:(NSString *)_key;
79 - (void)encodeDouble:(double)_number           forKey:(NSString *)_key;
80 - (void)encodeString:(NSString *)_string       forKey:(NSString *)_key;
81 - (void)encodeDateTime:(NSDate *)_date         forKey:(NSString *)_key;
82 - (void)encodeObject:(id)_object               forKey:(NSString *)_key;
83
84 - (void)setDefaultTimeZone:(NSTimeZone *)_timeZone;
85
86 - (NSTimeZone *)defaultTimeZone;
87
88 @end
89
90 @class NSMutableSet;
91
92 /*"
93   The XmlRpcDecoder is used to decode XML-RPC objects. It's pretty much like
94   NSUnarchiver, only for XML-RPC.
95   
96   Decoder example:
97
98    NSString             *xmlRpcString; // asume that exists
99    XmlRpcMethodCall     *methodCall     = nil;
100    XmlRpcMethodResponse *methodResponse = nil;
101
102    coder = [[XmlRpcDecoder alloc] initForReadingWithString:xmlRpcString];
103
104    methodCall = [coder decodeMethodCall];
105    
106    // or
107    
108    methodResponse = [coder decodeMethodResponse];
109 "*/
110 @interface XmlRpcDecoder : NSObject
111 {
112   NSData         *data;
113   NSMutableArray *valueStack;
114    unsigned       nesting;
115   NSMutableArray *unarchivedObjects;
116   NSMutableSet   *awakeObjects;
117   NSTimeZone     *timeZone;
118 }
119
120 - (id)initForReadingWithString:(NSString *)_string;
121 - (id)initForReadingWithData:(NSData *)_data;
122
123 - (XmlRpcMethodCall *)decodeMethodCall;
124 - (XmlRpcMethodResponse *)decodeMethodResponse;
125
126 /* decoding */
127 - (NSDictionary *)decodeStruct;
128 - (NSArray *)decodeArray;
129 - (NSData *)decodeBase64;
130 - (BOOL)decodeBoolean;
131 - (int)decodeInt;
132 - (double)decodeDouble;
133 - (NSString *)decodeString;
134 - (NSCalendarDate *)decodeDateTime;
135 - (id)decodeObject;
136
137 - (NSDictionary *)decodeStructForKey:(NSString *)_key;
138 - (NSArray *)decodeArrayForKey:(NSString *)_key;
139 - (NSData *)decodeBase64ForKey:(NSString *)_key;
140 - (BOOL)decodeBooleanForKey:(NSString *)_key;
141 - (int)decodeIntForKey:(NSString *)_key;
142 - (double)decodeDoubleForKey:(NSString *)_key;
143 - (NSString *)decodeStringForKey:(NSString *)_key;
144 - (NSCalendarDate *)decodeDateTimeForKey:(NSString *)_key;
145 - (id)decodeObjectForKey:(NSString *)_key;
146
147 - (void)setDefaultTimeZone:(NSTimeZone *)_timeZone;
148 - (NSTimeZone *)defaultTimeZone;
149
150 /* operations */
151 - (void)ensureObjectAwake:(id)_object;
152 - (void)finishInitializationOfObjects;
153 - (void)awakeObjects;
154
155 @end
156
157 @interface NSObject(XmlRpcCoder)
158
159 + (id)decodeObjectWithXmlRpcCoder:(XmlRpcDecoder *)_decoder;
160 - (void)encodeWithXmlRpcCoder:(XmlRpcEncoder *)_coder;
161
162 @end
163
164 @interface NSObject(XmlRpcDecoderAwakeMethods)
165
166 - (void)finishInitializationWithXmlRpcDecoder:(XmlRpcDecoder *)_decoder;
167 - (void)awakeFromXmlRpcDecoder:(XmlRpcDecoder *)_decoder;
168
169 @end
170
171
172 #endif /* __XmlRpc_XmlRpcCoder_H__ */