|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
public interface ConversionDelegate
Converts values between types, and provides a measure of the cost of performing such conversion.
Incoming values from the JavaScript engine in the web browser usually require conversion to be able to pass them to Java objects, or to objects of non-Java languages hosted on the JVM. The reason is that the JavaScript language is untyped, and different JavaScript engines represent entities like numeric values differently.
When handling an incoming method call, field access, etc. from
JavaScript via the InvocationDelegate
interface, the Bridge represents incoming values according to the
following rules:
netscape.javascript.JSObject.
The InvocationDelegate will typically call Bridge.convert to coerce values to certain types in preparation
for invoking a method or setting a field; for example, to perform
narrowing conversions on primitive types. The Bridge delegates
this work to the registered ConversionDelegates.
A ConversionDelegate may choose to compute a cost for a particular
conversion and/or perform the conversion, or pass this work on to
the next delegate in the chain. A default ConversionDelegate is
registered and is called last if no other delegate handles the
operation. The default delegate represents types with java.lang.Class instances, and implements the following
conversions:
boolean
java.lang.String
java.lang.String to a numeric value or
boolean; an empty String corresponds to the value false
To avoid creating overdependencies, the exact algorithm and values currently used by the default ConversionDelegate are left unspecified. However, as a hint to other implementors, it uses the following set of rules when computing costs:
| Method Summary | |
|---|---|
int |
conversionCost(Object object,
Object toType)
Computes the cost of converting the given object to the given type. |
boolean |
convert(Object object,
Object toType,
Object[] result)
Converts the given object to the given type. |
| Method Detail |
|---|
int conversionCost(Object object,
Object toType)
java.lang.Object) since different delegates may represent
classes and objects in different ways. A zero or positive
value indicates this delegate can convert the value to the
type. Lower numbers represent better matches. A negative
return value indicates this delegate can not perform the
conversion.
object - the object to converttoType - the type to which to convert the object
boolean convert(Object object,
Object toType,
Object[] result)
throws Exception
conversionCost returns a nonnegative value, although this may
not be possible in all cases; for example, during conversion
of a JavaScript array to a Java primitive array when the JS
array contains an inconvertible value. Should return true if
this delegate handles the conversion; false if it wants to
pass through to the next delegate; and should throw an
exception if it both handles the conversion and the conversion
is illegal.
object - the object to converttoType - the type to which to convert the objectresult - 1-length array into which to store the result of
the conversion, or the original object if it does not require
conversion
Exception - if an exception occurred during conversion
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||