Dresden OCL Toolkit

tudresden.ocl.check.types
Class ReflectionFacade

java.lang.Object
  extended bytudresden.ocl.check.types.ReflectionFacade
All Implemented Interfaces:
ModelFacade

public class ReflectionFacade
extends Object
implements ModelFacade

ReflectionFacade implements ModelFacade by extracting the required information from compiled Java classes via Java Reflection. The package name where classes are to be found is given as constructor parameter, along with a ReflectionAdapter object that is used to map Java classes to OCL types and vice versa. Classes are then loaded using the standard Java class loader.

While this approach is very flexible, it has some serious drawbacks. Association ends with a multiplicity greater than one are usually represented in Java classes as some Java collection type, e.g. java.util.Vector. Through static examination of the class it is not possible to find out the element type of the OCL collection type that is the result of navigation along this association in an OCL constraint. Hence the iterator type can not be determined whenever the expression contains a call to one of the iterating methods, and type checking will fail unless the iterator type is specifies explicitly.

For the same reason it is not possible to type-check the properties first and last defined for the OCL type Sequence.

Another problem with getting model information through reflection is that the security manager might deny access to non-public fields.

In addition, the mapping of OCL types to Java types is usually not a homomorphism. For further explanation, see the description of the method navigate(String name, Type[] params).

As the result of these restrictions, the class ReflectionFacade can only be used if all iterators and their types are declared explicitly. Additional problems might arise from security restrictions. Additionally, ReflectionFacade provides a default implementation for ReflectionExtender, which simply does nothing.

Author:
Frank Finger
See Also:
ClassAny.navigateParameterized(String name, Type[] params), ReflectionAdapter

Field Summary
protected  HashMap classAnyInstances
          this map is not static since different ReflectionFacades should use their own type representations as these are inner class objects, therefore dependent on their outer objects, which are the ReflectionFacades
private  ReflectionExtender extender
           
(package private)  NameAdapter nameAdapter
           
(package private)  String[] packageNames
           
(package private)  ReflectionAdapter reflAdapter
           
 
Constructor Summary
ReflectionFacade(String[] packageNames, ReflectionAdapter reflAdapter, NameAdapter nameAdapter)
           
ReflectionFacade(String[] packageNames, ReflectionAdapter reflAdapter, NameAdapter nameAdapter, ReflectionExtender extender)
           
 
Method Summary
protected  ClassAny getClassAny(Class c)
           
 Any getClassifier(String name)
           
protected  Class getElementType(Field f)
           
protected  Class getKeyType(Field f)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

packageNames

String[] packageNames

nameAdapter

NameAdapter nameAdapter

reflAdapter

ReflectionAdapter reflAdapter

classAnyInstances

protected HashMap classAnyInstances
this map is not static since different ReflectionFacades should use their own type representations as these are inner class objects, therefore dependent on their outer objects, which are the ReflectionFacades


extender

private ReflectionExtender extender
Constructor Detail

ReflectionFacade

public ReflectionFacade(String[] packageNames,
                        ReflectionAdapter reflAdapter,
                        NameAdapter nameAdapter,
                        ReflectionExtender extender)
Parameters:
packageNames - the names of the Java packages that contain the classes that will be queried for model information, without trailing dot character ("."); null or the empty string denote the root package (containing all classes not assign to a package through Java's package statement); when a class is searched for the package names are tried in their order in the array
reflAdapter - maps OCL types to Java types and vice versa
nameAdapter - maps OCL names to Java names and vice versa; see explanation in NameAdapter documentation

ReflectionFacade

public ReflectionFacade(String[] packageNames,
                        ReflectionAdapter reflAdapter,
                        NameAdapter nameAdapter)
Method Detail

getClassifier

public Any getClassifier(String name)
Specified by:
getClassifier in interface ModelFacade
Parameters:
name - the name of an application type (not the name of a predefined type, like "Integer"), possibly a "::"-separated path name

getClassAny

protected ClassAny getClassAny(Class c)

toString

public String toString()

getElementType

protected Class getElementType(Field f)

getKeyType

protected Class getKeyType(Field f)

Dresden OCL Toolkit

Submit a bug
Developed at the Dresden University of Technology.
This software is published under the GNU Lesser General Public License.