/* DBController.m
 * A utility class used to communicate with EOF.
 * 
 * You may freely copy, distribute, and reuse the code in this example.
 * NeXT disclaims any warranty of any kind, expressed or  implied, as to its
 * fitness for any particular use.
 *
 * Written by Paul Marcos, NeXT Software Engineer
 */

#import "dbcontroller.h"
#import <EOAccess/EOAccess.h>

// When the DLL is loaded, this function will be called. We
// simply return an instance of DBController which is nothing more
// than a utility class.
id NSGetDllObject (NSString *obj)
{
	return [[DBController alloc] init];
}

// DBController only has two methods.  The first exposes the 
// EODatabaseDataSource class since classes aren't directly
// accessible from OLE.  The second simply passes arguments
// through to a varargs Objective C method.  This is needed 
// since there is no varargs support in OLE.
@implementation DBController
- init
{
	[super init];
	return [self autorelease];
}

- eoDatabaseDataSource
{
	return [EODatabaseDataSource class];
}

- (EOQualifier*)qualifierWithEntity: (EOEntity*)entity format: (NSString*)format arg1: (NSString*)arg1 arg2: (NSString*)arg2
{
	return [[EOQualifier alloc] initWithEntity: entity qualifierFormat: format, arg1, arg2];
}

@end


// This category of EOGenericRecord lets the EO attributes 
// be treated as OLE Properties.  
@interface EOGenericRecord (OLEProperty)
@end


@implementation EOGenericRecord (OLEProperty)
- (NSValue*)getOLEPropertyNamed:(NSString*)str
{
	id value = [self objectForKey:str];
	if (value)
		return [NSValue value:&value withObjCType:@encode(id)];
	else if ([str caseInsensitiveCompare:@"value"] == NSOrderedSame)
		return [NSValue value:&self withObjCType:@encode(id)];
	else
		return nil;
}
@end

