3 * Copyright (c) 2011, Blue Static <http://www.bluestatic.org>
5 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
6 * General Public License as published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
10 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along with this program; if not,
14 * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
17 #import "VariableNode.h"
19 #include "NSXMLElementAdditions.h"
21 // Private Properties //////////////////////////////////////////////////////////
23 @interface VariableNode ()
25 @property (copy
) NSString
* name
;
26 @property (copy
) NSString
* fullName
;
27 @property (copy
) NSString
* className
;
28 @property (copy
) NSString
* type
;
29 @property (copy
) NSString
* value
;
30 @property (retain
) NSArray
* children
;
31 @property (copy
) NSString
* address
;
35 ////////////////////////////////////////////////////////////////////////////////
37 @implementation VariableNode
39 @synthesize name
= name_
;
40 @synthesize fullName
= fullName_
;
41 @synthesize className
= className_
;
42 @synthesize type
= type_
;
43 @synthesize value
= value_
;
44 @synthesize children
= children_
;
45 @synthesize childCount
= childCount_
;
46 @synthesize address
= address_
;
48 - (id)initWithXMLNode
:(NSXMLElement
*)node
50 if (self = [super init
]) {
51 self.name
= [[node attributeForName
:@
"name"] stringValue
];
52 self.fullName
= [[node attributeForName
:@
"fullname"] stringValue
];
53 self.className
= [[node attributeForName
:@
"classname"] stringValue
];
54 self.type
= [[node attributeForName
:@
"type"] stringValue
];
55 self.value
= [node base64DecodedValue
];
56 self.children
= [NSMutableArray array
];
57 if ([node children
]) {
58 [self setChildrenFromXMLChildren
:[node children
]];
60 childCount_
= [[[node attributeForName
:@
"numchildren"] stringValue
] integerValue
];
61 self.address
= [[node attributeForName
:@
"address"] stringValue
];
78 - (void)setChildrenFromXMLChildren
:(NSArray
*)children
80 [self willChangeValueForKey
:@
"children"];
82 [children_ removeAllObjects
];
84 for (NSXMLNode
* child
in children
) {
85 // Other child nodes may be the string value.
86 if ([child isKindOfClass
:[NSXMLElement
class]]) {
87 VariableNode
* node
= [[VariableNode alloc
] initWithXMLNode
:(NSXMLElement
*)child
];
88 // Don't include the CLASSNAME property as that information is retreeived
90 if (![node.name isEqualToString
:@
"CLASSNAME"])
91 [children_ addObject
:node
];
96 [self didChangeValueForKey
:@
"children"];
101 return (self.childCount
== 0);
104 - (NSString
*)displayType
106 if (self.className
!= nil) {
107 return [NSString stringWithFormat
:@
"%@ (%@)", self.className
, self.type
];
112 - (NSString
*)description
114 return [NSString stringWithFormat
:@
"<VariableNode %p : %@>", self, self.fullName
];