edu.memphis.ccrg.lida.framework.initialization
Class AgentXmlFactory

java.lang.Object
  extended by edu.memphis.ccrg.lida.framework.initialization.AgentXmlFactory
All Implemented Interfaces:
AgentFactory

public class AgentXmlFactory
extends java.lang.Object
implements AgentFactory

Creates and returns a Agent Object based on an XML file. Each module that is created is instantiated using Class.forName(String). Next its Initializable.init() method is run. After all modules have been created in this way, all associated modules are added for each module FullyInitializable.setAssociatedModule(FrameworkModule, String) Finally each module's initializer is run if it has one. Thus associated modules should not be used by the init method of modules, only constants and other variables should be set.

Author:
Javier Snaider, Ryan J. McCall

Nested Class Summary
(package private) static class AgentXmlFactory.TaskData
          Nested class for representing FrameworkTask definition
 
Constructor Summary
AgentXmlFactory()
           
 
Method Summary
(package private) static void associateModules(java.util.List<java.lang.Object[]> toAssoc, FrameworkModule topModule)
          Iterates through the module/associated-module pairs and associates them
 Agent getAgent(java.util.Properties properties)
          Creates and returns a Agent from specified Properties
(package private) static void getAssociatedModules(org.w3c.dom.Element ele, Initializable ini, java.util.List<java.lang.Object[]> toAssoc)
          Gets associated modules of the specified Initializable
(package private) static java.util.Map<java.lang.String,java.lang.Object> getGlobalParameters(org.w3c.dom.Element element)
           
(package private) static void getListener(org.w3c.dom.Element moduleElement, FrameworkModule topModule)
          Reads and creates a listener specified in element.
(package private) static void getListeners(org.w3c.dom.Element element, FrameworkModule topModule)
          Reads and creates all listeners specified in element.
(package private)  FrameworkModule getModule(org.w3c.dom.Element moduleElement, java.util.List<java.lang.Object[]> toAssoc, java.util.List<java.lang.Object[]> toInit, java.util.Map<java.lang.String,TaskSpawner> spawners, java.util.List<AgentXmlFactory.TaskData> toRun)
          Reads and creates a FrameworkModule in specified moduleElement
(package private)  java.util.List<FrameworkModule> getModules(org.w3c.dom.Element element, java.util.List<java.lang.Object[]> toAssoc, java.util.List<java.lang.Object[]> toInit, java.util.Map<java.lang.String,TaskSpawner> spawners, java.util.List<AgentXmlFactory.TaskData> toRun)
          Reads and creates all FrameworkModules in specified element
(package private) static AgentXmlFactory.TaskData getTask(org.w3c.dom.Element moduleElement, java.lang.Integer defaultTicks)
          Reads and creates FrameworkTask specified in element
(package private) static TaskManager getTaskManager(org.w3c.dom.Element element)
           
(package private) static java.util.List<AgentXmlFactory.TaskData> getTasks(org.w3c.dom.Element element, TaskSpawner ts)
          Reads and creates FrameworkTasks specified in element
(package private) static int getTasksDefaultTicksPerRun(org.w3c.dom.Element element)
          Reads the default ticks per run for initial Tasks
(package private) static void getTaskSpawner(org.w3c.dom.Element element, TaskManager tm, java.util.Map<java.lang.String,TaskSpawner> spawners)
          Creates a TaskSpawner from specified Element and TaskManager
(package private) static java.util.Map<java.lang.String,TaskSpawner> getTaskSpawners(org.w3c.dom.Element element, TaskManager tm)
          Reads in and creates all TaskSpawners specified in Element
(package private) static void initializeModules(Agent topModule, java.util.List<java.lang.Object[]> toInit)
          For all modules with an initializer, run the initializer passing in the specific module.
(package private) static void initializeTasks(java.util.Map<ModuleName,FrameworkModule> moduleMap, java.util.List<AgentXmlFactory.TaskData> toRun)
          Creates the tasks specified and adds them to their associated TaskSpawner
(package private)  Agent parseDocument(org.w3c.dom.Document dom)
          Parses the xml document creating the TaskManager, TaskSpawners, Modules, submodules.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AgentXmlFactory

public AgentXmlFactory()
Method Detail

getAgent

public Agent getAgent(java.util.Properties properties)
Description copied from interface: AgentFactory
Creates and returns a Agent from specified Properties

Specified by:
getAgent in interface AgentFactory
Parameters:
properties - Agent properties
Returns:
Constructed Agent object

parseDocument

Agent parseDocument(org.w3c.dom.Document dom)
Parses the xml document creating the TaskManager, TaskSpawners, Modules, submodules. Sets up listeners and associates modules and creates a new Agent.

Parameters:
dom - the xml dom Document
Returns:
the Agent

getGlobalParameters

static java.util.Map<java.lang.String,java.lang.Object> getGlobalParameters(org.w3c.dom.Element element)
Parameters:
element - Element containing the global parameters
Returns:
Map of the global parameters

getTaskManager

static TaskManager getTaskManager(org.w3c.dom.Element element)
Parameters:
element - Element containing the task manager
Returns:
TaskManager

getTaskSpawners

static java.util.Map<java.lang.String,TaskSpawner> getTaskSpawners(org.w3c.dom.Element element,
                                                                   TaskManager tm)
Reads in and creates all TaskSpawners specified in Element

Parameters:
element - Dom element
tm - the TaskManager
Returns:
a Map with all TaskSpawner indexed by name

getTaskSpawner

static void getTaskSpawner(org.w3c.dom.Element element,
                           TaskManager tm,
                           java.util.Map<java.lang.String,TaskSpawner> spawners)
Creates a TaskSpawner from specified Element and TaskManager

Parameters:
element - Dom element
tm - the TaskManager
spawners - The msp of TaskSpawners where the new TaskSpawner is included

getModules

java.util.List<FrameworkModule> getModules(org.w3c.dom.Element element,
                                           java.util.List<java.lang.Object[]> toAssoc,
                                           java.util.List<java.lang.Object[]> toInit,
                                           java.util.Map<java.lang.String,TaskSpawner> spawners,
                                           java.util.List<AgentXmlFactory.TaskData> toRun)
Reads and creates all FrameworkModules in specified element

Parameters:
element - dom element
toAssoc - List of pending associations
toInit - List of pending initializations
spawners - Map of TaskSpawner indexed by name
toRun - List of pending task to run
Returns:
FrameworkModules

getModule

FrameworkModule getModule(org.w3c.dom.Element moduleElement,
                          java.util.List<java.lang.Object[]> toAssoc,
                          java.util.List<java.lang.Object[]> toInit,
                          java.util.Map<java.lang.String,TaskSpawner> spawners,
                          java.util.List<AgentXmlFactory.TaskData> toRun)
Reads and creates a FrameworkModule in specified moduleElement

Parameters:
moduleElement - dom element
toAssoc - List of pending associations
toInit - List of pending initializations
spawners - Map of TaskSpawner indexed by name
toRun - List of pending task to run
Returns:
FrameworkModule

getTasks

static java.util.List<AgentXmlFactory.TaskData> getTasks(org.w3c.dom.Element element,
                                                         TaskSpawner ts)
Reads and creates FrameworkTasks specified in element

Parameters:
element - dom element
ts - the TaskSpawner that will run the tasks
Returns:
a list of FrameworkTasks

getTask

static AgentXmlFactory.TaskData getTask(org.w3c.dom.Element moduleElement,
                                        java.lang.Integer defaultTicks)
Reads and creates FrameworkTask specified in element

Parameters:
moduleElement - dom element
defaultTicks - the default ticks per run for these initial Tasks
Returns:
a TaskData with the data to create the task

getTasksDefaultTicksPerRun

static int getTasksDefaultTicksPerRun(org.w3c.dom.Element element)
Reads the default ticks per run for initial Tasks

Parameters:
element - dom element
Returns:
the default ticks per run or 0 if the 'defaultticksperrun' tag is missing or the value is invalid

getAssociatedModules

static void getAssociatedModules(org.w3c.dom.Element ele,
                                 Initializable ini,
                                 java.util.List<java.lang.Object[]> toAssoc)
Gets associated modules of the specified Initializable

Parameters:
ele - dom element
ini - the Initializable
toAssoc - List of pending associations

getListeners

static void getListeners(org.w3c.dom.Element element,
                         FrameworkModule topModule)
Reads and creates all listeners specified in element.

Parameters:
element - dom element
topModule - the root of the hierarchy of FrameworkModules, in general, an Agent

getListener

static void getListener(org.w3c.dom.Element moduleElement,
                        FrameworkModule topModule)
Reads and creates a listener specified in element.

Parameters:
moduleElement - dom element
topModule - the root of the hierarchy of FrameworkModules, in general, an Agent

associateModules

static void associateModules(java.util.List<java.lang.Object[]> toAssoc,
                             FrameworkModule topModule)
Iterates through the module/associated-module pairs and associates them

Parameters:
toAssoc - List of pending associations
topModule - the root of the hierarchy of FrameworkModules, in general, an Agent

initializeModules

static void initializeModules(Agent topModule,
                              java.util.List<java.lang.Object[]> toInit)
For all modules with an initializer, run the initializer passing in the specific module.

Parameters:
topModule - the root of the hierarchy of FrameworkModules, in general, an Agent
toInit - List of pending initializations

initializeTasks

static void initializeTasks(java.util.Map<ModuleName,FrameworkModule> moduleMap,
                            java.util.List<AgentXmlFactory.TaskData> toRun)
Creates the tasks specified and adds them to their associated TaskSpawner

Parameters:
moduleMap - Map of all FrameworkModule indexed by ModuleName
toRun - list of the FrameworkModule to be created and run