|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.edustructures.sifworks.tools.cfg.AgentConfig
public class AgentConfig
Implements an XML-based configuration file for agents.
To read the configuration file into memory, call the read
method and specify whether to validate the XML document against a DTD. The
methods of the AgentConfig class do not perform validation of required
elements and attributes or their values, so it is recommended that you
validate against a DTD. A default DTD is located in the docs
directory.
Applying the Configuration
Once the configuration file is parsed, you can inspect the elements and
attributes by calling the various methods of this class. Or, you can call
the apply method prior to agent initialization to automatically
apply the configuration settings to your agent as follows:
<agent> attributes are inspected to set
the SourceId and default SIF Version for the agent.
<property> element, the associated
property is set in the agent's AgentProperties object.
<transport> elements
<zone> element
extras directory.Properties Agent and Zone properties can be defined at three levels:
<property> elements of the root <agent>
node are intended to serve as global defaults. When then applyProperties
method is called, these property values are assigned to the Agent's
AgentProperties object.
<property> elements of a zone <template>
are inherited by zones that reference that template. When the applyZones
method is called, these property values are assigned to the Zone's
AgentProperties object unless specifically overridden by <property>
elements defined by each <zone>
<property> elements of a <zone>
are specific to that zone and override any property defined in the
template referenced by the zone
getProperty and setProperty
methods can also be used to manipulate the <property>
children of an element. Static helper routines from the
com.edustructures.util.XMLUtils class may also be used to get and set
element attributes and text values.
Call the save method to write the configuration to a file.
| Constructor Summary | |
|---|---|
AgentConfig()
Constructor |
|
| Method Summary | |
|---|---|
org.w3c.dom.Node |
addTransportNode(java.lang.String protocol)
Add a <transport> node for the specified transport protocol. |
org.w3c.dom.Node |
addZone(java.lang.String zoneId,
java.lang.String zoneUrl,
java.lang.String templateId)
Adds a new zone |
org.w3c.dom.Node |
addZoneTemplateNode(java.lang.String templateId)
Add a <template> node for the specified zone template. |
Zone[] |
apply(Agent agent,
boolean overwrite)
Applies the settings in the configuration to the Agent. |
void |
applyProperties(Agent agent,
boolean overwrite)
Applies <property> elements to the Agent |
void |
applyTransports(Agent agent,
boolean overwrite)
Applies <transport> elements to the Agent. |
Zone[] |
applyZones(Agent agent)
Applies <zone> elements to create new Zone instances. |
void |
deleteProperty(java.lang.String property)
Deletes a property. |
void |
deleteZone(java.lang.String zoneId)
Deletes a zone |
void |
deleteZoneProperty(java.lang.String zoneId,
java.lang.String property)
Deletes a zone property. |
void |
deleteZoneTemplateProperty(java.lang.String templateId,
java.lang.String property)
Deletes a zone template property. |
void |
getAgentProperties(AgentProperties props)
Populates an AgentProperties object with all <property>
values defined for the root <agent> element. |
org.w3c.dom.Node[] |
getAgentPropertyNodes()
Gets all <property> values defined for the root
<agent> node. |
org.w3c.dom.Document |
getDocument()
Gets the DOM document |
Mappings |
getMappings()
Gets the Mappings object |
java.lang.String |
getProperty(org.w3c.dom.Node node,
java.lang.String property,
java.lang.String defaultValue)
Gets the value of a <property> element defined by a node. |
java.lang.String |
getProperty(org.w3c.dom.Node node,
java.lang.String element,
java.lang.String property,
java.lang.String defaultValue)
A convenience function to get the value of a <property>
defined by the first child element of the specified node that has a
matching tag name. |
org.w3c.dom.Node |
getPropertyNode(org.w3c.dom.Node node,
java.lang.String property)
Gets a <property> DOM Node |
org.w3c.dom.Node[] |
getPropertyNodes(org.w3c.dom.Node node)
Gets all <property> child nodes of an element |
org.w3c.dom.Node |
getRootNode()
Gets the root <agent> element |
java.lang.String |
getSourceId()
Gets the SourceId that should be used by the agent |
org.w3c.dom.Node |
getTransportNode(java.lang.String protocol)
Gets a <transport> node. |
SIFVersion |
getVersion()
Gets the version of SIF that should be used by the agent |
java.lang.String |
getZoneAttribute(java.lang.String zoneId,
java.lang.String attr,
java.lang.String defaultValue)
Gets the value of a <zone> node attribute. |
org.w3c.dom.Node |
getZoneNode(java.lang.String zoneId)
Gets the <zone> element with the specified ID |
org.w3c.dom.Node[] |
getZoneNodes()
Gets an array of all zones defined by the configuration file |
void |
getZoneProperties(java.util.Properties props,
org.w3c.dom.Node zone)
Populates a Properties object with all <property>
values defined by a <zone> node as well as all
properties defined by the referenced zone template. |
void |
getZoneProperties(java.util.Properties props,
java.lang.String zone)
Populates a Properties object with all <property>
values defined by a <zone> node as well as all
properties defined by the referenced zone template. |
java.lang.String |
getZoneProperty(java.lang.String zoneId,
java.lang.String property,
java.lang.String defaultValue)
Gets the value of a <property> child of the specified
<zone> node. |
org.w3c.dom.Node[] |
getZonePropertyNodes(org.w3c.dom.Node zone)
Gets all <property> values defined for a
<zone> node. |
org.w3c.dom.Node[] |
getZonePropertyNodes(java.lang.String zoneId)
Gets all <property> values defined for a
<zone> node. |
org.w3c.dom.Node |
getZoneTemplateNode(java.lang.String templateId)
Gets a zone template by ID. |
void |
getZoneTemplateProperties(java.util.Properties props,
org.w3c.dom.Node template)
Populates a Properties object with all <property>
values defined for a <template> node. |
void |
getZoneTemplateProperties(java.util.Properties props,
java.lang.String template)
Populates a Properties object with all <property>
values defined for a <template> node. |
java.lang.String |
getZoneTemplateProperty(java.lang.String templateId,
java.lang.String property,
java.lang.String defValue)
Gets a zone template property. |
org.w3c.dom.Node |
getZoneTemplatePropertyNode(java.lang.String templateId,
java.lang.String property)
Gets a zone template property node. |
org.w3c.dom.Node[] |
getZoneTemplatePropertyNodes(org.w3c.dom.Node template)
Gets all <property> values defined for a <zone> node. |
org.w3c.dom.Node[] |
getZoneTemplatePropertyNodes(java.lang.String templateId)
Gets all <property> values defined for a <zone> node. |
org.w3c.dom.Node[] |
getZoneTemplates(boolean filtered)
Gets an array of all zones templates. |
boolean |
isLoaded()
Determines if the configuration file has been loaded |
void |
populateProperties(java.util.Properties props,
org.w3c.dom.Node node)
Populates a Properties object with all <property>
values defined as children of the specified node. |
void |
populateProperties(java.util.Properties props,
org.w3c.dom.Node node,
boolean replace)
Populates a Properties object with all <property>
values defined as children of the specified node. |
org.w3c.dom.Document |
read(java.lang.String file,
boolean validate)
Read a configuration file into memory. |
void |
save()
Saves the XML document back to the file from which it was read. |
void |
save(java.io.BufferedWriter out)
Saves the XML document to the specified Writer. |
void |
save(java.io.OutputStream out)
Saves the XML document to the specified output stream. |
void |
setAgentProperty(java.lang.String property,
java.lang.String value)
Sets the value of a <property> child of the root
<agent> node. |
void |
setProperty(org.w3c.dom.Node node,
java.lang.String property,
java.lang.String value)
Sets the value of a <property> child of the specified
node. |
void |
setProperty(org.w3c.dom.Node node,
java.lang.String element,
java.lang.String property,
java.lang.String value)
|
void |
setZoneAttribute(java.lang.String zoneId,
java.lang.String attr,
java.lang.String value)
Sets the value of a <zone> node attribute. |
void |
setZoneProperty(java.lang.String zoneId,
java.lang.String property,
java.lang.String value)
Sets the value of a <property> child of the specified
<zone> node. |
void |
setZoneTemplateProperty(java.lang.String template,
java.lang.String property,
java.lang.String value)
Sets the value of a <property> child of the specified
<zone> node. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public AgentConfig()
| Method Detail |
|---|
public org.w3c.dom.Document read(java.lang.String file,
boolean validate)
throws java.io.IOException,
ADKConfigException,
ADKMappingException,
ADKException
file - The path to the configuration filevalidate - true to validate the configuration file
getDocument
java.io.IOException - thrown if an error occurs reading the file
ADKException - thrown if the ADK is not initialized
ADKMappingException - thrown if an error occurs parsing any
<mappings> elements
ADKConfigException - thrown if the configuration file fails
to parse or is not valid when validation is turned ongetDocument()
public void save()
throws java.io.IOException,
ADKConfigException
java.io.IOException - thrown if an error occurs writing the document
ADKConfigException
public void save(java.io.OutputStream out)
throws java.io.IOException,
ADKConfigException
out - The OutputStream to which the XML document is written
java.io.IOException - thrown if an error occurs writing the document
ADKConfigException
public void save(java.io.BufferedWriter out)
throws java.io.IOException,
ADKConfigException
out - The Writer to which the XML document is written
java.io.IOException - thrown if an error occurs writing the document
ADKConfigExceptionpublic boolean isLoaded()
read method has been successfully called
public Zone[] apply(Agent agent,
boolean overwrite)
throws ADKException,
ADKConfigException
<property> element, the associated
property is set in the agent properties.
<zone>
element. Any <property> elements defined for
the zone are set in the zone's AgentProperties object. An array
of all zones created is returned. The caller can then join those
zones to topics.
agent - The Agent to apply the configuration settings tooverwrite - When true, properties defined in the configuration file
replace properties of the same name that are already defined in the
agent properties
ADKException
ADKConfigException
public void applyProperties(Agent agent,
boolean overwrite)
throws ADKException,
ADKConfigException
<property> elements to the Agent
agent - The Agent to apply properties tooverwrite - When true, properties defined in the configuration file
replace properties of the same name that are already defined in the
agent properties
ADKException
ADKConfigException
public void applyTransports(Agent agent,
boolean overwrite)
throws ADKException,
ADKConfigException
<transport> elements to the Agent.
This method selects the <transport> child of the root
<agent> with the enabled attribute set to true.
Only one transport may be enabled; if more than one is enabled the last
definition is considered the agent's default transport protocol. The
<property> elements are then assigned to the agent's
default transport properties for this protocol.
agent - The Agent to apply the transport properties tooverwrite - When true, properties defined in the configuration file
replace properties of the same name that are already defined in the
agent's default transport properties
ADKException
ADKConfigException
public Zone[] applyZones(Agent agent)
throws ADKException,
ADKConfigException
<zone> elements to create new Zone instances.
The caller is responsible for setting up topics, connecting to zones,
and joining zones to topics.
ADKException
ADKConfigExceptionpublic org.w3c.dom.Document getDocument()
public org.w3c.dom.Node addZone(java.lang.String zoneId,
java.lang.String zoneUrl,
java.lang.String templateId)
throws ADKConfigException
zoneId - The zone IDzoneUrl - The zone URLtemplateId - The ID of the zone template
ADKConfigExceptionpublic void deleteZone(java.lang.String zoneId)
zoneId - The zone IDpublic SIFVersion getVersion()
sifVersion
attribute specified by the <agent> element, or
the ADK's default SIFVersion if this attribute was not setpublic Mappings getMappings()
<agent> node if definedpublic org.w3c.dom.Node getRootNode()
<agent> element
public java.lang.String getSourceId()
public void getAgentProperties(AgentProperties props)
<property>
values defined for the root <agent> element.
Properties defined at the root level are applied to the AgentProperties
object of the Agent class. These serve as global defaults to all zones.
Use the getTemplateProperties method to obtain properties for a zone
template, which apply to all zones that reference that template, or the
getZoneProperties method to obtain properties specific to a zone.
public org.w3c.dom.Node[] getAgentPropertyNodes()
<property> values defined for the root
<agent> node.
public void setAgentProperty(java.lang.String property,
java.lang.String value)
<property> child of the root
<agent> node. If a <property>
element already exists, its value is updated; otherwise a new element is
appended to the root <agent> node.
property - The name of the propertyvalue - The property value
public void getZoneProperties(java.util.Properties props,
java.lang.String zone)
<property>
values defined by a <zone> node as well as all
properties defined by the referenced zone template. Properties defined
by the <zone> override properties defined by the
template.
public void getZoneProperties(java.util.Properties props,
org.w3c.dom.Node zone)
<property>
values defined by a <zone> node as well as all
properties defined by the referenced zone template. Properties defined
by the <zone> override properties defined by the
template.
public org.w3c.dom.Node[] getZonePropertyNodes(java.lang.String zoneId)
<property> values defined for a
<zone> node.
public org.w3c.dom.Node[] getZonePropertyNodes(org.w3c.dom.Node zone)
<property> values defined for a
<zone> node.
public void setZoneProperty(java.lang.String zoneId,
java.lang.String property,
java.lang.String value)
<property> child of the specified
<zone> node. If a <property> child
already exists with the same name, its value is updated; otherwise a new
element is appended to the <zone> node.
zoneId - The zone IDproperty - The name of the propertyvalue - The property value
public java.lang.String getZoneProperty(java.lang.String zoneId,
java.lang.String property,
java.lang.String defaultValue)
<property> child of the specified
<zone> node.
zoneId - The zone IDproperty - The name of the propertydefaultValue - The value that will be returned if the property is
not defined
public void setZoneAttribute(java.lang.String zoneId,
java.lang.String attr,
java.lang.String value)
<zone> node attribute.
zone - The zone IDattr - The name of the attributevalue - The attribute value
public java.lang.String getZoneAttribute(java.lang.String zoneId,
java.lang.String attr,
java.lang.String defaultValue)
<zone> node attribute.
zone - The zone IDattr - The name of the attributedefaultValue - The value that will be returned if the attribute is
not defined
public void getZoneTemplateProperties(java.util.Properties props,
java.lang.String template)
<property>
values defined for a <template> node.
public void getZoneTemplateProperties(java.util.Properties props,
org.w3c.dom.Node template)
<property>
values defined for a <template> node.
public java.lang.String getZoneTemplateProperty(java.lang.String templateId,
java.lang.String property,
java.lang.String defValue)
templateId - The ID of the <template>property - The name of the <property>defValue - The default value to return if the property is not defined
public org.w3c.dom.Node getZoneTemplatePropertyNode(java.lang.String templateId,
java.lang.String property)
templateId - The ID of the <template>property - The name of the <property>
public org.w3c.dom.Node[] getZoneTemplatePropertyNodes(java.lang.String templateId)
<property> values defined for a <zone> node.
public org.w3c.dom.Node[] getZoneTemplatePropertyNodes(org.w3c.dom.Node template)
<property> values defined for a <zone> node.
public void setZoneTemplateProperty(java.lang.String template,
java.lang.String property,
java.lang.String value)
<property> child of the specified
<zone> node. If a <property> child
already exists with the same name, its value is updated; otherwise a new
element is appended to the <template> node.
template - The zone template IDproperty - The name of the propertyvalue - The property valuepublic void deleteProperty(java.lang.String property)
property - The name of the <property>
public void deleteZoneProperty(java.lang.String zoneId,
java.lang.String property)
zoneId - The ID of the <zone>property - The name of the <property>
public void deleteZoneTemplateProperty(java.lang.String templateId,
java.lang.String property)
templateId - The ID of the <template>property - The name of the <property>
public void populateProperties(java.util.Properties props,
org.w3c.dom.Node node)
<property>
values defined as children of the specified node. Properties that already
exist in the Properties object are not overwritten by properties defined
by the node.
public void populateProperties(java.util.Properties props,
org.w3c.dom.Node node,
boolean replace)
<property>
values defined as children of the specified node. Properties that already
exist in the Properties object are optionally overwritten with properties
defined by the node.
props - The Properties object to populatenode - The Node to search for child <property> elementsreplace - true to replace the values of properties already defined
in the props object
public void setProperty(org.w3c.dom.Node node,
java.lang.String property,
java.lang.String value)
<property> child of the specified
node. If a <property> element already exists, its value
is updated; otherwise a new element is appended to the node.
node - The parent node of the propertyproperty - The name of the propertyvalue - The property value
public void setProperty(org.w3c.dom.Node node,
java.lang.String element,
java.lang.String property,
java.lang.String value)
public java.lang.String getProperty(org.w3c.dom.Node node,
java.lang.String property,
java.lang.String defaultValue)
<property> element defined by a node.
node - The parent node to searchproperty - The name of the propertydefaultValue - The value to return if the property is not found
public org.w3c.dom.Node getPropertyNode(org.w3c.dom.Node node,
java.lang.String property)
<property> DOM Node
node - The parent node to searchproperty - The name of the property
null
public java.lang.String getProperty(org.w3c.dom.Node node,
java.lang.String element,
java.lang.String property,
java.lang.String defaultValue)
<property>
defined by the first child element of the specified node that has a
matching tag name. This routine is often used to obtain properties that
are organized into named groups (e.g. <database-settings>,
<transport-settings>, etc.)
For example, to lookup a property named "user" of a top-level
<database-settings> element,
getProperty( getRootNode(), "database-settings", "user", "sa" );
node - The parent node to searchelement - The tag name of the element to search for (it must be a
non-repeating child of the parent node)property - The name of the propertydefaultValue - The value to return if the property is not found
public org.w3c.dom.Node[] getPropertyNodes(org.w3c.dom.Node node)
<property> child nodes of an element
public org.w3c.dom.Node[] getZoneNodes()
<zone> elements
defined by the configuration filepublic org.w3c.dom.Node getZoneNode(java.lang.String zoneId)
<zone> element with the specified ID
public org.w3c.dom.Node[] getZoneTemplates(boolean filtered)
<template>
elements defined as children of the root <agent> nodepublic org.w3c.dom.Node getZoneTemplateNode(java.lang.String templateId)
templateId - The ID of the template to return
<template>
element with the specified IDpublic org.w3c.dom.Node addZoneTemplateNode(java.lang.String templateId)
public org.w3c.dom.Node getTransportNode(java.lang.String protocol)
protocol - The protocol type (e.g. "http", "https", etc.)
<transport> elementpublic org.w3c.dom.Node addTransportNode(java.lang.String protocol)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||