com.ibm.dtfj.analyzer.helpers.objectwrapper
Class ObjectWrapperCollection

java.lang.Object
  extended by TranslatableAnalyzer
      extended by com.ibm.dtfj.analyzer.base.SimpleAnalyzerBean
          extended by com.ibm.dtfj.analyzer.base.CollectionAnalyzerBase
              extended by com.ibm.dtfj.analyzer.helpers.objectwrapper.ObjectWrapperCollection
All Implemented Interfaces:
IAnalyzerBase, IReport, IWrapper, java.lang.Iterable, java.util.Collection
Direct Known Subclasses:
ListClassDefinitions, ListObjectInstances, ListObjectInstancesWithSubClasses, ObjectNavigatorCollection

public class ObjectWrapperCollection
extends CollectionAnalyzerBase

Keep track of a collection of one or multiple instances of a given class, and provide utility functions to print the values of various fields directly or indirectly pointed to by each of these instances (using ObjectWrapper to use XPath like syntax to follow a chain of references).


Field Summary
static int INDEX_ALL_EQUAL
          Special index value to indicate that, when reading some field out of all the instances contained in this collection, we should verify that the value of the field is identical in every instance (throw an exception if the value are not all identical).
static int INDEX_ALL_INSTANCES
          Special index value to indicate that, when printing some field out of all the instances contained in this collection, we should iterate over all instances and print the corresponding field from each instance.
static int INDEX_SINGLETON
          Special index value to indicate that the collection should represent a singleton; an exception should be thrown when attempting to access any instances from that collection if there is more than one instance.
 
Constructor Summary
ObjectWrapperCollection()
          Null constructor for use as JavaBean
 
Method Summary
 java.lang.Object get(int index)
          Get one particular object instance from the collection represented by this ObjectWrapperCollection.
 int getCachingPriority()
          Avoid caching ObjectWrapperCollection objects (there are too many of them, and they are cheap to re-create)
static ObjectWrapperCollection getClassDefinitions(IAnalyzerContext context, java.lang.String className)
          Find the ObjectWrapperCollection bean instance with all the definitions of a given class (for access to static class variables).
static ObjectWrapperCollection getObjectInstances(IAnalyzerContext context, java.lang.String className)
          Find the ObjectWrapperCollection bean instance with all the instances of a given class.
static ObjectWrapperCollection getObjectInstancesWithSubClasses(IAnalyzerContext context, java.lang.String className)
          Find the ObjectWrapperCollection bean instance with all the instances of a given class as well as all instances of subclasses of the given class.
 ObjectWrapper getObjectWrapper(int index)
          Return an ObjectWrapper for a given object instance in the collection.
 ObjectWrapper getObjectWrapper(int index, java.lang.String wrapperName)
          Return a wrapper for a given object instance in the collection.
 ObjectWrapper getValueAtPath(java.lang.String path, int index)
          Return the object found at the end of a sequence of field references, starting with a given object instance in the collection.
 java.lang.String getVersion()
          Get version information for this analyser.
 java.util.Iterator iterator()
           
 void printReportAtPath(IAnalysisReport out, java.lang.String label, java.lang.String path, java.lang.String analyzerName, int index)
          Print a report for every object found at the end of a sequence of field references, starting with a given object instance or all instances in the collection.
 void printValueAtPath(IAnalysisReport out, java.lang.String label, java.lang.String path, int index)
          Print the object or value found at the end of a sequence of field references, starting with a given object instance or all instances in the collection.
 IAnalysisReport produceReport()
          Generate a report which will be encapsulated in the IAnalysisReport object for later use by some formatter.
 void setParent(java.lang.Object parent)
          Set the parent underlying this analyzer bean.
 int size()
           
 
Methods inherited from class com.ibm.dtfj.analyzer.base.CollectionAnalyzerBase
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
 
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, recordInternalExceptionStatic, setContext
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

INDEX_SINGLETON

public static final int INDEX_SINGLETON
Special index value to indicate that the collection should represent a singleton; an exception should be thrown when attempting to access any instances from that collection if there is more than one instance.

See Also:
Constant Field Values

INDEX_ALL_EQUAL

public static final int INDEX_ALL_EQUAL
Special index value to indicate that, when reading some field out of all the instances contained in this collection, we should verify that the value of the field is identical in every instance (throw an exception if the value are not all identical).

See Also:
Constant Field Values

INDEX_ALL_INSTANCES

public static final int INDEX_ALL_INSTANCES
Special index value to indicate that, when printing some field out of all the instances contained in this collection, we should iterate over all instances and print the corresponding field from each instance.

See Also:
Constant Field Values
Constructor Detail

ObjectWrapperCollection

public ObjectWrapperCollection()
Null constructor for use as JavaBean

Method Detail

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.

getObjectInstances

public static ObjectWrapperCollection getObjectInstances(IAnalyzerContext context,
                                                         java.lang.String className)
Find the ObjectWrapperCollection bean instance with all the instances of a given class. (create it if necessary)

Parameters:
context - the AnalyzerContext in which to locate this bean instance
className - the class name for the instances in this collection
Returns:
the desired ObjectWrapperCollection analyzer bean

getObjectInstancesWithSubClasses

public static ObjectWrapperCollection getObjectInstancesWithSubClasses(IAnalyzerContext context,
                                                                       java.lang.String className)
Find the ObjectWrapperCollection bean instance with all the instances of a given class as well as all instances of subclasses of the given class. (create it if necessary)

Parameters:
context - the AnalyzerContext in which to locate this bean instance
className - the class name for the instances in this collection
Returns:
the desired ObjectWrapperCollection analyzer bean

getClassDefinitions

public static ObjectWrapperCollection getClassDefinitions(IAnalyzerContext context,
                                                          java.lang.String className)
Find the ObjectWrapperCollection bean instance with all the definitions of a given class (for access to static class variables). (create it if necessary)

Parameters:
context - the AnalyzerContext in which to locate this bean instance
className - the class name for the class definitions in this collection
Returns:
the desired ObjectWrapperCollection analyzer bean

getCachingPriority

public int getCachingPriority()
Avoid caching ObjectWrapperCollection objects (there are too many of them, and they are cheap to re-create)

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()

setParent

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

Specified by:
setParent in interface IWrapper
Overrides:
setParent in class SimpleAnalyzerBean
Parameters:
parent - The parent object to set. Must be a string describing the class name of the objects underlying this collection.
See Also:
IWrapper.setParent(java.lang.Object)

getObjectWrapper

public ObjectWrapper getObjectWrapper(int index)
                               throws com.ibm.dtfj.image.DTFJException,
                                      java.lang.IllegalArgumentException
Return an ObjectWrapper for a given object instance in the collection. This version unconditionally returns a true ObjectWrapper, not a subclass of ObjectWrapper.

Parameters:
index - the index of the instance in the collection from which we want to read field, or one of the special index values for special functions (e.g. INDEX_SINGLETON, etc.)
Returns:
the desired instance, as an ObjectWrapper
Throws:
com.ibm.dtfj.image.DTFJException - if the desired instance cannot be found
java.lang.IllegalArgumentException - if the index argument is invalid

getObjectWrapper

public ObjectWrapper getObjectWrapper(int index,
                                      java.lang.String wrapperName)
                               throws com.ibm.dtfj.image.DTFJException,
                                      java.lang.IllegalArgumentException
Return a wrapper for a given object instance in the collection.

Parameters:
index - the index of the instance in the collection from which we want to read field, or one of the special index values for special functions (e.g. INDEX_SINGLETON, etc.)
wrapperName - the name of an analyzer to use as a wrapper for this value (must be a subclass of ObjectWrapper)
Returns:
the desired instance, as an ObjectWrapper or a subclass as specified by wrapperName
Throws:
com.ibm.dtfj.image.DTFJException - if the desired instance cannot be found
java.lang.IllegalArgumentException - if the index argument is invalid

get

public java.lang.Object get(int index)
                     throws java.lang.IllegalStateException,
                            java.lang.IllegalArgumentException
Get one particular object instance from the collection represented by this ObjectWrapperCollection. This method is similar to getObjectWrapper(int) but it parallels the signature of the method in the List interface. In particular, it does not throw DTFJException; it throws IllegalStateException instead (a runtime exception).

Parameters:
index - the index of the instance in the collection from which we want to read field, or one of the special index values for special functions (e.g. INDEX_SINGLETON, etc.)
Returns:
the desired instance, as an ObjectWrapper
Throws:
java.lang.IllegalStateException - if the desired instance cannot be found
java.lang.IllegalArgumentException - if the index argument is invalid

getValueAtPath

public ObjectWrapper getValueAtPath(java.lang.String path,
                                    int index)
                             throws com.ibm.dtfj.image.DTFJException
Return the object found at the end of a sequence of field references, starting with a given object instance in the collection.

Parameters:
path - a path-like string that represents the sequence of field names, separated by "/"
index - the index of the instance in the collection from which we want to read field, or one of the special index values for special functions (e.g. INDEX_SINGLETON, etc.)
Returns:
the value of the field, as a ObjectWrapper
Throws:
com.ibm.dtfj.image.DTFJException - if the index is invalid or the collection contains no instances or the field does not exist

printValueAtPath

public void printValueAtPath(IAnalysisReport out,
                             java.lang.String label,
                             java.lang.String path,
                             int index)
Print the object or value found at the end of a sequence of field references, starting with a given object instance or all instances in the collection.

Parameters:
out - a AnalysisReport object to which to write the output
label - a name to use for this field in the report
path - a path-like string that represents the sequence of field names, separated by "/"
index - the index of the instance in the collection from which we want to read field, or one of the special index values for special functions (e.g. INDEX_SINGLETON, etc.)

printReportAtPath

public void printReportAtPath(IAnalysisReport out,
                              java.lang.String label,
                              java.lang.String path,
                              java.lang.String analyzerName,
                              int index)
Print a report for every object found at the end of a sequence of field references, starting with a given object instance or all instances in the collection.

This method loads a specified analyzer and invokes its produceReport() method on the target object to generate a new report, which is then embedded in the main report.

Parameters:
out - a AnalysisReport object to which to write the output
label - a name to use as title for the report being generated
path - a path-like string that represents the sequence of field names, separated by "/"
analyzerName - the name of an analyzer that should generate the report to be printed
index - the index of the instance in the collection from which we want to read field, or one of the special index values for special functions (e.g. INDEX_SINGLETON, etc.)

iterator

public java.util.Iterator iterator()
Specified by:
iterator in interface java.lang.Iterable
Specified by:
iterator in interface java.util.Collection
Specified by:
iterator in class CollectionAnalyzerBase
See Also:
Collection.iterator()

size

public int size()
Specified by:
size in interface java.util.Collection
Specified by:
size in class CollectionAnalyzerBase
See Also:
Collection.size()

produceReport

public IAnalysisReport produceReport()
Description copied from interface: IReport
Generate a report which will be encapsulated in the IAnalysisReport object for later use by some formatter.

Specified by:
produceReport in interface IReport
Overrides:
produceReport in class SimpleAnalyzerBean
Returns:
- the generic report object which will be given to some formatter
See Also:
IReport.produceReport()


© 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.