| java.lang.Object org.mozilla.javascript.WrapFactory
WrapFactory | public class WrapFactory (Code) | | Embeddings that wish to provide their own custom wrappings for Java
objects may extend this class and call
Context.setWrapFactory(WrapFactory) Once an instance of this class or an extension of this class is enabled
for a given context (by calling setWrapFactory on that context), Rhino
will call the methods of this class whenever it needs to wrap a value
resulting from a call to a Java method or an access to a Java field.
See Also: org.mozilla.javascript.Context.setWrapFactory(WrapFactory) since: 1.5 Release 4 |
Method Summary | |
final public boolean | isJavaPrimitiveWrap() Return false if result of Java method, which is instance of
String , Number , Boolean and
Character , should be used directly as JavaScript primitive
type. | final public void | setJavaPrimitiveWrap(boolean value) | public Object | wrap(Context cx, Scriptable scope, Object obj, Class staticType) Wrap the object.
The value returned must be one of
- java.lang.Boolean
- java.lang.String
- java.lang.Number
- org.mozilla.javascript.Scriptable objects
- The value returned by Context.getUndefinedValue()
- null
Parameters: cx - the current Context for this thread Parameters: scope - the scope of the executing script Parameters: obj - the object to be wrapped. | public Scriptable | wrapAsJavaObject(Context cx, Scriptable scope, Object javaObject, Class staticType) Wrap Java object as Scriptable instance to allow full access to its
methods and fields from JavaScript.
WrapFactory.wrap(Context,Scriptable,Object,Class) and
WrapFactory.wrapNewObject(Context,Scriptable,Object) call this method
when they can not convert javaObject to JavaScript primitive
value or JavaScript array.
Subclasses can override the method to provide custom wrappers
for Java objects.
Parameters: cx - the current Context for this thread Parameters: scope - the scope of the executing script Parameters: javaObject - the object to be wrapped Parameters: staticType - type hint. | public Scriptable | wrapNewObject(Context cx, Scriptable scope, Object obj) Wrap an object newly created by a constructor call. |
isJavaPrimitiveWrap | final public boolean isJavaPrimitiveWrap()(Code) | | Return false if result of Java method, which is instance of
String , Number , Boolean and
Character , should be used directly as JavaScript primitive
type.
By default the method returns true to indicate that instances of
String , Number , Boolean and
Character should be wrapped as any other Java object and
scripts can access any Java method available in these objects.
Use
WrapFactory.setJavaPrimitiveWrap(boolean) to change this.
|
wrap | public Object wrap(Context cx, Scriptable scope, Object obj, Class staticType)(Code) | | Wrap the object.
The value returned must be one of
- java.lang.Boolean
- java.lang.String
- java.lang.Number
- org.mozilla.javascript.Scriptable objects
- The value returned by Context.getUndefinedValue()
- null
Parameters: cx - the current Context for this thread Parameters: scope - the scope of the executing script Parameters: obj - the object to be wrapped. Note it can be null. Parameters: staticType - type hint. If security restrictions prevent to wrapobject based on its class, staticType will be used instead. the wrapped value. |
wrapAsJavaObject | public Scriptable wrapAsJavaObject(Context cx, Scriptable scope, Object javaObject, Class staticType)(Code) | | Wrap Java object as Scriptable instance to allow full access to its
methods and fields from JavaScript.
WrapFactory.wrap(Context,Scriptable,Object,Class) and
WrapFactory.wrapNewObject(Context,Scriptable,Object) call this method
when they can not convert javaObject to JavaScript primitive
value or JavaScript array.
Subclasses can override the method to provide custom wrappers
for Java objects.
Parameters: cx - the current Context for this thread Parameters: scope - the scope of the executing script Parameters: javaObject - the object to be wrapped Parameters: staticType - type hint. If security restrictions prevent to wrapobject based on its class, staticType will be used instead. the wrapped value which shall not be null |
wrapNewObject | public Scriptable wrapNewObject(Context cx, Scriptable scope, Object obj)(Code) | | Wrap an object newly created by a constructor call.
Parameters: cx - the current Context for this thread Parameters: scope - the scope of the executing script Parameters: obj - the object to be wrapped the wrapped value. |
|
|