public final class JaplScript extends Object
Modifier and Type | Method | Description |
---|---|---|
static void |
addGlobalAspect(Aspect aspect) |
|
static void |
addType(Codec<?> type) |
|
static <T> T |
cast(Class<T> interfaceClass,
boolean useMostSpecificSubClass,
Reference reference) |
Creates a suitable Java instance or dynamic proxy for the given
Reference . |
static <T> T |
cast(Class<T> interfaceClass,
Reference reference) |
Casts a reference to a specific Java class.
|
static <T> T |
getApplication(Class<T> interfaceClass,
String applicationName) |
Gets the application object for an application.
|
static List<Aspect> |
getGlobalAspects() |
|
static Property |
getProperty(Reference reference,
TypeClass typeClass,
String name) |
|
static <T> T |
getScriptingAddition(Class<T> interfaceClass,
String scriptingAdditionName) |
Gets the scripting addition object for a scripting addition.
|
static String |
getStandardJavaType(String applescriptType) |
|
static List<Codec<?>> |
getTypes() |
|
static <T> Class<? extends T> |
guessMostSpecificSubclass(Class<T> interfaceClass,
Reference reference) |
For a given reference, guess the most specific Java interface class, which is
identical to the given interface class or one of its subclasses.
|
static TypeClass |
internTypeClass(TypeClass typeClass) |
Lookup a
TypeClass instance declared in a CLASS
field of a generated class/interface. |
static String |
quote(String s) |
Quotes the string to make it usable for AppleScript.
|
static boolean |
removeGlobalAspect(Aspect aspect) |
|
static boolean |
removeType(Codec<?> type) |
|
static Session |
startSession() |
Starts a session.
|
public static void addGlobalAspect(Aspect aspect)
public static boolean removeGlobalAspect(Aspect aspect)
public static void addType(Codec<?> type)
public static boolean removeType(Codec<?> type)
public static Session startSession()
public static <T> T getApplication(Class<T> interfaceClass, String applicationName)
T
- tinterfaceClass
- interface classapplicationName
- application name, e.g. "iTunes" or "Music"public static <T> T getScriptingAddition(Class<T> interfaceClass, String scriptingAdditionName)
T
- tinterfaceClass
- interface classscriptingAdditionName
- scripting addition name, e.g. "StandardAdditions"public static TypeClass internTypeClass(TypeClass typeClass)
TypeClass
instance declared in a CLASS
field of a generated class/interface.typeClass
- typeClass to use as lookup keypublic static Property getProperty(Reference reference, TypeClass typeClass, String name)
public static <T> Class<? extends T> guessMostSpecificSubclass(Class<T> interfaceClass, Reference reference)
This method is expected to not cause an AppleScript round trip, but instead guess the correct type based on the given reference object. It takes advantage of the fact that most references' object reference (or Object Specifier) starts with the object's class name, either as chevron encoded code or plain text name. This is typically how object specifiers are returned from an AppleScript call.
So, if the object reference starts with a class name that is translated to a Java class that happens to be identical to the given Java interface class or one of its subclasses, we assume it's the correct class.
Note that this is not a perfect mapping, as object references can be free-form AppleScripts (but usually aren't, especially when returned from the scripting engine).
T
- Java interface type paraminterfaceClass
- Java interface classreference
- AppleScript referencepublic static <T> T cast(Class<T> interfaceClass, Reference reference)
T
- target typeinterfaceClass
- interface classreference
- reference to cast to interface classpublic static <T> T cast(Class<T> interfaceClass, boolean useMostSpecificSubClass, Reference reference)
Reference
.T
- target typeinterfaceClass
- interface classuseMostSpecificSubClass
- attempt to create an instance of the most specific subclass of interfaceClass
that is still suitable for the given referencereference
- reference to create a Java instance forpublic static String quote(String s)
s
- string