//
//  EXPFlowElement.m
//  XMLTest
//
//  Created by Ashley on 11/04/2007.
//  Copyright 2007 __MyCompanyName__. All rights reserved.
//

#import "EXPFlowElement.h"

@implementation EXPFlowElement

- (id) initWithXLMElement:(NSXMLElement *)element
{
	self = [super init];
	_source = nil;
	_destination = nil;	
//	[_expressionList setArray:[element children]];
	
/*	NSXMLElement *expression = [[element elementsForName:@"expression"] objectAtIndex:0];
	NSXMLNode *child = [expression childAtIndex:0];
	do {
		NSString *name = [child name];
		NSLog(@"%@", name);
		[_expressionList addObject:name];
	} while ( child = [child nextSibling] ); */
	
	return self;
}

- (void) setElementFromXMLElement:(NSXMLElement *)element
{
	[super setElementFromXLMElement:element];

	NSArray *sources = [element elementsForName:@"source"];
	NSXMLElement *source = [sources objectAtIndex:0];
	NSString *sourceName = [[source stringValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
	if ([sourceName length]==0) {
		sourceName = nil;
	}
	[self setSource:sourceName];

	NSArray *destinations = [element elementsForName:@"destination"];
	NSXMLElement *destination = [destinations objectAtIndex:0];
	NSString *destinationName = [[destination stringValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
	if ([destinationName length]==0) {
		destinationName = nil;
	}
	[self setDestination:destinationName];

}

- (id) source
{
	return _source;
}

- (void) setSource:(id)source
{
	[source retain];
	[_source release];
	_source = source;
}

- (id) destination
{
	return _destination;
}

- (void)  setDestination:(id)destination
{
	[destination retain];
	[_destination release];
	_destination = destination;
}

- (BOOL) isFlow
{
	return YES;
}

- (NSString *)elementType
{
	return @"flow";
}

- (void) clear
{	
	[self setSource:nil];
	[self setDestination:nil];
	[super clear];
}

- (NSString *)description
{
	return [NSString stringWithFormat:@"EXPFlowElement '%@'", [self name]];
}

- (void) dealloc
{
//	printf("EXPFlowElement - (void) dealloc\n");
	[_source release];
	[_destination release];
	[super dealloc];
}

@end
