"WEBNMS_5 API Docs"

com.adventnet.management.config
Class DataSourceGenerator

java.lang.Object
  extended by com.adventnet.management.config.DataSourceGenerator

public class DataSourceGenerator
extends java.lang.Object

This class provides methods for generating DataSource in XML Format. This DataSource XML provides various resources for gathering data which is populated to the template for configuration. DataSource supports data gathering from Inventory, NetworkElement and User.

By default, inventory maintained by the Web NMS will be used for providing the inventory inputs. This can be overridden by specifying the class implementing the com.adventnet.management.config.InventoryHandler in NmsProcessesBE.conf file. Now this class becomes the default class for handling InventoryInputs defined in various DataSources. Also, InventoryHandler can be specified at the DataSource level. If any handler class is specified at the level of DataSource, all the InventoryInputs defined in the DataSource will be handled by this class instead of the default handler specified in NmsProcessesBE.conf. In addition to this, handlers can also be specified for each InventoryInput in the DataSource.

A sample code that generates DataSource XML.

DataSourceGenerator dsg = new DataSourceGenerator();

// Setting the associated task(s) for which this DataSource can be associated.
dsg.setAssociatedTasks( new String[]{"sampleTask"});
dsg.setDataSourceName("sampleDataSource");

// Adding an InventoryInput.
dsg.addInventoryInput("port", "$DataSourceParam$MOName", "$DataSourceParam$MOField", "161");

// Adding a UserInput.
dsg.addUserInput("NEName", "Device", "$DataSourceParam$NEName");

//Generating a task
TaskGenerator tg = new TaskGenerator();
tg.setTaskName("task1");
tg.setProtocol("snmp");
SnmpDevice device = new SnmpDevice("$UserInput$NEName", "$InventoryInput$port");
tg.setDevices( new SnmpDevice[]{device});
SnmpAttribute attr = new SnmpAttribute("1.6.0", "sysLocation", (byte)4, "");
tg.addAttribute(attr);
String taskXML = tg.getTask();

//Adding an NEInput
dsg.addNEInput("1", taskXML);
String dataSourceXML = dsg.getDataSource();

$DataSourceParam$<id> indicates input values for the DataSource. Placeholders $DataSourceParam$MOName, $DataSourceParam$MOField, $DataSourceParam$NEName, $UserInput$NEName, $InventoryInput$port, $NEInput$location will be searched in the template for data population.

Since:
Web NMS 2.3
See Also:
DataSource, TaskGenerator

Constructor Summary
DataSourceGenerator()
          Initilizes a XML Document for generating DataSource in XML format.
DataSourceGenerator(DataSource dataSource)
          Initializes the XML Document from the DataSource root element.
 
Method Summary
 void addInventoryInput(java.lang.String id, java.util.Properties prop)
          Adds an InventoryInput for the DataSource.
 void addInventoryInput(java.lang.String id, java.lang.String moName, java.lang.String moField)
          Adds an InventoryInput for the DataSource.
 void addInventoryInput(java.lang.String id, java.lang.String moName, java.lang.String moField, java.lang.String defaultVal)
          Adds an InventoryInput for the DataSource.
 void addInventoryInput(java.lang.String id, java.lang.String moName, java.lang.String moField, java.lang.String defaultVal, java.lang.String inventoryHandler)
          Adds an InventoryInput for the DataSource.
 void addNEInput(java.lang.String id, ConfigTask configTask)
          Adds an NEInput to the DataSource.
 void addNEInput(java.lang.String id, java.lang.String taskXML)
          Adds an NEInput to the DataSource.
 void addUserInput(java.lang.String id, java.util.Properties prop)
          Adds a UserInput with properties like id,name,value etc.
 void addUserInput(java.lang.String id, java.lang.String name, java.lang.String value)
          Adds a UserInput for the DataSource.
 java.lang.String getDataSource()
          Returns DataSource String in XML Format
 org.w3c.dom.Element getElement()
          Returns the root element for DataSource XML.
 void saveDataSource(java.lang.String fileName)
          Saves the DataSource XML in the specified file.
 void setAssociatedTasks(java.lang.String[] taskNames)
          Specifies the tasks for which this DataSource can be associated for execution.
 void setDataSourceName(java.lang.String dataSourceName)
          Assigns a name for this DataSource.
 void setDataSourceProperties(java.util.Properties prop)
          Specifies the properties for the DataSource.
 void setDescription(java.lang.String description)
          Sets the description for the DataSource
 void setInventoryHandler(java.lang.String inventoryHandler)
          Sets the inventory handler class for handling the InventoryInputs defined in the DataSource.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataSourceGenerator

public DataSourceGenerator()
                    throws InvalidTemplateException
Initilizes a XML Document for generating DataSource in XML format.

Throws:
InvalidTemplateException - if it fails to create an empty element.

DataSourceGenerator

public DataSourceGenerator(DataSource dataSource)
                    throws InvalidTemplateException
Initializes the XML Document from the DataSource root element.

Parameters:
dataSource - the base from which dataSource XML is constructed.
Throws:
InvalidTemplateException - if it fails to get the element.
Method Detail

setInventoryHandler

public void setInventoryHandler(java.lang.String inventoryHandler)
Sets the inventory handler class for handling the InventoryInputs defined in the DataSource. This handler will be responsible for providing inventory values to the Template . If it fails, default value defined in the InventoryInput element will be populated to the Template.

Parameters:
inventoryHandler - class name that implements InventoryHandler class.
See Also:
InventoryHandler

setAssociatedTasks

public void setAssociatedTasks(java.lang.String[] taskNames)
Specifies the tasks for which this DataSource can be associated for execution.

Parameters:
taskNames - an array of template based tasks.

setDataSourceName

public void setDataSourceName(java.lang.String dataSourceName)
Assigns a name for this DataSource.

Parameters:
dataSourceName - a name for the dataSource

setDescription

public void setDescription(java.lang.String description)
Sets the description for the DataSource

Parameters:
description - specifies the description for this DataSource.

setDataSourceProperties

public void setDataSourceProperties(java.util.Properties prop)
Specifies the properties for the DataSource. Properties like name,description,associatedTasks etc can be assigned through this method. Refer <Web NMS Home >/configtasks/DataSource.dtd for more properties.

Parameters:
prop - Contains attributes for this DataSource.

getDataSource

public java.lang.String getDataSource()
Returns DataSource String in XML Format

Returns:
the dataSourceXML as a String.

addInventoryInput

public void addInventoryInput(java.lang.String id,
                              java.lang.String moName,
                              java.lang.String moField,
                              java.lang.String defaultVal)
Adds an InventoryInput for the DataSource. If InventoryHandler fails to retrieve the value from the specified inventory, default value will be populated to the Template. The argument id should be unique among the InventoryInputs defined in the DataSource.

Parameters:
id - a unique value that will be appended with $InventoryInput$ for replacing the placeholders present in Templates
moName - Specifies the ManagedObject for getting the inventory values.
moField - Specifies the name of the property to be fetched in the ManagedObject.
defaultVal - defaultValue for this inventory.

addInventoryInput

public void addInventoryInput(java.lang.String id,
                              java.lang.String moName,
                              java.lang.String moField,
                              java.lang.String defaultVal,
                              java.lang.String inventoryHandler)
Adds an InventoryInput for the DataSource. If the specified InventoryHandler fails to retrieve the value from inventory, default value will be populated to the Template. The argument id should be unique among the InventoryInputs defined in the DataSource.

Parameters:
id - a unique value that will be appended with $InventoryInput$ for replacing the placeholders present in Templates
moName - Specifies the ManagedObject for getting the inventory values.
moField - Specifies the name of the property to be fetched in the ManagedObject.
defaultVal - defaultValue for this inventory.
inventoryHandler - class name that handles this Inventory

addInventoryInput

public void addInventoryInput(java.lang.String id,
                              java.lang.String moName,
                              java.lang.String moField)
Adds an InventoryInput for the DataSource. The argument id should be unique among the InventoryInputs defined in the DataSource.

Parameters:
id - a unique value that will be appended with $InventoryInput$ for replacing the placeholders present in Templates
moName - Specifies the ManagedObject for getting the inventory values.
moField - Specifies the name of the property to be fetched in the ManagedObject.

addInventoryInput

public void addInventoryInput(java.lang.String id,
                              java.util.Properties prop)
Adds an InventoryInput for the DataSource. The argument id should be unique among the InventoryInputs defined in the DataSource.Properties contains details for getting values from the inventory.

Parameters:
id - a unique value that will be appended with $InventoryInput$ for replacing the placeholders present in Templates
prop - contains attributes for this inventory.

addUserInput

public void addUserInput(java.lang.String id,
                         java.lang.String name,
                         java.lang.String value)
Adds a UserInput for the DataSource. The id should be unique among the UserInputs defined for this DataSource.

Parameters:
id - a unique value that will be appended with $UserInput$ for replacing the placeholders defined in templates.
name - name of the UserInput.
value - the value that need to be substituted for this UserInput

addUserInput

public void addUserInput(java.lang.String id,
                         java.util.Properties prop)
Adds a UserInput with properties like id,name,value etc.

Parameters:
id - a unique value that will be appended with $UserInput$ for replacing the placeholders defined in templates.
prop - contains UserInput attributes.

addNEInput

public void addNEInput(java.lang.String id,
                       ConfigTask configTask)
Adds an NEInput to the DataSource. For NEInputs, Attribute's label will be appended to $NEInput$ (instead of id's value) for replacing the placeholders defined in Templates. So attribute's label should be unique among the attributes defined.

Parameters:
id - a unique value among the NEInputs.
configTask - contains attributes for uploading configuration from the specified device.

addNEInput

public void addNEInput(java.lang.String id,
                       java.lang.String taskXML)
                throws InvalidTemplateException
Adds an NEInput to the DataSource. taskXML can be generated using TaskGenerator. Attribute's label will be appended (instead of id's value) to $NEInput$ for replacing the placeholders defined in Templates. So attribute's label should be unique among the attributes defined in the task.

Parameters:
id - a unique value among the NEInputs.
taskXML - contains attributes for uploading configuration from the specified device.
Throws:
InvalidTemplateException - if the template being passed is an invalid XML.

getElement

public org.w3c.dom.Element getElement()
Returns the root element for DataSource XML.

Returns:
the dataSource's root.

saveDataSource

public void saveDataSource(java.lang.String fileName)
Saves the DataSource XML in the specified file.

Parameters:
fileName - name of the file for storing the DataSource.

"WEBNMS_5 API Docs"

Copyright © 2011 ZOHO Corp., All Rights Reserved.