Implement generation of XML introspection data for methods.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/dbuskit/trunk@34646 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Niels Grewe 2012-01-27 13:58:57 +00:00
parent 9e26d988ab
commit bf6cb08323
5 changed files with 77 additions and 1 deletions

View File

@ -1,3 +1,11 @@
2012-01-27 Niels Grewe <niels.grewe@halbordnung.de>
* Source/DKIntrospectionNode.h
* Source/DKIntrospectionNode.m:
Declare -XMLNode on all introspection nodes.
* Source/DKMethod.m: Implement generation of MXL introspection data.
* Tests(TestDKMethod.m: Add test for XML introspection data generation.
2012-01-27 Niels Grewe <niels.grewe@halbordnung.de>
* Tests/TestDKArgument.m: Add test for annotated XML introspection data.

View File

@ -23,7 +23,7 @@
*/
#import <Foundation/NSObject.h>
@class DKProxy, NSString, NSXMLParser, NSMutableDictionary;
@class DKProxy, NSString, NSXMLNode, NSXMLParser, NSMutableDictionary;
/**
* DKIntrospectionNode is the common superclass of all elements that make up the
* introspection graph for a D-Bus entity.
@ -83,4 +83,8 @@
*/
- (id) annotationValueForKey: (NSString*)key;
/**
* Returns an XML node representing the introspection node.
*/
- (NSXMLNode*)XMLNode;
@end

View File

@ -153,6 +153,13 @@
return [NSArray arrayWithArray: [annotationNodes autorelease]];
}
- (NSXMLNode*)XMLNode
{
[self subclassResponsibility: _cmd];
return nil;
}
- (void) dealloc
{
parent = nil;

View File

@ -29,6 +29,7 @@
#import <Foundation/NSMethodSignature.h>
#import <Foundation/NSNull.h>
#import <Foundation/NSString.h>
#import <Foundation/NSXMLNode.h>
#import "DKArgument.h"
#import "DKMethod.h"
@ -746,6 +747,52 @@
return newNode;
}
- (void)_addArgXMLNodesForDirection: (NSString*)direction
toArray: (NSMutableArray*)nodes
{
NSEnumerator *theEnum = nil;
DKArgument *arg = nil;
if ([@"in" isEqualToString: direction])
{
theEnum = [inArgs objectEnumerator];
}
else if ([@"out" isEqualToString: direction])
{
theEnum = [outArgs objectEnumerator];
}
else
{
return;
}
while (nil != (arg = [theEnum nextObject]))
{
NSXMLNode *node = [arg XMLNodeForDirection: @"in"];
if (nil != node)
{
[nodes addObject: node];
}
}
}
- (NSXMLNode*)XMLNode
{
NSXMLNode *nameAttribute = [NSXMLNode attributeWithName: @"name"
stringValue: name];
NSMutableArray *childNodes = [NSMutableArray array];
[self _addArgXMLNodesForDirection: @"in"
toArray: childNodes];
[self _addArgXMLNodesForDirection: @"out"
toArray: childNodes];
[childNodes addObjectsFromArray: [self annotationXMLNodes]];
return [NSXMLNode elementWithName: @"method"
children: childNodes
attributes: [NSArray arrayWithObject: nameAttribute]];
}
- (void)dealloc
{
[inArgs release];

View File

@ -101,4 +101,14 @@
UKNotNil(method);
UKObjectsEqual(new, [method parent]);
}
- (void)testXMLNode
{
//We use our builtin introspection method for this.
DKMethod *m = [_DKInterfaceIntrospectable DBusMethodForSelector: @selector(Introspect)];
NSXMLNode *n = [m XMLNode];
UKNotNil(n);
UKObjectsEqual(@"<method name=\"Introspect\">\n <arg name=\"data\" type=\"s\" direction=\"in\"/>\n </method>", [n XMLString]);
}
@end