org.curjent.impl.agent
Class TypeInfo

java.lang.Object
  extended by org.curjent.impl.agent.TypeInfo

final class TypeInfo
extends Object

Information for bytecode generation of an agent's proxy and message classes. The purpose of the "info" classes, such as this one, is to simplify the bytecode generation process. The info classes gather and evaluate information needed to generate the proxy and message classes. This information is based on the agent's list of interfaces and its task type. The "factory" classes use this information to generate the bytecode and create the classes.

The diagram below shows the relationships between the info classes, the agent's interfaces, and the agent's task. For example, a single TypeInfo instance contains zero or more MethodInfo instances. Each MethodInfo instance describes exactly one interface method. And zero or more interface methods map to each task method.

See Also:
MethodInfo, ProxyFactory, Agent.newInstance(AgentLoader, Class[], AgentTasks, Class)

Field Summary
private static AtomicInteger id
          Id generator to ensure uniquely named generated classes.
(package private)  String[] interfaceInternals
          Internal JVM names for the agent's interfaces.
(package private)  Class<?>[] interfaces
          Agent's interfaces.
(package private)  List<MethodInfo> methods
          Information for each unique interface method.
(package private)  int proxyId
          Unique id used to create uniquely named classes.
(package private)  String proxyInternal
          Internal JVM name for the proxy class.
(package private)  String proxyName
          Proxy's class name.
(package private)  String taskInternal
          Internal JVM name for the task type.
(package private)  String taskName
          Task type's name.
(package private)  Class<?> taskType
          Task's class.
 
Constructor Summary
TypeInfo(Class<?>[] interfaces, Class<?> taskType)
          Evaluates and saves the information needed to generate the agent's proxy and message classes.
 
Method Summary
private  Map<String,List<MethodInfo>> evaluateInterfaces()
          Evaluates the agent's interfaces for unique methods.
private  void evaluateMethods()
          Makes one final pass over the evaluated methods.
private  void evaluateTaskType(Map<String,List<MethodInfo>> map)
          Evaluates the agent's task type given the information on the agent's interfaces.
(package private) static String getInternalName(String name)
          Converts a class name to an internal JVM name.
(package private) static String[] getInternalNames(Class<?>[] types)
          Converts an array of class names to their internal JVM names.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

id

private static final AtomicInteger id
Id generator to ensure uniquely named generated classes.


interfaces

Class<?>[] interfaces
Agent's interfaces.


interfaceInternals

String[] interfaceInternals
Internal JVM names for the agent's interfaces. For example, java/lang/Runnable for Runnable.


taskType

Class<?> taskType
Task's class. All of the classes of the agent's tasks must equal or subclass the task type.


taskName

String taskName
Task type's name.

See Also:
Class.getName()

taskInternal

String taskInternal
Internal JVM name for the task type.


proxyId

int proxyId
Unique id used to create uniquely named classes.

See Also:
id

proxyName

String proxyName
Proxy's class name. The proxy's class name is prefixed with the task type's name, and the message class names are prefixed with the proxy class's name. This ensures the proxy and message classes are in the same package as the task's type. This in turn enables the agent designer to use protected and package-private tasks and task methods. The generated names also include the proxy id to ensure unique class names.

See Also:
taskName, proxyId

proxyInternal

String proxyInternal
Internal JVM name for the proxy class.


methods

List<MethodInfo> methods
Information for each unique interface method. This information is used to generate the proxy's methods and associated message classes.

Constructor Detail

TypeInfo

TypeInfo(Class<?>[] interfaces,
         Class<?> taskType)
Evaluates and saves the information needed to generate the agent's proxy and message classes.

Throws:
AgentException - The agent's interfaces and/or task type has an illegal construct, such as incompatible return types, conflicting annotations, etc.
Method Detail

evaluateInterfaces

private Map<String,List<MethodInfo>> evaluateInterfaces()
Evaluates the agent's interfaces for unique methods. Duplicates are skipped. Interface methods are considered duplicates if they have the same name, parameters, and return type.

Each unique interface method is evaluated with an instance of MethodInfo and added to methods.

In addition, a map of method keys to MethodInfo instances is created and returned. The number of MethodInfo instances is equal to the number of unique interface methods, whereas the number of keys may be less. See MethodInfo.getKey(Method) for key generation. See ResultInfo for details on mapping interface methods to task methods.

The keys in the returned map uniquely identify methods by name and parameters, excluding the return type. These keys correspond one-to-one to the task's methods and may number less than the number of interface methods. Associated with each key is a list of one or more unique interface methods (where uniqueness includes not only the interface method's name and parameters, but also its return type).


evaluateTaskType

private void evaluateTaskType(Map<String,List<MethodInfo>> map)
Evaluates the agent's task type given the information on the agent's interfaces. See evaluateInterfaces() for details on the given map argument. This method updates the MethodInfo instances with information on the corresponding task methods.


evaluateMethods

private void evaluateMethods()
Makes one final pass over the evaluated methods.

Throws:
AgentException - At least one interface method is missing a corresponding task method.

getInternalName

static String getInternalName(String name)
Converts a class name to an internal JVM name. For example, converts "java.lang.String" to "java/lang/String".


getInternalNames

static String[] getInternalNames(Class<?>[] types)
Converts an array of class names to their internal JVM names.

See Also:
getInternalName(String)


Copyright 2009-2011 Tom Landon
Apache License 2.0