24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
-
+
-
+
-
-
+
+
-
+
-
+
-
-
-
+
+
+
-
-
-
+
+
+
|
#import "OFInvalidArgumentException.h"
#import "autorelease.h"
#import "macros.h"
@implementation OFXMLAttribute
+ (instancetype)attributeWithName: (OFString*)name
namespace: (OFString*)ns
namespace: (OFString*)namespace
stringValue: (OFString*)stringValue
{
return [[[self alloc] initWithName: name
namespace: ns
namespace: namespace
stringValue: stringValue] autorelease];
}
+ (instancetype)attributeWithName: (OFString*)name
stringValue: (OFString*)stringValue
{
return [[[self alloc] initWithName: name
stringValue: stringValue] autorelease];
}
- initWithName: (OFString*)name_
stringValue: (OFString*)stringValue_
- initWithName: (OFString*)name
stringValue: (OFString*)stringValue
{
return [self initWithName: name_
return [self initWithName: name
namespace: nil
stringValue: stringValue_];
stringValue: stringValue];
}
- initWithName: (OFString*)name_
namespace: (OFString*)ns_
stringValue: (OFString*)stringValue_
- initWithName: (OFString*)name
namespace: (OFString*)namespace
stringValue: (OFString*)stringValue
{
self = [super init];
@try {
name = [name_ copy];
ns = [ns_ copy];
stringValue = [stringValue_ copy];
_name = [name copy];
_namespace = [namespace copy];
_stringValue = [stringValue copy];
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
|
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
-
-
-
-
-
+
+
+
+
+
-
-
-
+
+
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
+
-
+
-
-
-
+
+
+
-
+
-
+
-
+
-
+
-
+
|
if (![[element name] isEqual: [self className]] ||
![[element namespace] isEqual: OF_SERIALIZATION_NS])
@throw [OFInvalidArgumentException
exceptionWithClass: [self class]
selector: _cmd];
name = [[[element attributeForName: @"name"] stringValue]
copy];
ns = [[[element attributeForName: @"namespace"] stringValue]
copy];
stringValue = [[[element attributeForName: @"stringValue"]
_name = [[[element attributeForName: @"name"]
stringValue] copy];
_namespace = [[[element attributeForName: @"namespace"]
stringValue] copy];
_stringValue = [[[element attributeForName: @"stringValue"]
stringValue] copy];
objc_autoreleasePoolPop(pool);
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
- (void)dealloc
{
[name release];
[ns release];
[stringValue release];
[_name release];
[_namespace release];
[_stringValue release];
[super dealloc];
}
- (OFString*)name
{
OF_GETTER(name, YES)
OF_GETTER(_name, YES)
}
- (OFString*)namespace
{
OF_GETTER(ns, YES)
OF_GETTER(_namespace, YES)
}
- (OFString*)stringValue
{
OF_GETTER(stringValue, YES)
OF_GETTER(_stringValue, YES)
}
- (BOOL)isEqual: (id)object
{
OFXMLAttribute *otherAttribute;
OFXMLAttribute *attribute;
if (![object isKindOfClass: [OFXMLAttribute class]])
return NO;
otherAttribute = object;
attribute = object;
if (![otherAttribute->name isEqual: name])
if (![attribute->_name isEqual: _name])
return NO;
if (otherAttribute->ns != ns && ![otherAttribute->ns isEqual: ns])
if (attribute->_namespace != _namespace &&
![attribute->_namespace isEqual: _namespace])
return NO;
if (![otherAttribute->stringValue isEqual: stringValue])
if (![attribute->_stringValue isEqual: _stringValue])
return NO;
return YES;
}
- (uint32_t)hash
{
uint32_t hash;
OF_HASH_INIT(hash);
OF_HASH_ADD_HASH(hash, [name hash]);
OF_HASH_ADD_HASH(hash, [ns hash]);
OF_HASH_ADD_HASH(hash, [stringValue hash]);
OF_HASH_ADD_HASH(hash, [_name hash]);
OF_HASH_ADD_HASH(hash, [_namespace hash]);
OF_HASH_ADD_HASH(hash, [_stringValue hash]);
OF_HASH_FINALIZE(hash);
return hash;
}
- (OFXMLElement*)XMLElementBySerializing
{
void *pool = objc_autoreleasePoolPush();
OFXMLElement *element;
element = [OFXMLElement elementWithName: [self className]
namespace: OF_SERIALIZATION_NS];
[element addAttributeWithName: @"name"
stringValue: name];
stringValue: _name];
if (ns != nil)
if (_namespace != nil)
[element addAttributeWithName: @"namespace"
stringValue: ns];
stringValue: _namespace];
[element addAttributeWithName: @"stringValue"
stringValue: stringValue];
stringValue: _stringValue];
[element retain];
objc_autoreleasePoolPop(pool);
return [element autorelease];
}
- (OFString*)description
{
return [OFString stringWithFormat: @"<OFXMLAttribute, name=%@, "
@"namespace=%@, stringValue=%@>",
name, ns, stringValue];
_name, _namespace, _stringValue];
}
@end
|