Document No .: PT-TR-Configuration
PTF3 configuration management manual
PTF3 Configuration Architect Document
V3.0
Initial version release time: 2004/06/01
Peng Tian Information System (Beijing) Co., Ltd.
Technology research and development
table of Contents
Basic information ... 3
Features ... 4
Technology background ... 4
Interface range ... 4
API description ... 5
Precautions ... 5
Development and test instance ... 5
HashMap-based configuration data container ... 5
XML file-based configuration management ... 6
AbstractManagerAgent instance (as an example of Command) 6
AbstractMappingLoad instance (as an example of Command) 8
AbstractParse instance (as an example of Command) 11
Properties file-based configuration management ... 12
AbstractManagerAgent instance (as an example of Velocity) 12
AbstractMappingLoad instance (as an example of Velocity) 13
AbstractParse instance (as an example of Velocity) 15
Test instance ... 17
Basic Information
Document Description Information:
file name:
PTF3 Configuration Normative Document
The latest version of:
V3.0
Document creator:
Peng Tian Company Technology R & D Department
Document maintenance:
Organization: Peng Tian Company Technology Research and Development Department
Member: Era, Chen Yonghui, take people
Document reviewer:
Peng Tian Company Technology Research Department, Xi'an Local Tax Project Group
Date of order:
2004-06-01
Document goal:
This document describes the technical details of PTF3 COFIGURATION from the perspective of theory, concept, feature, and instance, and the interface and use.
Document modification summary:
version
date
Modify description
Author
V3.0
2004-06-01
PTF3 COFIGURATION Normative Documentation
Original force
PTF Configuration is the new core of PTF3, which uses plugin technology to expand and manage the Configuration, and Configuration mainly includes:
A global registry:
Registery
Three parent classes:
AbstractMappingAgent
AbstractMappingLoad
AbstractMappingParse
A container specification:
XXXXABLE EXTENDS HASHMAP
Through the inheritance and implementation of three parent classes, as well as custom Configuration data containers, you can manage the corresponding configuration items to the registry while providing targeted queries and access methods.
Features
1. Configuration's data is managed by the registry
2, configuration is a list of orders, its resident memory
3. Configuration is managed by the core cfgmapping manager to manage the extended configuration plugin
4. Configuration supports management methods for shaped profiles, such as XML, Properties, TXT and other files.
5. Configuration allows the integrity check of parsing files, valid for XML files
6. Configuration supports access to files for various storage methods, such as directory, files, compressed files, streams, etc.
7. Configuration can use a tree structure file system to populate the specific mapping container, such as a file tree in a JAR in file.
8. Single elements stored in Configuration must be unique
9. Configuration provides an expandable registry lookup method
technical background
Configuration is an open architecture system that can also say that Configuration is a core component of an architecture system because in an open institution, various components are directly relatively independent, they are actually configurable. Configuration Manager interands. This is the core of Configuration: An assembly is an extensible frame structure that is organized by a configurer. Configuration used two technologies used in PTF2:
1. Maping container This method is managing a list of mapping in memory, equivalent to registry, press Domain to store registration items in this registry, and this concept is perfect, but in implementation, due to hardcoding Causes the expansion and access difficulties of Configuration, configure is limited to a small application level.
2. JMX Configuration has fully used JMX in PTF2 to implement Configuration in accordance with JMX specifications. Although various properties of dynamic management configuration objects, it is abandoned due to more components of their management methods and applications.
3. Now Configuration actually uses the mapping container mode. On the implementation, the registry, the underlayer underlayer, and the Domain container are separated. At the same time, the Configuration Manager for self-management plug-in mode is implemented.
Interface range
A global registry:
Registery: The registry is a global single sub-container that needs to be initialized at startup.
Three parent classes:
AbstractManagerAgent: Abstract class of Configuration Manager Agent
Manager Agemt is the main controller of Configuration, from the specified
Configuration registers the specified properties in the corresponding type MAP item.
AbstractMappingLoad: is a Load program interface that mapping parsing in Configuration
This program supports file access below.
All files in the compressed file.
All files in the physical catalog.
Separate files.
Separate file stream
AbstractParse: Abstract classes for configuration or external data analysis of Configuration
A container specification:
XXXXABLE EXTENDS HASHMAP: It is a container that inherits HashMap to store configuration elements, which will be registered in the registry according to Domain
API description
(See the com.ptf.cfg and com.ptf.cfg and com.ptf.PTF.MApping packages in ptf3javadoc)
Precautions
1, XXXABLE must inherit HashMap and Serializable
2. Access to Configuration must use registry_name = "xxxxx" to declare the Domain of the access registry, not declaring the back ClassCastException exception
3. For specific agents, users can customize the query method of the configuration element for customizing the environment.
4, multiple Agent can be used to parse the various parts of XML, that is, not a type of XML for an agent, Agent is classified according to logic type, and XML is the actual data store class
Development and test instance
Based on the configuration management of XML files, specific parsing processes are required because the XML file is a complex structure document. Specific parses must be made in accordance with user-defined requirements.
Multiple agents can be used to parse the various parts of XML, that is, not a type of XML for an agent, Agent is classified according to logic type, and XML is actual data storage class
HashMap-based configuration data container
/ **
* Command Config data container, inherited HashMap and implemented the serializable interface
* /
Public class cmdconfigable
Extends hashmap
Implements Serializable
{
/ ** CMDCONFIGABLE object constructor * /
Public cmdconfigable ()
{
}
/ **
* Get Command Config according to the name
* @ param name parameter description
* @ Return The SqlnamedQuery Value of SqlnamedQuery.
* /
Public Commandsconfig getcommandsconfig (String name)
{
Return (Commandsconfig) THIS.GET (NAME);
}
/ **
* Add Command Config to the container
* @ param Name New Attribute cmdconfig value
* @ param cmdcfg New attribute cmdconfig
* /
Public void addcmdconfig (String Name, Commandsconfig CMDCFG)
{
THIS.PUT (Name, CMDCFG);
}
/ **
* Added CommandSconfig attribute to object cmdconfigable object
*
* @ param Name New Attribute Commandsconfig value
* @ param Form new attribute Commandsconfig value
* @ param cmdlist New Attribute Commandsconfig value
* /
Public void addcommandsconfig (String Name, String Form, List cmdlist)
{
Commandsconfig cfg = new commandsconfig ();
cfg.setname (name);
Cfg.setformClassName (Form);
Cfg.setCommandList (cmdlist);
}
}
XML file-based configuration management
AbstractManagerAgent instance (as an example of Command)
/ **
* Class Description CmdconfigManagerAgent is a subclass of PTF Configuration AbstractManagerAgent.
* CMDConfigManagerAgent completes the operation of managing Command Config configuration data to the registry, and provides a query method
* /
Public class cmdconfigmanageRagent
Extends AbstractManagerAgent
{
/ **
* Property Description Command Config Data Container
* /
Private cmdconfigable cfgable = NULL;
/ **
* Property Description Log Instance
* /
Private final static logger log = logger.getlogger (cmdconfigmanagergent.class);
/ ** CMDConfigManageRAgent object constructor * /
Public cmdconfigmanageRageRagent ()
{
Super ();
}
/ **
* Get the Command Config object that specifies the Command name
*
* @ param name description of the parameter
* @ Return The Property Value
* /
Public Commandsconfig getcommandsconfig (string name) {
Cfgable = (cmdconfigable) registry.configcontext.get (registry_name);
Commandsconfig cfg = NULL;
IF (registry == null)
{
Log.debug ("Registry is Null, please init registry with registry.getregistry () method");
}
IF (cfgable! = null)
{
// log.debug (sqlable);
Cfg = cfgable.getCommandsconfig (name);
}
Return CFG;
}
/ **
* Method Description Call Analysis Profile Interface AbstractParse and Its Implementation CmdconfigMAppingParse
*
* @ Exception mappingexception exception handling
* /
Public void parse ()
Throws mappingexception
{
AbstractParse Parse = new cmdconfigmappingpival ();
PARSE.PATH = this.path;
Cfgable = (cmdconfigable) Parse.getResult ();
}
/ **
* Added Command Config container to registry after analysis
* /
Public void addRegistry ()
{
Registry.adddomain (registry_name, cfgable);
}
}
AbstractMappingLoad instance (as an example of Command)
/ **
* Class Description cmdconfigmappingLoad is subclass of PTF Configuration AbstractMappingLoad.
* Cmdconfigmappingload completes parsing Command Config configuration action, is a specific configuration resolution class
* /
Public class cmdconfigmappingload
Extends AbstractMappingload
{
/ **
* Property Description Command Config Data Container
* /
Private cmdconfigable cfgable = new cmdconfigable ();
/ **
* Property Description Log Instance
* /
Private static logger log = logger.getlogger (cmdconfigmappingload.class);
/ ** CMDConfigmappingLoad object constructor * /
Public cmdconfigmappingload ()
{
Super ();
// Statemonize the suffix of the configuration file
DescName = ".xml";
/ / Set whether to perform an XML validity check
Valid = false;
}
/ **
* Get cmdconfigable
* @ Return The Msgmappingable Value of Msgable.
* /
Public cmdconfigable getcmdconfigable ()
{
Return cfgable;
}
/ **
* Method Description ADD method inherited AbstractMAppingLoad, add a configuration source to the parser, and analyze, deposit into the container
*
* @ param DOC parameter description
* @ EXCEPTION MAPPINGEXCEPTION exception handling * /
Public void add (org.dom4j.document doc)
Throws mappingexception
{
// use the DOM4J to perform XML analysis
List cmdcfgs = doc.getrootelement (). Elements (cmdcfgcontains.cmd_cfg);
IF (cmdcfgs! = null)
{
ITERATOR IT = cmdcfgs.iterator (); it.hasnext ();)
{
Commandsconfig cfg = new commandsconfig ();
ELEMENT CMDCFG = (Element) it.next ();
String name = cmdcfg.element (cmdcfgcontains.cmd_name) .getText ();
cfg.setname (name);
Element formel = cmdcfg.Element (cmdcfgcontains.cmd_form);
IF (FORMEL! = NULL)
{
String form = formel.gettext ();
Cfg.setformClassName (Form);
}
Element tx = cmdcfg.element (cmdcfgcontains.cmd_txds);
String txname = cmdcfgcontains.cmd_detxds;
IF (TX! = NULL)
{
Txname = tx.gettext ();
cfg.settxdsname (txname);
}
Element cmdlist = cmdcfg.eray (cmdcfgcontains.cmd_list);
IF (cmdlist! = null)
{
Iterator cmds = cmdlist.ElementItem (cmdcfgcontains.cmd);
List cmdits = new arraylist ();
WHILE (cmds.hasnext ())
{
ELEMENT CMD = (Element) cmds.next ();
cmdits.add (cmd.getText ());
}
Cfg.setCommandList (cmdits);
}
Cfgable.addcmdconfig (Name, CFG);
}
}
}
/ **
* Method Description Use the DOCUMENT of DOM4J for analysis, this method is a pseudo method
*
* @ param DOC parameter description
* @ Exception mappingexception exception handling
* /
Public void configure (org.dom4j.document doc)
Throws mappingexception
{
}
}
AbstractParse instance (as an example of Command)
/ **
* Class Description CmdconfigMappingParse is a subclass of PTF Configuration AbstractParse.
* CmdconfigmappingParse completes parsing Command Config configuration, and store data to cmdconfigable
* /
Public class cmdconfigmappingpival
Extends AbstractParse
{
/ **
* Property Description Command Config Data Container
* /
Private cmdconfigable cfgable;
/ **
* Property Description Log Instance * /
Private final static logger log = logger.getlogger (cmdconfigmappingparse.class);
/ ** CMDConfigmappingParse object constructor * /
Public cmdconfigmappingpival ()
{
Super ();
}
/ **
* Result property from cmdconfigmappingParse Object
* Get all data for Command Config
*
* @ Return The Result Value
* /
Public Object GetResult ()
{
Cmdconfigmappingload loading = new cmdconfigmappingload ();
Try
{
String filename = this.path;
Load.addjar (filename);
Cfgable = loading.getcmdconfigable ();
}
Catch (mappingexception ex)
{
EX.PrintStackTrace ();
}
Return cfgable;
}
}
Configuration Management Based on Properties File
Based on the configuration management of the Properties file, there is no need for a specific parsing process because the Properties tool class parses the Properties type file, and the parser is implemented inside the Properties tool class, all in this type file, in Parse and Load The type definition and stream processing of external incoming data is implemented, and there is no specific parsing process.
AbstractManagerAgent instance (as an example of Velocity)
/ **
* Class Description VcManagerAgent is a subclass of PTF Configuration AbstractManagerAgent.
* VcManagerAgent completes the configuration data of Velocity's Properties to the registry, and provides a query method
* /
Public Class VcmanageRageRageRagent
Extends AbstractManagerAgent
{
/ **
* Property Description Velocity Data Container
* /
Private velocityable vcable = NULL;
/ **
* Property Description Log Instance
* /
Private final static logger log = logger.getlogger (VcManagerAgent.class);
/ ** VcManagerAgent object constructor * /
Public vcmanageRagent ()
{
Super ();
}
/ **
* Get the specified Properties from Velocity from the specified name
*
* @ param name description of the parameter
* @ Return The Property Value
* /
Public Properties GetVelocity (String Name)
{
Vcable = (velocityable) registry.configcontext.get (registry_name);
IF (registry == null)
{
Log.debug ("Registry is Null, please init registry with registry.getregistry () method");
}
Properties PROPS = NULL;
IF (Vcable! = NULL)
{
// log.debug (sqlable);
PROPS = Vcable.getProps (name);
}
Return prOPs;
}
/ **
* Method description What AbstractParse interface is implemented, and analyzes
*
* @ Exception mappingexception exception handling
* /
Public void parse ()
Throws mappingexception
{
AbstractParse Parse = new vcmappingpival ();
PARSE.PATH = this.path;
Vcable = (velocityable) Parse.getResult ();
}
/ **
* Added data containers to registry after analyzing
* /
Public void addRegistry ()
{
Registry.adddomain (registry_name, vcable);
}
}
AbstractMappingLoad instance (as an example of Velocity)
/ **
* Class Description VcmappingLoad is a subclass of PTF Configuration AbstractMappingLoad.
* VcmappingLoad completes the parsing of Velocity configuration action, is a specific configuration parsing class
* /
Public Class VcmappingLoad
Extends AbstractMappingload
{
/ **
* Property Description Velocity Data Container
* /
Private velocityable vcable = new velocityable ();
/ **
* Property Description Log Instance
* /
Private static logger log = logger.getlogger (vcmappingload.class);
/ **
* Property Description Default Attribute Name
* /
Private final static string default_name = "default";
/ ** VCMAppingLoad object constructor * /
Public vcmappingload ()
{
Super ();
// Declare the configuration file suffix
DescName = ".properties";
}
/ **
* Get a Velocity data container
* @ Return The Msgmappingable Value of Msgable.
* /
Public velocityable getVelocityable ()
{
Return Vcable;
}
/ **
* Method Description Increase the Properties object as a data source, namely false default properties
*
* @ param prots parameter description
* @ Exception mappingexception exception handling
* /
Public Void Add (Properties PROPS)
Throws mappingexception
{
vcable.addprops (default_name, prOps);
}
/ **
* Method Description Increase the Properties object of the specified name as a data source
*
* @ param name parameter description
* @ param prots parameter description
* @ Exception mappingexception exception handling
* /
Public Void Add (String Name, Properties PROPS)
Throws mappingexception
{
vcable.addprops (name, prOps);
}
/ **
* Method Description DOM4J object as a data source, this method is a pseudo-way
*
* @ param DOC parameter description
* @ Exception mappingexception exception handling
* /
Public void add (org.dom4j.document doc)
Throws mappingexception
{
}
/ **
* Method Description Use the DOCUMENT of DOM4J for analysis, this method is a pseudo method
*
* @ param DOC parameter description
* @ Exception mappingexception exception handling
* /
Public void configure (org.dom4j.document doc)
Throws mappingexception
{
}
}
AbstractParse instance (configured as a Velocity)
/ **
* Class Description VcmappingParse is a subclass of PTF Configuration AbstractParse.
* VcmappingParse completes parsing Velocity configuration, and store data to velocityable
* /
Public class vcmappingparse
Extends AbstractParse
{
/ **
* Property Description Velocity Data Container
* /
PRIVATE VELOCITYABLE VCABLE;
/ **
* Property Description Log Instance
* /
Private final static logger log = logger.getlogger (vcmappingparse.class);
/ ** VCMAppingParse object constructor * /
Public vcmappingparse ()
{
Super ();
}
/ **
* Get the Result property of VcmappingParse Object
*
* @ Return The Result Value
* /
Public Object GetResult ()
{
Vcmappingload loading = new vcmappingload ();
Try
{
String filename = this.path;
// log.debug (filename);
Filename.endswith ("Properties"))
{
Load.addprops (filename);
}
Else IF (Filename.endswith (". jar"))
{
Load.addjar (filename);
}
vcable = loading.getvelocityable ();
}
Catch (mappingexception ex)
{
EX.PrintStackTrace ();
}
Return Vcable;
}
}
Test example
The test is relatively simple for Configuration, mainly to choose the specific Agent and object, and operate according to the specific query method, pay attention, must declare the registry_name registration name.
/ **
* Configuration's test program, test the initialization of Configuration, and access to various agents
*
* @ authoror
* @ created November 26, 2003
* /
Public class cfgtest
{
/ **
* Main executor method for this test program
*
* @ param args the command line arguments
* /
Public static void main (String [] args) {
Cfgtest cfgtest = new cfgtest ();
cfgtest.parse ();
}
/ **
* Test for CFGABLE data containers
* /
Public void cfgable ()
{
Cfgable Map = New cfgable ();
CONFIG Conf = New Config ();
Conf.setAlias ("Test");
Conf.setpath ("./ Test");
Map.Addcfg ("com.ptf.cfg.test.class", conf);
System.out.println ("com.ptf.cfg.test.class));
}
/ **
* Test the initialization of Configuration, and access to various Agents
* /
Public void parse ()
{
// Test the initialization of Configuration
ConfigurationFactory Factory = ConfigurationFactory.GetFactory ();
Factory.initRegistry ();
// The access process of the MsgManagerAgent in PTF2
COM.PTF.MApping.msgptf2.Agent.msgmanageRAgent agento = new com.ptf.mapping.msgptf2.amp.msgmanageRAgent ();
// Declare registration name
Agento.registry_name = "msgptf2mapping";
// Print output test results
System.out.println ("PTF2 Message <-" Agento.getNameDMessage ("Dossier_Date_INVALID");
// The access process of the MsgManagerAgent in PTF3
COM.PTF.MApping.msg.Agent.msgManagerAgent agent = new com.ptf.mapping.msg.Agent.msgManageRagent ();
// Declare registration name
Agent.registry_name = "msgmapping";
// Print output test results
System.out.println ("Message <-" Agent.getNameDMessage ("SystemException"));
// The access process of the SQLManagerAgent in PTF3
COM.PTF.MApping.sql.Agent.sqlmanageRagent SQLAGENT = New com.ptf.mapping.sql.Agent.sqlmanageRAgent ();
// Declare registration name
SQLAGENT.REGISTRY_NAME = "SQLMApping";
// Print output test results
System.out.println ("SQL <-" SQLAGENT.GETSQLQUERY ("acc.hello");
// The accessed process of SQLManager in PTF2
COM.PTF.MApping.sqlptf2.agent.sqlmanageRagent SQLPTF2Agent = new com.ptf.mapping.sqlptf2.agent.sqlmanageRagent ();
// Declare registration name
SQLPTF2Agent.registry_name = "SQLPTF2MApping"; // Print Output Test Results
System.out.Println ("PTF2 SQL <-" SQLPTF2Agent.getsqlQuery ("MyTest1"));
// PTF3 access process of VcManagerAgent
VcManagerAgent vc = new vcManagerAgent ();
// Declare registration name
vc.registry_name = "velocity";
// Print output test results
System.out.println ("Velocity <-" vc.getVelocity ("velocity"));
}
}