spark.data.io
Class TypeFactoryReflect

java.lang.Object
  extended by spark.data.io.TypeFactoryReflect
All Implemented Interfaces:
TypeFactory

public class TypeFactoryReflect
extends java.lang.Object
implements TypeFactory

This type factory uses reflection to create SOs that are subclasses of SOReflect. This way objects of various Java classes can be read and written with the class information correctly handled in the external form.

This TypeFactory can restrict objects to come only from a specified list of packages. The goal here is to simplify the type names so they do not need to be fully qualified and also to restrict the kinds of objects that can be created. This prevents a rather simple form of attack whereby an arbitrary object can be generated and then start taking action within the program.

Arrays are still created as SArrays.

Author:
olsen

Constructor Summary
TypeFactoryReflect(java.lang.String[] packages)
          This will construct a new TypeFactoryReflect object.
 
Method Summary
 java.lang.String externalTypeName(SO obj)
          This will return the externalTypeName to be used to represent the object externally.
 SA makeArray()
          SAs are not typed generally.
 SO makeObject(java.lang.String externalTypeName)
          Given an external type name this will create an SO of the correct internal type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TypeFactoryReflect

public TypeFactoryReflect(java.lang.String[] packages)
This will construct a new TypeFactoryReflect object.

Parameters:
packages - these are the only packages from which objects can be generated. Each package must be explicitly named even if it is a subpackage of a package that is already included. If this is null then this will create any object for which there is a fully qualified name that is assignable to SO.
Method Detail

makeObject

public SO makeObject(java.lang.String externalTypeName)
Description copied from interface: TypeFactory
Given an external type name this will create an SO of the correct internal type.

Specified by:
makeObject in interface TypeFactory
Parameters:
externalTypeName - the name used in the external representation for an object type.
Returns:
an empty object ready to be filled. If the externalTypeName is not appropriate for some reason, then null is returned.

makeArray

public SA makeArray()
Description copied from interface: TypeFactory
SAs are not typed generally. The normal implementation is to return an SArray.

Specified by:
makeArray in interface TypeFactory
Returns:
an empty SA ready to be filled.

externalTypeName

public java.lang.String externalTypeName(SO obj)
Description copied from interface: TypeFactory
This will return the externalTypeName to be used to represent the object externally.

Specified by:
externalTypeName in interface TypeFactory
Parameters:
obj - the object whose type is to be represented.
Returns:
the type name to be used. If obj is a legal object that has no external type name, then an empty string is returned. If this object is not acceptable for output, then a null value is returned.