java.lang.Object
org.htmlunit.corejs.javascript.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 calling a Java method or accessing a Java field.- Since:
- 1.5 Release 4
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanReturnfalseif result of Java method, which is instance ofString,Number,BooleanandCharacter, should be used directly as JavaScript primitive type.final voidsetJavaPrimitiveWrap(boolean value) final ObjectWrap the object.final ScriptablewrapAsJavaObject(Context cx, VarScope scope, Object javaObject, Class<?> staticType) wrapAsJavaObject(Context cx, VarScope scope, Object javaObject, TypeInfo staticType) Wrap Java object as Scriptable instance to allow full access to its methods and fields from JavaScript.wrapJavaClass(Context cx, VarScope scope, Class<?> javaClass) Wrap a Java class as Scriptable instance to allow access to its static members and fields and use as constructor from JavaScript.wrapNewObject(Context cx, VarScope scope, Object obj) Wrap an object newly created by a constructor call.
-
Constructor Details
-
WrapFactory
public WrapFactory()
-
-
Method Details
-
wrap
-
wrap
Wrap the object.The value returned must be one of
- java.lang.Boolean
- java.lang.String
- java.lang.Number
- org.htmlunit.corejs.javascript.Scriptable objects
- The value returned by Context.getUndefinedValue()
- null
- Parameters:
cx- the current Context for this threadscope- the scope of the executing scriptobj- the object to be wrapped. Note it can be null.staticType- type hint. It will be used for improving generic support and fallback type when security restrictions prevent wrapping object based on object class- Returns:
- the wrapped value.
- Since:
- 1.9.0
-
wrapNewObject
Wrap an object newly created by a constructor call.- Parameters:
cx- the current Context for this threadscope- the scope of the executing scriptobj- the object to be wrapped- Returns:
- the wrapped value.
-
wrapAsJavaObject
public final Scriptable wrapAsJavaObject(Context cx, VarScope scope, Object javaObject, Class<?> staticType) -
wrapAsJavaObject
public Scriptable wrapAsJavaObject(Context cx, VarScope scope, Object javaObject, TypeInfo staticType) Wrap Java object as Scriptable instance to allow full access to its methods and fields from JavaScript.wrap(Context, VarScope, Object, Class)andwrapNewObject(Context, VarScope, Object)call this method when they can not convertjavaObjectto 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 threadscope- the scope of the executing scriptjavaObject- the object to be wrappedstaticType- type hint. It will be used for improving generic support and fallback type when security restrictions prevent wrapping object based on object class- Returns:
- the wrapped value which shall not be null
- Since:
- 1.9.0
-
wrapJavaClass
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.
- Parameters:
cx- the current Context for this threadscope- the scope of the executing scriptjavaClass- the class to be wrapped- Returns:
- the wrapped value which shall not be null
- Since:
- 1.7R3
-
isJavaPrimitiveWrap
public final boolean isJavaPrimitiveWrap()Returnfalseif result of Java method, which is instance ofString,Number,BooleanandCharacter, should be used directly as JavaScript primitive type. By default the method returns true to indicate that instances ofString,Number,BooleanandCharactershould be wrapped as any other Java object and scripts can access any Java method available in these objects. UsesetJavaPrimitiveWrap(boolean)to change this. -
setJavaPrimitiveWrap
public final void setJavaPrimitiveWrap(boolean value) - See Also:
-