4632N/A// Most of this is adapted from Ken Ferry's KFAppleScript Additions, contributed with permission
4632N/A#import <Cocoa/Cocoa.h>
4632N/A#import <Carbon/Carbon.h>
4632N/A// AS objects to ObjC objects, and is called by -[NSAppleScript executeHandler:error:withParameters:].
4632N/A// It does no work itself. It finds a handler based on the type of the descriptor and lets that
4632N/A// handler object do the work. If there is no handler type registered for a the type of a descriptor,
4632N/A// +[NSAppleEventDescriptor registerConversionHandler:selector:forDescriptorTypes:]. Please note
4632N/A// that this method does _not_ retain the handler object (for now anyway). The selector should
4632N/A// take a single argument, a descriptor to translate, and should return an object. An example such
4632N/A// selector is @selector(dictionaryWithAEDesc:), for which the handler object would be [NSDictionary class].
4632N/A// A number of handlers are designated by default. The methods and objects can be easily inferred (or check
4632N/A+ (void)registerConversionHandler:(id)anObject selector:(SEL)aSelector forDescriptorTypes:(DescType)firstType, ...;
4632N/A+ (void) jaseSetUpHandlerDict;
4632N/A// NSNumbers created with numberWithBool should be correctly translated to AS booleans and vice versa.
4632N/A// [[NSNumber numberWithUnsignedChar:255] aeDescriptorValue] is going to get you an AS integer
4632N/A// with value -1. If you really need a descriptor with an unsigned value, you'll need to do it
4632N/A // encode the description as a fallback - this is pretty useless, only helpful for debugging
4632N/A return resultDesc;
4632N/A// don't need to override aeDescriptorValue, the NSObject will treat the array as a collection
4632N/A return resultArray;
4632N/A [resultDesc setDescriptor:[[self objectForKey:key] aeDescriptorValue] forKeyword:[(NSNumber *)key intValue]];
4632N/A return resultDesc;
4632N/A return resultDict;
4632N/A return [[[NSString alloc] initWithBytes:&v.shortVersion[1] length:StrLength(v.shortVersion) encoding:NSUTF8StringEncoding] autorelease];
4632N/A format:@"JavaAppleScriptEngineAdditions: conversion of an NSNumber with objCType '%s' to an aeDescriptor is not supported.", type];
4632N/A format:@"JavaAppleScriptEngineAdditions: conversion of an NSAppleEventDescriptor with objCType '%s' to an aeDescriptor is not supported.", type];
4632N/A format:@"NSNumber jaseNumberWithSignedIntP:byteCount: number with %i bytes not supported.", bytes];
4632N/A format:@"NSNumber numberWithUnsignedInt:byteCount: number with %i bytes not supported.", bytes];
4632N/A format:@"NSNumber numberWithFloat:byteCount: floating point number with %i bytes not supported.", bytes];
4632N/A format:@"JavaAppleScriptEngineAdditions: conversion of an NSNumber with objCType '%s' to an aeDescriptor is not supported.", type];
4632N/A NSInvocation *handlerInvocation = [handlerDict objectForKey:[NSValue valueWithBytes:&type objCType:@encode(DescType)]];
4632N/A+ (void)registerConversionHandler:(id)anObject selector:(SEL)aSelector forDescriptorTypes:(DescType)firstType, ... {
4632N/A NSInvocation *handlerInvocation = [NSInvocation invocationWithMethodSignature:[anObject methodSignatureForSelector:aSelector]];
4632N/A return [NSAppleEventDescriptor descriptorWithDescriptorType:typeSInt16 bytes:&val length:sizeof(val)];
4632N/A return [NSAppleEventDescriptor descriptorWithDescriptorType:typeUInt32 bytes:&val length:sizeof(val)];
4632N/A return [NSAppleEventDescriptor descriptorWithDescriptorType:typeIEEE32BitFloatingPoint bytes:&val length:sizeof(val)];
4632N/A return [NSAppleEventDescriptor descriptorWithDescriptorType:typeIEEE64BitFloatingPoint bytes:&val length:sizeof(val)];
4632N/A return [NSAppleEventDescriptor descriptorWithDescriptorType:typeLongDateTime bytes:&val length:sizeof(val)];
4632N/A+ (void)jaseSetUpHandlerDict {
4632N/A [NSAppleEventDescriptor registerConversionHandler:[NSString class] selector:@selector(stringWithAEDesc:) forDescriptorTypes:
4632N/A [NSAppleEventDescriptor registerConversionHandler:[NSNumber class] selector:@selector(numberWithAEDesc:) forDescriptorTypes:
4632N/A [NSAppleEventDescriptor registerConversionHandler:[NSArray class] selector:@selector(arrayWithAEDesc:) forDescriptorTypes:typeAEList, nil];
4632N/A [NSAppleEventDescriptor registerConversionHandler:[NSDictionary class] selector:@selector(dictionaryWithAEDesc:) forDescriptorTypes:typeAERecord, nil];
4632N/A [NSAppleEventDescriptor registerConversionHandler:[NSDate class] selector:@selector(dateWithAEDesc:) forDescriptorTypes:typeLongDateTime, nil];
4632N/A [NSAppleEventDescriptor registerConversionHandler:[NSImage class] selector:@selector(imageWithAEDesc:) forDescriptorTypes:
4632N/A [NSAppleEventDescriptor registerConversionHandler:[NSString class] selector:@selector(versionWithAEDesc:) forDescriptorTypes:typeVersion, nil];