org.talika.tarsis.command.factory.xml
Class XmlCommandFactory

java.lang.Object
  extended by org.talika.tarsis.service.AbstractService
      extended by org.talika.tarsis.command.factory.CommandFactoryService
          extended by org.talika.tarsis.command.factory.xml.XmlCommandFactory
All Implemented Interfaces:
CommandFactory, Service

public final class XmlCommandFactory
extends CommandFactoryService

XML based implementation of CommandFactory interface.

It reads command definitions from an XML file. It supports multiple definitions files stored in a package directory, typically /WEB-INF/packages/.

File name is considered to be package name and to have all commands of a single package.
Commands packages are loaded on demand when they are invoked. When a command is lodaded is initialized and its action is put into service.

Version:
$Revision: 269 $
Author:
Jose M. Palomar
See Also:
XmlCommandsFactory

Field Summary
static java.lang.String PACKAGE_EXTENSION
          Default package file extension.
static java.lang.String PACKAGES_DIR
          Default directory for package files.
 
Constructor Summary
XmlCommandFactory()
          Creates a new XmlCommandFactory object.
 
Method Summary
 void destroy()
          Called by the framework to indicate that is being placed out of service.
 java.lang.String getName()
          Service name.
 java.lang.String getPackakesDir()
          Returns packages directory.
 void init(Context context)
          Called by the framework to indicate that is being placed into service.
protected  void loadCommand(java.lang.String commandName)
          Tries to load command definition from repository for a given name.
protected  void loadPackage(java.lang.String packageName)
          Tries to load all command definitions from repository for a given package.
protected  java.util.Map loadXmlPackage(org.xml.sax.InputSource input)
          Loads command definitions from an XML source.
 void setPackagesDir(java.lang.String packagesDir)
          Sets packages directory.
 
Methods inherited from class org.talika.tarsis.command.factory.CommandFactoryService
addCommand, addCommands, findCommand
 
Methods inherited from class org.talika.tarsis.service.AbstractService
getContext, getLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PACKAGES_DIR

public static final java.lang.String PACKAGES_DIR
Default directory for package files.

See Also:
Constant Field Values

PACKAGE_EXTENSION

public static final java.lang.String PACKAGE_EXTENSION
Default package file extension.

See Also:
Constant Field Values
Constructor Detail

XmlCommandFactory

public XmlCommandFactory()
Creates a new XmlCommandFactory object.

Method Detail

init

public void init(Context context)
          throws ServiceException
Called by the framework to indicate that is being placed into service.

Initialization secuence:
  1. Call super init method.
  2. Checks if packagesDir is set if not sets its value to PACKAGES_DIR.
  3. Obtains Logger instance from context.
  4. Initializes packsLoaded to an empty Set.

Specified by:
init in interface Service
Overrides:
init in class AbstractService
Parameters:
context - Context context that initialized service.
Throws:
ServiceException - if an exception has occurred that interferes with the services's normal operation
See Also:
Service.init(Context)

destroy

public void destroy()
Called by the framework to indicate that is being placed out of service.
Destroy secuence:
  1. Clears packsLoaded.
  2. Call super destroy method.

Specified by:
destroy in interface Service
Overrides:
destroy in class AbstractService
See Also:
Service.destroy()

getName

public java.lang.String getName()
Service name.

Specified by:
getName in interface Service
Specified by:
getName in class AbstractService
Returns:
String service name.
See Also:
Service.getName()

loadCommand

protected void loadCommand(java.lang.String commandName)
Tries to load command definition from repository for a given name.

Loading a command causes loading its entire package.

Specified by:
loadCommand in class CommandFactoryService
Parameters:
commandName - String name of command to load.

loadPackage

protected void loadPackage(java.lang.String packageName)
Tries to load all command definitions from repository for a given package.
Packages are loaded only once.

Specified by:
loadPackage in class CommandFactoryService
Parameters:
packageName - String name for package to load.

loadXmlPackage

protected java.util.Map loadXmlPackage(org.xml.sax.InputSource input)
Loads command definitions from an XML source.

Parameters:
input - InputSource XML source.
Returns:
Map a map with all package commands or null if something wrong happens parsing XML source.

getPackakesDir

public java.lang.String getPackakesDir()
Returns packages directory.

Returns:
String packages directory.

setPackagesDir

public void setPackagesDir(java.lang.String packagesDir)
Sets packages directory.

Parameters:
packagesDir - String sets packages directory.


Copyright © 2002-2012 Talika Open Source Group. All Rights Reserved.