edu.sdsc.inca.util
Class SuiteWrapper

java.lang.Object
  extended by edu.sdsc.inca.util.XmlWrapper
      extended by edu.sdsc.inca.util.SuiteWrapper

public class SuiteWrapper
extends XmlWrapper

Convenience object for accessing suite documents and persisting changes to them.

Author:
Shava Smallen <ssmallen@sdsc.edu>

Field Summary
 
Fields inherited from class edu.sdsc.inca.util.XmlWrapper
PASSWORD_MACRO_VALUE_PATTERN, PROCESSING_INSTRUCTION_PATTERN, XML_CDATA_PATTERN, XML_COMMENT_PATTERN, XML_NAME_PATTERN, XML_NODE_PATTERN
 
Constructor Summary
SuiteWrapper()
          Create a new SuiteWrapper object containing a blank suite.
SuiteWrapper(java.lang.String filename)
          Create a new SuiteWrapper object from a suite XML file.
SuiteWrapper(edu.sdsc.inca.dataModel.suite.Suite suite)
          Create a new SuiteWrapper object from an XML Beans class instance.
SuiteWrapper(edu.sdsc.inca.dataModel.suite.SuiteDocument suiteDoc)
          Create a new SuiteWrapper object from an XML Beans class instance.
 
Method Summary
 void appendSeriesConfig(edu.sdsc.inca.dataModel.util.SeriesConfig seriesConfig)
          Append a new series config to the existing suite.
 void changeAction(java.lang.String action)
          Change the action in all series configs found in the suite document.
 void copySuiteAttributes(edu.sdsc.inca.dataModel.suite.SuiteDocument suiteDoc)
          Copy the top level suite attributes: name, guid, and description to supplied suite document.
 edu.sdsc.inca.dataModel.suite.SuiteDocument diff(edu.sdsc.inca.dataModel.suite.SuiteDocument suiteDoc)
          Compare the existing suite against the passed in suite and return the differences as adds and deletes.
 edu.sdsc.inca.dataModel.util.SeriesConfig getSeriesConfig(int index)
          Return a series config from the suite.
 int getSeriesConfigCount()
          Return the number of series config objects contained in the suite document.
 int[] getSeriesConfigCountByPattern(java.lang.String[] nicknamePatterns, java.lang.String[] namePatterns)
          Count the number of series configs that match the provided patterns.
 edu.sdsc.inca.dataModel.util.SeriesConfig[] getSeriesConfigs()
          Return all series configs in the suite as an array.
 edu.sdsc.inca.dataModel.suite.SuiteDocument getSuiteDocument()
          Return the root element of the suite document.
 boolean hasRunNowMatch(edu.sdsc.inca.dataModel.util.SeriesConfig runNow)
          Given the supplied run now series config, check to see if it has a match to a scheduled series config
 int mergeSeriesConfig(edu.sdsc.inca.dataModel.util.SeriesConfig seriesConfig)
          Append a new series config to the existing suite.
 void removeSeriesConfig(int index)
          Remove a specified series config from the suite.
 boolean removeSeriesConfig(edu.sdsc.inca.dataModel.util.SeriesConfig config)
          Remove a specified series config from the suite.
 void save(java.io.File saveTo)
          Save the suite to the specified file
 
Methods inherited from class edu.sdsc.inca.util.XmlWrapper
configEqual, createCron, cryptSensitive, escape, getPrettyPrintOptions, main, prettyPrint, read, save, unescape, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SuiteWrapper

public SuiteWrapper()
Create a new SuiteWrapper object containing a blank suite.


SuiteWrapper

public SuiteWrapper(edu.sdsc.inca.dataModel.suite.Suite suite)
             throws org.apache.xmlbeans.XmlException
Create a new SuiteWrapper object from an XML Beans class instance.

Parameters:
suite - An instance of Suite, a class generated by XmlBeans
Throws:
org.apache.xmlbeans.XmlException - if schema error

SuiteWrapper

public SuiteWrapper(edu.sdsc.inca.dataModel.suite.SuiteDocument suiteDoc)
             throws org.apache.xmlbeans.XmlException
Create a new SuiteWrapper object from an XML Beans class instance.

Parameters:
suiteDoc - An instance of SuiteDocument, a class generated by XmlBeans
Throws:
org.apache.xmlbeans.XmlException - if schema error

SuiteWrapper

public SuiteWrapper(java.lang.String filename)
             throws java.io.IOException,
                    org.apache.xmlbeans.XmlException
Create a new SuiteWrapper object from a suite XML file.

Parameters:
filename - Path to a file containing suite XML.
Throws:
java.io.IOException - if trouble reading file from disk
org.apache.xmlbeans.XmlException - if trouble parsing file
Method Detail

appendSeriesConfig

public void appendSeriesConfig(edu.sdsc.inca.dataModel.util.SeriesConfig seriesConfig)
Append a new series config to the existing suite.

Parameters:
seriesConfig - A new series config object to be added to the end of the existing suite.

changeAction

public void changeAction(java.lang.String action)
Change the action in all series configs found in the suite document.

Parameters:
action - The action to use in all series configs.

copySuiteAttributes

public void copySuiteAttributes(edu.sdsc.inca.dataModel.suite.SuiteDocument suiteDoc)
Copy the top level suite attributes: name, guid, and description to supplied suite document.

Parameters:
suiteDoc - A suite that where the top level suite attributes will be copied to

diff

public edu.sdsc.inca.dataModel.suite.SuiteDocument diff(edu.sdsc.inca.dataModel.suite.SuiteDocument suiteDoc)
                                                 throws org.apache.xmlbeans.XmlException
Compare the existing suite against the passed in suite and return the differences as adds and deletes.

Parameters:
suiteDoc - Another suite document to compare to the object's suite document.
Returns:
The differences between the suites returned as a suite document represented as adds and deletes.
Throws:
org.apache.xmlbeans.XmlException - if unable to create diff document

hasRunNowMatch

public boolean hasRunNowMatch(edu.sdsc.inca.dataModel.util.SeriesConfig runNow)
Given the supplied run now series config, check to see if it has a match to a scheduled series config

Parameters:
runNow - A series config with a run now schedule
Returns:
True if there is a match and false if not

getSeriesConfig

public edu.sdsc.inca.dataModel.util.SeriesConfig getSeriesConfig(int index)
Return a series config from the suite.

Parameters:
index - The index of the series config to return.
Returns:
The series config object.

getSeriesConfigs

public edu.sdsc.inca.dataModel.util.SeriesConfig[] getSeriesConfigs()
Return all series configs in the suite as an array.

Returns:
An array of series config objects from the suite document.

getSeriesConfigCount

public int getSeriesConfigCount()
Return the number of series config objects contained in the suite document.

Returns:
An integer containing the number of series config objects.

getSeriesConfigCountByPattern

public int[] getSeriesConfigCountByPattern(java.lang.String[] nicknamePatterns,
                                           java.lang.String[] namePatterns)
Count the number of series configs that match the provided patterns.

Parameters:
nicknamePatterns - Patterns that should be matched against the series nickname
namePatterns - Patterns that should be matched against the series reporter name
Returns:
An integer array of size nicknamePatterns.length + namePatterns.length + 1

mergeSeriesConfig

public int mergeSeriesConfig(edu.sdsc.inca.dataModel.util.SeriesConfig seriesConfig)
Append a new series config to the existing suite. If its counterpart is (add/delete) is already in the suite, don't add config to file and delete its counterpart.

Parameters:
seriesConfig - A new series config object to be added to suite
Returns:
1 if the change was added or -1 if the change was merged

getSuiteDocument

public edu.sdsc.inca.dataModel.suite.SuiteDocument getSuiteDocument()
Return the root element of the suite document.

Returns:
The suite root element of the suite document.

removeSeriesConfig

public void removeSeriesConfig(int index)
Remove a specified series config from the suite.

Parameters:
index - The index of the series config to delete.

removeSeriesConfig

public boolean removeSeriesConfig(edu.sdsc.inca.dataModel.util.SeriesConfig config)
Remove a specified series config from the suite.

Parameters:
config - The series config to delete from suite
Returns:
true if able to find and delete series config from suite; false otherwise

save

public void save(java.io.File saveTo)
          throws java.io.IOException
Save the suite to the specified file

Parameters:
saveTo - The file to save the suite to.
Throws:
java.io.IOException - if unable to save to disk