com.ibm.dtfj.analyzer.helpers
Class ValueWrapper

java.lang.Object
  extended by TranslatableAnalyzer
      extended by com.ibm.dtfj.analyzer.base.SimpleAnalyzerBean
          extended by com.ibm.dtfj.analyzer.helpers.ValueWrapper
All Implemented Interfaces:
IAnalyzerBase, IReport, IWrapper
Direct Known Subclasses:
ObjectWrapper

public abstract class ValueWrapper
extends SimpleAnalyzerBean

Utility class to contain the value of an arbitrary Java field or object extracted from the DTFJ image, that corresponds to either an object reference or one of the primitive types.

In methods like JavaField.get() in the DTFJ API, this is sometimes represented as a java.lang.Object that must then be cast explicitly to an instance of JavaObject or Integer, Character, Boolean, etc. But this approach does not provide much flexibility for error handling and compile-time type checking, and it also does not provide a simple mechanism to deal with other common types of objects like java.lang.String, etc.

This utility class attempts to encapsulate this concept and provide a more user-friendly representation. Note however that we cannot ever completely eliminate the need for runtime type checking for this functionality. But at least, encapsulating into a single class should make it more explicit and maintainable.

For completeness, and for use when reading static fields through ObjectWrapper, this class also be used to wrap an instance of JavaClass (though of course that would never be returned from code>JavaField.get())


Constructor Summary
ValueWrapper()
           
 
Method Summary
 boolean equals(java.lang.Object obj)
           
 boolean getBooleanValue()
           
 byte getByteValue()
           
 int getCachingPriority()
          Never cache ValueWrapper objects.
 char getCharacterValue()
           
 double getDoubleValue()
           
 float getFloatValue()
           
 int getIntegerValue()
           
 com.ibm.dtfj.java.JavaClass getJavaClassValue()
           
 com.ibm.dtfj.java.JavaObject getJavaObjectValue()
           
 long getLongValue()
           
 ObjectWrapper getObjectWrapper()
          Convert an instance of ValueWrapper into an ObjectWrapper
 ObjectWrapper getObjectWrapper(java.lang.String wrapperName)
          Convert an instance of ValueWrapper into an arbitrary object wrapper type
 OneJavaClass getOneJavaClassValue()
           
 OneJavaObject getOneJavaObjectValue()
           
 java.lang.Object getRawValue()
          Return the internal value wrapped by this container.
 short getShortValue()
           
 java.lang.String getStringValue()
           
 java.lang.String getTypeSignature()
           
static ValueWrapper getValueWrapperInstance(IAnalyzerContext context, java.lang.Object parent)
          Create a ValueWrapper bean instance associated with a given parent object.
 java.lang.String getVersion()
          Get version information for this analyser.
 int hashCode()
           
 boolean isBoolean()
           
 boolean isByte()
           
 boolean isCharacter()
           
 boolean isDouble()
           
 boolean isFloat()
           
 boolean isInstanceOf(java.lang.String clsname)
          Determin if this value is an instance of a specified class (or any of its subclasses)
 boolean isInteger()
           
 boolean isJavaClass()
           
 boolean isJavaObject()
           
 boolean isLong()
           
 boolean isShort()
           
 boolean isString()
           
 void setParent(java.lang.Object parent)
          Set the parent Object underlying this analyzer bean.
 
Methods inherited from class com.ibm.dtfj.analyzer.base.SimpleAnalyzerBean
allocateReport, allocateReportOptions, allocateSecondaryReport, getCategories, getContext, getIdentityString, getInstance, getLogger, getLongDescription, getName, getNextValidObject, getParent, getReportExtensionHelper, getResourceBundleName, getShortDescription, isPrimaryAnalyzer, printEmbeddedReport, printEmbeddedReport, printEmbeddedReportWithOptions, printEmbeddedReportWithOptions, printReportInfoHeader, produceReport, recordInternalExceptionStatic, setContext
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ValueWrapper

public ValueWrapper()
Method Detail

getCachingPriority

public int getCachingPriority()
Never cache ValueWrapper objects.

Specified by:
getCachingPriority in interface IAnalyzerBase
Overrides:
getCachingPriority in class SimpleAnalyzerBean
Returns:
the caching priority, as a number between 0 and 10
See Also:
SimpleAnalyzerBean.getCachingPriority()

getVersion

public java.lang.String getVersion()
Description copied from interface: IAnalyzerBase
Get version information for this analyser.

Specified by:
getVersion in interface IAnalyzerBase
Overrides:
getVersion in class SimpleAnalyzerBean
Returns:
- a String containing the version information
See Also:
Override the default from SimpleAnalyzerBean ("EXPERIMENTAL"). The version number is typically not defined for small wrappers.

getValueWrapperInstance

public static ValueWrapper getValueWrapperInstance(IAnalyzerContext context,
                                                   java.lang.Object parent)
Create a ValueWrapper bean instance associated with a given parent object.

This method actually creates a subclass of ValueWrapper, of the type specified in the option "com.ibm.dtfj.analyzer.helpers.ValueWrapper.actualClass".

Parameters:
context - the AnalyzerContext in which to locate this bean instance
parent - the parent Object underlying this analyzer bean
Returns:
the desired ValueWrapper analyzer bean

getObjectWrapper

public ObjectWrapper getObjectWrapper()
Convert an instance of ValueWrapper into an ObjectWrapper

Returns:
the resulting ObjectWrapper (might be the same object as the original ValueWrapper, or a different instance)

getObjectWrapper

public ObjectWrapper getObjectWrapper(java.lang.String wrapperName)
Convert an instance of ValueWrapper into an arbitrary object wrapper type

Parameters:
wrapperName - the name of an analyzer to use as a wrapper for this value (must be a subclass of ObjectWrapper)
Returns:
the resulting wrapper, as an ObjectWrapper or a subclass as specified by wrapperName (might be the same object as the original ValueWrapper, or a different instance)

setParent

public void setParent(java.lang.Object parent)
Set the parent Object underlying this analyzer bean.

Specified by:
setParent in interface IWrapper
Overrides:
setParent in class SimpleAnalyzerBean
Parameters:
parent - The parent object to set. Must be of type JavaMethod. compatible with the type of analyzer bean that receives it
See Also:
IWrapper.setParent(java.lang.Object)

isJavaObject

public final boolean isJavaObject()
Returns:
true if this container contains a JavaObject

getJavaObjectValue

public final com.ibm.dtfj.java.JavaObject getJavaObjectValue()
                                                      throws com.ibm.dtfj.image.DTFJException
Returns:
the value of this container as a JavaObject
Throws:
com.ibm.dtfj.image.DTFJException - if this container does not contain a JavaObject

getOneJavaObjectValue

public final OneJavaObject getOneJavaObjectValue()
                                          throws com.ibm.dtfj.image.DTFJException
Returns:
the value of this container as a OneJavaObject
Throws:
com.ibm.dtfj.image.DTFJException - if this container does not contain a JavaObject

isJavaClass

public final boolean isJavaClass()
Returns:
true if this container contains a JavaClass

getJavaClassValue

public final com.ibm.dtfj.java.JavaClass getJavaClassValue()
                                                    throws com.ibm.dtfj.image.DTFJException
Returns:
the value of this container as a JavaClass
Throws:
com.ibm.dtfj.image.DTFJException - if this container does not contain a JavaClass

getOneJavaClassValue

public final OneJavaClass getOneJavaClassValue()
                                        throws com.ibm.dtfj.image.DTFJException
Returns:
the value of this container as a OneJavaClass
Throws:
com.ibm.dtfj.image.DTFJException - if this container does not contain a JavaClass

isString

public boolean isString()
Returns:
true if this wrapper is representing a String value

getStringValue

public java.lang.String getStringValue()
                                throws com.ibm.dtfj.image.DTFJException
Returns:
the value of this container as a String
Throws:
com.ibm.dtfj.image.DTFJException - if this container does not contain a valid String

isInteger

public boolean isInteger()
Returns:
true if this wrapper is representing an Integer value

getIntegerValue

public int getIntegerValue()
                    throws com.ibm.dtfj.image.DTFJException
Returns:
the value of this container as an int
Throws:
com.ibm.dtfj.image.DTFJException - if this container does not contain a valid Integer

isBoolean

public boolean isBoolean()
Returns:
true if this wrapper is representing a Boolean value

getBooleanValue

public boolean getBooleanValue()
                        throws com.ibm.dtfj.image.DTFJException
Returns:
the value of this container as a boolean
Throws:
com.ibm.dtfj.image.DTFJException - if this container does not contain a valid Boolean

isLong

public boolean isLong()
Returns:
true if this wrapper is representing a Long value

getLongValue

public long getLongValue()
                  throws com.ibm.dtfj.image.DTFJException
Returns:
the value of this container as a long
Throws:
com.ibm.dtfj.image.DTFJException - if this container does not contain a valid Long

isByte

public boolean isByte()
Returns:
true if this wrapper is representing a Byte value

getByteValue

public byte getByteValue()
                  throws com.ibm.dtfj.image.DTFJException
Returns:
the value of this container as a byte
Throws:
com.ibm.dtfj.image.DTFJException - if this container does not contain a valid Byte

isCharacter

public boolean isCharacter()
Returns:
true if this wrapper is representing a Character value

getCharacterValue

public char getCharacterValue()
                       throws com.ibm.dtfj.image.DTFJException
Returns:
the value of this container as a char
Throws:
com.ibm.dtfj.image.DTFJException - if this container does not contain a valid Character

isDouble

public boolean isDouble()
Returns:
true if this wrapper is representing a Double value

getDoubleValue

public double getDoubleValue()
                      throws com.ibm.dtfj.image.DTFJException
Returns:
the value of this container as a double
Throws:
com.ibm.dtfj.image.DTFJException - if this container does not contain a valid Double

isFloat

public boolean isFloat()
Returns:
true if this wrapper is representing a Float value

getFloatValue

public float getFloatValue()
                    throws com.ibm.dtfj.image.DTFJException
Returns:
the value of this container as a float
Throws:
com.ibm.dtfj.image.DTFJException - if this container does not contain a valid Float

isShort

public boolean isShort()
Returns:
true if this wrapper is representing a Short value

getShortValue

public short getShortValue()
                    throws com.ibm.dtfj.image.DTFJException
Returns:
the value of this container as a short
Throws:
com.ibm.dtfj.image.DTFJException - if this container does not contain a valid Float

getTypeSignature

public java.lang.String getTypeSignature()
Returns:
the type signature for the value contained in this container (as a String)

isInstanceOf

public boolean isInstanceOf(java.lang.String clsname)
Determin if this value is an instance of a specified class (or any of its subclasses)

Parameters:
clsname - the class name to check
Returns:
true if this value is an instance of clsname, false otherwise

equals

public boolean equals(java.lang.Object obj)
See Also:
Object.equals(java.lang.Object)

hashCode

public int hashCode()
See Also:
Object.hashCode()

getRawValue

public java.lang.Object getRawValue()
Return the internal value wrapped by this container. Could be a JavaObject, a JavaClass or anything else. This method is used to get a reference key suitable to use in report references, and internally for comparing containers in .equals().

Returns:
the internal value wrapped by this container


© Copyright IBM Corp. 2007, 2008 All Rights Reserved. US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.