Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/macosx/native_NOTIOS/apple/applescript/AppleScriptEngine.m
38829 views
/*1* Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425#import "apple_applescript_AppleScriptEngine.h"26#import "apple_applescript_AppleScriptEngineFactory.h"2728#import <JavaNativeFoundation/JavaNativeFoundation.h>2930#import "NS_Java_ConversionUtils.h"31#import "AppleScriptExecutionContext.h"3233//#define DEBUG 1343536/*37* Class: apple_applescript_AppleScriptEngineFactory38* Method: initNative39* Signature: ()V40*/41JNIEXPORT void JNICALL Java_apple_applescript_AppleScriptEngineFactory_initNative42(JNIEnv *env, jclass clazz)43{44return;45}464748/*49* Class: apple_applescript_AppleScriptEngine50* Method: initNative51* Signature: ()V52*/53JNIEXPORT void JNICALL Java_apple_applescript_AppleScriptEngine_initNative54(JNIEnv *env, jclass clazz)55{56return;57}585960/*61* Class: apple_applescript_AppleScriptEngine62* Method: createContextFrom63* Signature: (Ljava/lang/Object;)J64*/65JNIEXPORT jlong JNICALL Java_apple_applescript_AppleScriptEngine_createContextFrom66(JNIEnv *env, jclass clazz, jobject javaContext)67{68NSObject *obj = nil;6970JNF_COCOA_ENTER(env);7172obj = [[JavaAppleScriptEngineCoercion coercer] coerceJavaObject:javaContext withEnv:env];7374#ifdef DEBUG75NSLog(@"converted context: %@", obj);76#endif7778CFRetain(obj);7980JNF_COCOA_EXIT(env);8182return ptr_to_jlong(obj);83}848586/*87* Class: apple_applescript_AppleScriptEngine88* Method: createObjectFrom89* Signature: (J)Ljava/lang/Object;90*/91JNIEXPORT jobject JNICALL Java_apple_applescript_AppleScriptEngine_createObjectFrom92(JNIEnv *env, jclass clazz, jlong nativeContext)93{94jobject obj = NULL;9596JNF_COCOA_ENTER(env);9798obj = [[JavaAppleScriptEngineCoercion coercer] coerceNSObject:(id)jlong_to_ptr(nativeContext) withEnv:env];99100JNF_COCOA_EXIT(env);101102return obj;103}104105106/*107* Class: apple_applescript_AppleScriptEngine108* Method: disposeContext109* Signature: (J)V110*/111JNIEXPORT void JNICALL Java_apple_applescript_AppleScriptEngine_disposeContext112(JNIEnv *env, jclass clazz, jlong nativeContext)113{114115JNF_COCOA_ENTER(env);116117id obj = (id)jlong_to_ptr(nativeContext);118if (obj != nil) CFRelease(obj);119120JNF_COCOA_EXIT(env);121122}123124125/*126* Class: apple_applescript_AppleScriptEngine127* Method: evalScript128* Signature: (Ljava/lang/String;J)J129*/130JNIEXPORT jlong JNICALL Java_apple_applescript_AppleScriptEngine_evalScript131(JNIEnv *env, jclass clazz, jstring ascript, jlong contextptr)132{133id retval = nil;134135JNF_COCOA_ENTER(env);136137NSDictionary *ncontext = jlong_to_ptr(contextptr);138NSString *source = JNFJavaToNSString(env, ascript);139140#ifdef DEBUG141NSLog(@"evalScript(source:\"%@\" context: %@)", source, ncontext);142#endif143144AppleScriptExecutionContext *scriptInvocationCtx = [[[AppleScriptExecutionContext alloc] initWithSource:source context:ncontext] autorelease];145retval = [scriptInvocationCtx invokeWithEnv:env];146147#ifdef DEBUG148NSLog(@"returning: %@", retval);149#endif150151if (retval) CFRetain(retval);152153JNF_COCOA_EXIT(env);154155return ptr_to_jlong(retval);156}157158159/*160* Class: apple_applescript_AppleScriptEngine161* Method: evalScriptFromURL162* Signature: (Ljava/lang/String;J)J163*/164JNIEXPORT jlong JNICALL Java_apple_applescript_AppleScriptEngine_evalScriptFromURL165(JNIEnv *env, jclass clazz, jstring afilename, jlong contextptr)166{167id retval = nil;168169JNF_COCOA_ENTER(env);170171NSDictionary *ncontext = jlong_to_ptr(contextptr);172NSString *filename = JNFJavaToNSString(env, afilename);173174#ifdef DEBUG175NSLog(@"evalScript(filename:\"%@\" context: %@)", filename, ncontext);176#endif177178AppleScriptExecutionContext *scriptInvocationCtx = [[[AppleScriptExecutionContext alloc] initWithFile:filename context:ncontext] autorelease];179retval = [scriptInvocationCtx invokeWithEnv:env];180181#ifdef DEBUG182NSLog(@"returning: %@", retval);183#endif184185if (retval) CFRetain(retval);186187JNF_COCOA_EXIT(env);188189return ptr_to_jlong(retval);190}191192193