Fields Summary |
---|
protected static final String | CLASS_PATHThe path the Cocoa-Java class files are located at |
private static final String | PF_SCRIPT_SRC |
private final com.apple.cocoa.foundation.NSAppleScript | PF_SCRIPT |
private final boolean | USE_PF |
private static final String | REVEAL_SCRIPT_FORMAT |
private static final String | DEL_SCRIPT_FORMAT |
private int | mainPoolMain NSAutoreleasePool |
protected org.gudy.azureus2.core3.util.AEMonitor | classMon |
private org.gudy.azureus2.core3.util.AEMonitor | scriptMon |
protected boolean | isDisposed |
protected RunnableDispatcher | scriptDispatcher |
Methods Summary |
---|
protected void | dispose(){@inheritDoc}
try
{
classMon.enter();
if(!isDisposed)
{
Debug.outNoStack("Disposing Native PlatformManager...");
NSAutoreleasePool.pop(mainPool);
isDisposed = true;
Debug.outNoStack("Done");
}
}
finally
{
classMon.exit();
}
|
protected final com.apple.cocoa.foundation.NSAppleEventDescriptor | executeScript(java.lang.String scriptFormat, java.lang.Object[] params)Executes a new instance of NSAppleScript
The method is wrapped in an autorelease pool and an AEMonitor. If there are
no format parameters, MessageFormat is not used to parse the format string, and
the format string will be treated as the source itself.
try
{
scriptMon.enter();
int pool = NSAutoreleasePool.push();
long start = System.currentTimeMillis();
String src;
if(params == null || params.length == 0)
{
src = scriptFormat;
}
else
{
src = MessageFormat.format(scriptFormat, params);
}
Debug.outNoStack("Executing: \n" + src);
NSAppleScript scp = new NSAppleScript(src);
NSAppleEventDescriptor result = scp.execute(new NSMutableDictionary());
Debug.outNoStack(MessageFormat.format("Elapsed time: {0}ms\n", new Object[]{new Long(System.currentTimeMillis() - start)}));
NSAutoreleasePool.pop(pool);
return result;
}
finally
{
scriptMon.exit();
}
|
protected final com.apple.cocoa.foundation.NSAppleEventDescriptor | executeScriptWithAsync(java.lang.String scriptFormat, java.lang.Object[] params)Asynchronously executes a new instance of NSAppleScript
This method always returns a "true" event descriptor. Callbacks are currently unsupported
, so in the event of an error, the logger is autuomatically notified.
The thread's runSupport method is wrapped in an autorelease pool. If there are
no format parameters, MessageFormat is not used to parse the format string, and
the format string will be treated as the source itself.
final AERunnable worker = new AERunnable()
{
public void runSupport()
{
int pool = NSAutoreleasePool.push();
long start = System.currentTimeMillis();
String src;
if(params == null || params.length == 0)
{
src = scriptFormat;
}
else
{
src = MessageFormat.format(scriptFormat, params);
}
Debug.outNoStack("Executing: \n" + src);
NSMutableDictionary errorInfo = new NSMutableDictionary();
if(new NSAppleScript(src).execute(errorInfo) == null)
{
Debug.out(String.valueOf(errorInfo.objectForKey(NSAppleScript.AppleScriptErrorMessage)));
//logWarning(String.valueOf(errorInfo.objectForKey(NSAppleScript.AppleScriptErrorBriefMessage)));
}
Debug.outNoStack(MessageFormat.format("Elapsed time: {0}ms\n", new Object[]{new Long(System.currentTimeMillis() - start)}));
NSAutoreleasePool.pop(pool);
}
};
AEThread t = new AEThread("ScriptObject", true)
{
public void runSupport()
{
scriptDispatcher.exec(worker);
}
};
t.setPriority(Thread.NORM_PRIORITY - 1);
t.start();
return NSAppleEventDescriptor.descriptorWithBoolean(true);
|
protected final com.apple.cocoa.foundation.NSAppleEventDescriptor | executeScriptWithNewThread(java.lang.String scriptFormat, java.lang.Object[] params)Executes a new instance of NSAppleScript in a forked AEThread
This method always returns a "true" event descriptor. Callbacks are currently unsupported
, so in the event of an error, the logger is autuomatically notified.
The thread's runSupport method is wrapped in an autorelease pool. If there are
no format parameters, MessageFormat is not used to parse the format string, and
the format string will be treated as the source itself.
Thread worker = new AEThread("ScriptObject", true)
{
public void runSupport()
{
int pool = NSAutoreleasePool.push();
long start = System.currentTimeMillis();
String src;
if(params == null || params.length == 0)
{
src = scriptFormat;
}
else
{
src = MessageFormat.format(scriptFormat, params);
}
Debug.outNoStack("Executing: \n" + src);
NSMutableDictionary errorInfo = new NSMutableDictionary();
if(new NSAppleScript(src).execute(errorInfo) == null)
{
Debug.out(String.valueOf(errorInfo.objectForKey(NSAppleScript.AppleScriptErrorMessage)));
//logWarning(String.valueOf(errorInfo.objectForKey(NSAppleScript.AppleScriptErrorBriefMessage)));
}
Debug.outNoStack(MessageFormat.format("Elapsed time: {0}ms\n", new Object[]{new Long(System.currentTimeMillis() - start)}));
NSAutoreleasePool.pop(pool);
}
};
worker.setPriority(Thread.NORM_PRIORITY - 1);
worker.start();
return NSAppleEventDescriptor.descriptorWithBoolean(true);
|
protected void | finalize(){@inheritDoc}
dispose();
super.finalize();
|
protected boolean | isEnabled(){@inheritDoc}
// simple check with classpath
return System.getProperty("java.class.path").toLowerCase().indexOf(CLASS_PATH) != -1;
|
private void | logWarning(java.lang.String message)Logs a warning message to Logger. The class monitor is used.
try
{
classMon.enter();
Logger.log(new LogAlert(LogAlert.UNREPEATABLE, LogAlert.AT_WARNING, message));
}
finally
{
classMon.exit();
}
|
protected boolean | performRecoverableFileDelete(java.io.File path){@inheritDoc}
if(!path.exists())
return false;
NSAppleEventDescriptor result = executeScriptWithAsync(DEL_SCRIPT_FORMAT, new Object[]{path.getAbsolutePath()});
return (result != null);
|
protected boolean | showInFinder(java.io.File path){@inheritDoc}
if(!path.exists())
return false;
int pool = NSAutoreleasePool.push();
String fb = "Finder";
if(USE_PF)
{
NSAppleEventDescriptor result = PF_SCRIPT.execute(new NSMutableDictionary());
if(result != null && result.booleanValue())
fb = "Path Finder";
}
NSAppleEventDescriptor result = executeScriptWithAsync(REVEAL_SCRIPT_FORMAT, new Object[]{fb, path.getAbsolutePath()});
NSAutoreleasePool.pop(pool);
return (result != null);
|