C# Class Rhino.WrapFactory

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.
显示文件 Open project: hazzik/Rhino.Net Class Usage Examples

Public Methods

Method Description
IsJavaPrimitiveWrap ( ) : bool

Return false if result of Java method, which is instance of String, Number, Boolean and Character, should be used directly as JavaScript primitive type.

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 SetJavaPrimitiveWrap(bool) to change this.

SetJavaPrimitiveWrap ( bool value ) : void
Wrap ( Context cx, Scriptable scope, object obj, Type staticType ) : object

Wrap the object.

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
WrapAsJavaObject ( Context cx, Scriptable scope, object javaObject, Type staticType ) : Scriptable

Wrap Java object as Scriptable instance to allow full access to its methods and fields from JavaScript.

Wrap Java object as Scriptable instance to allow full access to its methods and fields from JavaScript.

Wrap(Context, Scriptable, object, System.Type<T>) and 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.

WrapJavaClass ( Context cx, Scriptable scope, Type javaClass ) : Scriptable

Wrap a Java class as Scriptable instance to allow access to its static members and fields and use as constructor from JavaScript.

Wrap a Java class as Scriptable instance to allow access to its static members and fields and use as constructor from JavaScript.

Subclasses can override this method to provide custom wrappers for Java classes.

WrapNewObject ( Context cx, Scriptable scope, object obj ) : Scriptable

Wrap an object newly created by a constructor call.

Wrap an object newly created by a constructor call.

Method Details

IsJavaPrimitiveWrap() public method

Return false if result of Java method, which is instance of String, Number, Boolean and Character, should be used directly as JavaScript primitive type.
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 SetJavaPrimitiveWrap(bool) to change this.
public IsJavaPrimitiveWrap ( ) : bool
return bool

SetJavaPrimitiveWrap() public method

public SetJavaPrimitiveWrap ( bool value ) : void
value bool
return void

Wrap() public method

Wrap the object.
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
public Wrap ( Context cx, Scriptable scope, object obj, Type staticType ) : object
cx Context the current Context for this thread
scope Scriptable the scope of the executing script
obj object the object to be wrapped. Note it can be null.
staticType System.Type /// type hint. If security restrictions prevent to wrap /// object based on its class, staticType will be used instead. ///
return object

WrapAsJavaObject() public method

Wrap Java object as Scriptable instance to allow full access to its methods and fields from JavaScript.
Wrap Java object as Scriptable instance to allow full access to its methods and fields from JavaScript.

Wrap(Context, Scriptable, object, System.Type<T>) and 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.

public WrapAsJavaObject ( Context cx, Scriptable scope, object javaObject, Type staticType ) : Scriptable
cx Context the current Context for this thread
scope Scriptable the scope of the executing script
javaObject object the object to be wrapped
staticType System.Type /// type hint. If security restrictions prevent to wrap /// object based on its class, staticType will be used instead. ///
return Scriptable

WrapJavaClass() public method

Wrap a Java class as Scriptable instance to allow access to its static members and fields and use as constructor from JavaScript.
Wrap a Java class as Scriptable instance to allow access to its static members and fields and use as constructor from JavaScript.

Subclasses can override this method to provide custom wrappers for Java classes.

public WrapJavaClass ( Context cx, Scriptable scope, Type javaClass ) : Scriptable
cx Context the current Context for this thread
scope Scriptable the scope of the executing script
javaClass System.Type the class to be wrapped
return Scriptable

WrapNewObject() public method

Wrap an object newly created by a constructor call.
Wrap an object newly created by a constructor call.
public WrapNewObject ( Context cx, Scriptable scope, object obj ) : Scriptable
cx Context the current Context for this thread
scope Scriptable the scope of the executing script
obj object the object to be wrapped
return Scriptable