oscript.data
Class JavaClassWrapper

java.lang.Object
  extended byoscript.data.Value
      extended byoscript.data.Type
          extended byoscript.data.JavaClassWrapper
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
BuiltinType, JavaInnerClassWrapper

public class JavaClassWrapper
extends Type

A wrapper for a java class. Types should be intern'd.

Author:
Rob Clark (rob@ti.com)
See Also:
Serialized Form

Nested Class Summary
static class JavaClassWrapper.Base
          For use by test suite...
static class JavaClassWrapper.Derived
           
protected static class JavaClassWrapper.JavaClassWrapperImpl
          Implements the reflection stuff...
 
Field Summary
protected  JavaClassWrapper.JavaClassWrapperImpl impl
           
protected  java.lang.Class javaClass
           
static java.lang.String[] MEMBER_NAMES
           
static java.lang.String PARENT_TYPE_NAME
           
static Value TYPE
          The type object for an script java type.
static java.lang.String TYPE_NAME
           
protected  JavaClassWrapper.JavaClassWrapperImpl wrapperImpl
           
 
Fields inherited from class oscript.data.Type
HIDDEN_TYPE
 
Fields inherited from class oscript.data.Value
DEBUG, NULL, UNDEFINED
 
Constructor Summary
protected JavaClassWrapper(java.lang.Class javaClass)
          Class Constructor.
 
Method Summary
 Value callAsConstructor(StackFrame sf, MemberTable args)
          Call this object as a constructor.
 Value callAsExtends(StackFrame sf, Scope scope, MemberTable args)
          Call this object as a parent class constructor.
 java.lang.Object castToJavaObject()
          Convert this object to a native java Object value.
 java.lang.String castToString()
          Convert this object to a native java String value.
protected  java.lang.Object doConstruct(StackFrame sf, MemberTable args, boolean isWrapper)
           
static java.lang.Class forName(java.lang.String className)
           
 java.lang.ClassLoader getClassLoader()
          Get the ClassLoader object for the java class this class is a wrapper for.
static JavaClassWrapper getClassWrapper(java.lang.Class javaClass)
          The class wrapper instances need to be intern'd, so the types work out right...
static JavaClassWrapper getClassWrapper(java.lang.String className)
           
 Value getMember(int id, boolean exception)
          Get a member of this object.
 java.lang.String getName()
          Convert this object to a native java String value.
protected  Value getTypeImpl()
          Get the type of this object.
protected  Value getTypeMember(Value obj, int id)
          Get a member of this type.
protected  Value getTypeMemberImpl(java.lang.Object javaObj, int id)
           
protected  void init()
          Initialize this object.
 boolean isA(Value type)
          If this object is a type, determine if an instance of this type is an instance of the specified type, ie.
protected  void populateMemberSet(java.util.Set s, boolean debugger)
          Derived classes that implement getMember(int, boolean) should also implement this.
protected  void populateTypeMemberSet(java.util.Set s, boolean debugger)
          Derived classes that implement getTypeMember(oscript.data.Value, int) should also implement this.
 
Methods inherited from class oscript.data.Value
_getTypeMember, _populateTypeMemberSet, bopBitwiseAnd, bopBitwiseAndR, bopBitwiseOr, bopBitwiseOrR, bopBitwiseXor, bopBitwiseXorR, bopCast, bopCastR, bopDivide, bopDivideR, bopEquals, bopEqualsR, bopGreaterThan, bopGreaterThanOrEquals, bopGreaterThanOrEqualsR, bopGreaterThanR, bopInstanceOf, bopInstanceOfR, bopLeftShift, bopLeftShiftR, bopLessThan, bopLessThanOrEquals, bopLessThanOrEqualsR, bopLessThanR, bopLogicalAnd, bopLogicalAndR, bopLogicalOr, bopLogicalOrR, bopMinus, bopMinusR, bopMultiply, bopMultiplyR, bopNotEquals, bopNotEqualsR, bopPlus, bopPlusR, bopRemainder, bopRemainderR, bopSignedRightShift, bopSignedRightShiftR, bopUnsignedRightShift, bopUnsignedRightShiftR, callAsConstructor, callAsConstructor, callAsExtends, callAsExtends, callAsFunction, callAsFunction, callAsFunction, castToBoolean, castToExactNumber, castToInexactNumber, elementAt, elementsAt, getMember, getMember, getMember, getMember, getMember, getMonitor, getType, getTypeMember, length, memberSet, noSuchMember, opAssign, readExternal, toString, unhand, uopBitwiseNot, uopDecrement, uopIncrement, uopLogicalNot, uopMinus, uopPlus, writeExternal
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

javaClass

protected java.lang.Class javaClass

impl

protected transient JavaClassWrapper.JavaClassWrapperImpl impl

wrapperImpl

protected transient JavaClassWrapper.JavaClassWrapperImpl wrapperImpl

TYPE

public static final Value TYPE
The type object for an script java type.


PARENT_TYPE_NAME

public static final java.lang.String PARENT_TYPE_NAME
See Also:
Constant Field Values

TYPE_NAME

public static final java.lang.String TYPE_NAME
See Also:
Constant Field Values

MEMBER_NAMES

public static final java.lang.String[] MEMBER_NAMES
Constructor Detail

JavaClassWrapper

protected JavaClassWrapper(java.lang.Class javaClass)
Class Constructor.

Parameters:
javaClass - the java class this object is a wrapper for
Method Detail

getClassWrapper

public static JavaClassWrapper getClassWrapper(java.lang.Class javaClass)
The class wrapper instances need to be intern'd, so the types work out right... otherwise you might have multiple wrappers per java class (ie type), which would confuse type checking...

Parameters:
javaClass - the java class this object is a wrapper for

getClassWrapper

public static JavaClassWrapper getClassWrapper(java.lang.String className)
                                        throws java.lang.ClassNotFoundException
Throws:
java.lang.ClassNotFoundException

forName

public static java.lang.Class forName(java.lang.String className)
                               throws java.lang.ClassNotFoundException
Throws:
java.lang.ClassNotFoundException

init

protected void init()
Initialize this object. Initialization is done on demand because impl and wrapperImpl are transient, and might not exist if this object gets unserialized...


getTypeImpl

protected Value getTypeImpl()
Get the type of this object. The returned type doesn't have to take into account the possibility of a script type extending a built-in type, since that is handled by Value.getType().

Specified by:
getTypeImpl in class Value
Returns:
the object's type

getName

public java.lang.String getName()
Convert this object to a native java String value.

Returns:
a String value
Throws:
PackagedScriptObjectException(NoSuchMethodException)

isA

public boolean isA(Value type)
If this object is a type, determine if an instance of this type is an instance of the specified type, ie. if this is type, or a subclass.

Overrides:
isA in class Type
Parameters:
type - the type to compare this type to
Returns:
true or false
Throws:
PackagedScriptObjectException(NoSuchMemberException)

castToString

public java.lang.String castToString()
                              throws PackagedScriptObjectException
Convert this object to a native java String value.

Overrides:
castToString in class Value
Returns:
a String value
Throws:
PackagedScriptObjectException(NoSuchMethodException)
PackagedScriptObjectException

castToJavaObject

public java.lang.Object castToJavaObject()
                                  throws PackagedScriptObjectException
Convert this object to a native java Object value.

Overrides:
castToJavaObject in class Value
Returns:
a java object
Throws:
PackagedScriptObjectException(NoSuchMethodException)
PackagedScriptObjectException

callAsConstructor

public Value callAsConstructor(StackFrame sf,
                               MemberTable args)
                        throws PackagedScriptObjectException
Call this object as a constructor.

Overrides:
callAsConstructor in class Value
Parameters:
sf - the current stack frame
args - the arguments to the function, or null if none
Returns:
the newly constructed object
Throws:
PackagedScriptObjectException
See Also:
Function

callAsExtends

public Value callAsExtends(StackFrame sf,
                           Scope scope,
                           MemberTable args)
                    throws PackagedScriptObjectException
Call this object as a parent class constructor.

Overrides:
callAsExtends in class Value
Parameters:
sf - the current stack frame
scope - the object
args - the arguments to the function, or null if none
Returns:
the value returned by the function
Throws:
PackagedScriptObjectException
See Also:
Function

doConstruct

protected java.lang.Object doConstruct(StackFrame sf,
                                       MemberTable args,
                                       boolean isWrapper)

getMember

public Value getMember(int id,
                       boolean exception)
                throws PackagedScriptObjectException
Get a member of this object.

Overrides:
getMember in class Value
Parameters:
id - the id of the symbol that maps to the member
exception - whether an exception should be thrown if the member object is not resolved
Returns:
a reference to the member
Throws:
PackagedScriptObjectException(NoSuchMethodException)
PackagedScriptObjectException(NoSuchMemberException)
PackagedScriptObjectException

getTypeMember

protected Value getTypeMember(Value obj,
                              int id)
Get a member of this type. This is used to interface to the java method of having members be attributes of a type. Regular object- script object's members are attributes of the object, but in the case of java types (including built-in types), the members are attributes of the type.

Overrides:
getTypeMember in class Value
Parameters:
obj - an object of this type
id - the id of the symbol that maps to the member
Returns:
a reference to the member, or null
See Also:
Value.populateTypeMemberSet(java.util.Set, boolean)

getTypeMemberImpl

protected Value getTypeMemberImpl(java.lang.Object javaObj,
                                  int id)

getClassLoader

public java.lang.ClassLoader getClassLoader()
Get the ClassLoader object for the java class this class is a wrapper for.

Returns:
the ClassLoader of the java class

populateMemberSet

protected void populateMemberSet(java.util.Set s,
                                 boolean debugger)
Derived classes that implement getMember(int, boolean) should also implement this.

Overrides:
populateMemberSet in class Value
Parameters:
s - the set to populate
debugger - true if being used by debugger, in which case both public and private/protected field names should be returned
See Also:
getMember(int, boolean)

populateTypeMemberSet

protected void populateTypeMemberSet(java.util.Set s,
                                     boolean debugger)
Derived classes that implement getTypeMember(oscript.data.Value, int) should also implement this.

Overrides:
populateTypeMemberSet in class Value
Parameters:
s - the set to populate
debugger - true if being used by debugger, in which case both public and private/protected field names should be returned
See Also:
getTypeMember(oscript.data.Value, int)