|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object sleep.bridges.BridgeUtilities
public class BridgeUtilities
A bridge is a class that bridges your applications API and sleep. Bridges are created using interfaces from the sleep.interfaces package. Arguments are passed to bridges generally in a java.util.Stack form. The Stack of arguments contains sleep Scalar objects. The BridgeUtilities makes it safer and easier for you to extract Java types from arguments.
// some code to execute an internal add function, not a complete example public class MyAddFunction implements Function { public Scalar evaluate(String name, ScriptInstance script, Stack arguments) { if (name.equals("&add")) { int a = BridgeUtilities.getInt(arguments, 0); int b = BridgeUtilities.getInt(arguments, 0); return SleepUtils.getScalar(a + b); } return SleepUtils.getEmptyScalar(); } }
Constructor Summary | |
---|---|
BridgeUtilities()
|
Method Summary | |
---|---|
static boolean |
expectArray(java.lang.String n,
Scalar value)
returns true if value is an array or throws an appropriate exception if value is not an array. |
static java.util.Map |
extractNamedParameters(java.util.Stack args)
extracts all named parameters from the argument stack. |
static Scalar |
flattenArray(Scalar fromValue,
Scalar toValue)
Flattens the specified scalar array. |
static Scalar |
flattenIterator(java.util.Iterator i,
Scalar toValue)
Flattens the specified arrays within the specified iterator. |
static ScalarArray |
getArray(java.util.Stack arguments)
grab a sleep array, if the stack is empty a scalar array with no elements will be returned. |
static java.lang.Class |
getClass(java.util.Stack arguments,
java.lang.Class defaultValue)
grab a class, if the stack is empty the default value will be returned |
static double |
getDouble(java.util.Stack arguments)
grab a double. |
static double |
getDouble(java.util.Stack arguments,
double defaultValue)
grab a double, if the stack is empty the default value will be returned |
static java.io.File |
getFile(java.util.Stack arguments,
ScriptInstance i)
returns a File object from a string argument, the path in the string argument is transformed such that the character / will refer to the correct path separator for the current OS. |
static SleepClosure |
getFunction(java.util.Stack arguments,
ScriptInstance script)
retrieves an executable Function object from the stack. |
static ScalarHash |
getHash(java.util.Stack arguments)
grab a sleep hash, if the stack is empty a scalar hash with no members will be returned. |
static int |
getInt(java.util.Stack arguments)
grab an integer. |
static int |
getInt(java.util.Stack arguments,
int defaultValue)
grab an integer, if the stack is empty the default value will be returned |
static java.util.Iterator |
getIterator(java.util.Stack arguments,
ScriptInstance script)
grabs a scalar iterator, this can come from either an array or a closure called continuously until $null is returned. |
static KeyValuePair |
getKeyValuePair(java.util.Stack arguments)
Pops a Key/Value pair object off of the argument stack. |
static long |
getLong(java.util.Stack arguments)
grab a long. |
static long |
getLong(java.util.Stack arguments,
long defaultValue)
grab a long, if the stack is empty the default value will be returned |
static java.lang.Object |
getObject(java.util.Stack arguments)
grab an object, if the stack is empty then null will be returned. |
static Scalar |
getScalar(java.util.Stack arguments)
grab a scalar, if the stack is empty the empty/null scalar will be returned. |
static java.lang.String |
getString(java.util.Stack arguments,
java.lang.String defaultValue)
grab a string, if the stack is empty or if the value is null the default value will be returned. |
static ScalarArray |
getWorkableArray(java.util.Stack arguments)
grab a sleep array, if the grabbed array is a readonly array, a copy is returned. |
static int |
initLocalScope(ScriptVariables vars,
Variable localLevel,
java.util.Stack locals)
initializes local scope based on argument stack |
static int |
normalize(int value,
int length)
normalizes the index value based on the specified length |
static byte[] |
toByteArrayNoConversion(java.lang.String textz)
converts the specified string to an array of bytes (useful as Sleep stores byte arrays to strings) |
static java.io.File |
toSleepFile(java.lang.String text,
ScriptInstance i)
adjusts the file argument to accomodate for the current working directory |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public BridgeUtilities()
Method Detail |
---|
public static byte[] toByteArrayNoConversion(java.lang.String textz)
public static int getInt(java.util.Stack arguments)
public static int getInt(java.util.Stack arguments, int defaultValue)
public static java.lang.Class getClass(java.util.Stack arguments, java.lang.Class defaultValue)
public static long getLong(java.util.Stack arguments)
public static long getLong(java.util.Stack arguments, long defaultValue)
public static double getDouble(java.util.Stack arguments)
public static double getDouble(java.util.Stack arguments, double defaultValue)
public static java.util.Map extractNamedParameters(java.util.Stack args)
public static java.util.Iterator getIterator(java.util.Stack arguments, ScriptInstance script)
public static ScalarArray getArray(java.util.Stack arguments)
public static ScalarHash getHash(java.util.Stack arguments)
public static ScalarArray getWorkableArray(java.util.Stack arguments)
public static java.lang.Object getObject(java.util.Stack arguments)
public static SleepClosure getFunction(java.util.Stack arguments, ScriptInstance script)
public static Scalar getScalar(java.util.Stack arguments)
public static java.lang.String getString(java.util.Stack arguments, java.lang.String defaultValue)
public static java.io.File toSleepFile(java.lang.String text, ScriptInstance i)
public static java.io.File getFile(java.util.Stack arguments, ScriptInstance i)
public static KeyValuePair getKeyValuePair(java.util.Stack arguments)
public static Scalar flattenArray(Scalar fromValue, Scalar toValue)
public static Scalar flattenIterator(java.util.Iterator i, Scalar toValue)
public static int initLocalScope(ScriptVariables vars, Variable localLevel, java.util.Stack locals)
public static final int normalize(int value, int length)
public static boolean expectArray(java.lang.String n, Scalar value)
n
- the name of the &functionvalue
- the scalar to check
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |