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 #import "AppDelegate.h"
20 #include "NSXMLElementAdditions.h"
22 // Private Properties //////////////////////////////////////////////////////////
24 @interface VariableNode ()
26 @property (copy
) NSString
* name
;
27 @property (copy
) NSString
* fullName
;
28 @property (copy
) NSString
* className
;
29 @property (copy
) NSString
* type
;
30 @property (copy
) NSString
* value
;
31 @property (retain
) NSArray
* children
;
32 @property (copy
) NSString
* address
;
36 ////////////////////////////////////////////////////////////////////////////////
38 @implementation VariableNode
40 @synthesize name
= name_
;
41 @synthesize fullName
= fullName_
;
42 @synthesize className
= className_
;
43 @synthesize type
= type_
;
44 @synthesize value
= value_
;
45 @synthesize children
= children_
;
46 @synthesize childCount
= childCount_
;
47 @synthesize address
= address_
;
49 - (id)initWithXMLNode
:(NSXMLElement
*)node
51 if (self = [super init
]) {
52 self.name
= [[node attributeForName
:@
"name"] stringValue
];
53 self.fullName
= [[node attributeForName
:@
"fullname"] stringValue
];
54 self.className
= [[node attributeForName
:@
"classname"] stringValue
];
55 self.type
= [[node attributeForName
:@
"type"] stringValue
];
56 self.value
= [node base64DecodedValue
];
57 self.children
= [NSMutableArray array
];
58 if ([node children
]) {
59 [self setChildrenFromXMLChildren
:[node children
]];
61 childCount_
= [[[node attributeForName
:@
"numchildren"] stringValue
] integerValue
];
62 self.address
= [[node attributeForName
:@
"address"] stringValue
];
79 - (void)setChildrenFromXMLChildren
:(NSArray
*)children
81 for (NSXMLNode
* child
in children
) {
82 // Other child nodes may be the string value.
83 if ([child isKindOfClass
:[NSXMLElement
class]]) {
84 VariableNode
* node
= [[VariableNode alloc
] initWithXMLNode
:(NSXMLElement
*)child
];
85 [children_ addObject
:[node autorelease
]];
90 - (NSArray
*)dynamicChildren
92 NSArray
* children
= self.children
;
93 if (![self isLeaf
] && [children count
] < 1) {
94 // If this node has children but they haven't been loaded from the backend,
95 // request them asynchronously.
96 [[AppDelegate instance
].debugger fetchChildProperties
:self];
103 return (self.childCount
== 0);
106 - (NSString
*)displayType
108 if (self.className
!= nil) {
109 return [NSString stringWithFormat
:@
"%@ (%@)", self.className
, self.type
];
114 - (NSString
*)description
116 return [NSString stringWithFormat
:@
"<VariableNode %p : %@>", self, self.fullName
];