Package repast.simphony.parameter.xml
Class ParameterSweepParser
- java.lang.Object
-
- org.xml.sax.helpers.DefaultHandler
-
- org.xml.sax.ext.DefaultHandler2
-
- repast.simphony.parameter.xml.ParameterSweepParser
-
- All Implemented Interfaces:
ContentHandler
,DTDHandler
,EntityResolver
,ErrorHandler
,DeclHandler
,EntityResolver2
,LexicalHandler
public class ParameterSweepParser extends DefaultHandler2
Parses a parameters xml file and creates ParameterTreeSweeper based on that. Additional ParameterSetterCreators can be registered for dealing with additional parameter types using the registerSetterCreator method.- Version:
- $Revision$ $Date$
- Author:
- Nick Collier
-
-
Constructor Summary
Constructors Constructor Description ParameterSweepParser(InputStream in)
ParameterSweepParser(URL paramsURL)
Creates a ParameterSweepParser to parse the specified URL.ParameterSweepParser(ParameterTreeSweeper sweeper, URL paramsURL)
Creates a ParameterSweeper parser to use the specified sweeper and to parse the specified URL.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
endElement(String uri, String localName, String qName)
void
inputFile(String input)
Method writes out string content to a batch xml file used for temporary data storage.protected boolean
isDouble(String val)
protected boolean
isFloat(String val)
protected boolean
isInt(Double value)
protected boolean
isLong(String val)
Pair<Parameters,ParameterTreeSweeper>
parse()
Parse the url and return the created ParameterTreeSweeper.String
readFile(URL url, int size)
Method reads file URL and size (based on content) and returns a string representation of that content.void
registerConstantCreator(String constantTypeID, ParameterSetterCreator creator)
Register a setter creator to be used for constant setters during sweeper creation.void
registerStepperCreator(String typeID, ParameterSetterCreator creator)
Register a setter creator to be used during sweeper creation.void
startElement(String uri, String localName, String qName, Attributes attributes)
-
Methods inherited from class org.xml.sax.ext.DefaultHandler2
attributeDecl, comment, elementDecl, endCDATA, endDTD, endEntity, externalEntityDecl, getExternalSubset, internalEntityDecl, resolveEntity, resolveEntity, startCDATA, startDTD, startEntity
-
Methods inherited from class org.xml.sax.helpers.DefaultHandler
characters, endDocument, endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, setDocumentLocator, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl, warning
-
-
-
-
Constructor Detail
-
ParameterSweepParser
public ParameterSweepParser(URL paramsURL)
Creates a ParameterSweepParser to parse the specified URL.- Parameters:
paramsURL
-
-
ParameterSweepParser
public ParameterSweepParser(InputStream in)
-
ParameterSweepParser
public ParameterSweepParser(ParameterTreeSweeper sweeper, URL paramsURL)
Creates a ParameterSweeper parser to use the specified sweeper and to parse the specified URL.- Parameters:
sweeper
-paramsURL
-
-
-
Method Detail
-
parse
public Pair<Parameters,ParameterTreeSweeper> parse() throws ParserConfigurationException, SAXException, IOException
Parse the url and return the created ParameterTreeSweeper.- Returns:
- the created ParameterTreeSweeper.
- Throws:
ParserConfigurationException
SAXException
IOException
-
inputFile
public void inputFile(String input) throws IOException
Method writes out string content to a batch xml file used for temporary data storage.- Parameters:
input
- the input string to write out- Throws:
IOException
-
readFile
public String readFile(URL url, int size) throws IOException
Method reads file URL and size (based on content) and returns a string representation of that content.- Parameters:
url
- the file urlsize
- the size of the file- Returns:
- a string representation of the parameters
- Throws:
IOException
-
registerStepperCreator
public void registerStepperCreator(String typeID, ParameterSetterCreator creator)
Register a setter creator to be used during sweeper creation. When a parameter element whose "type" attribute is equal to the specified typeID is encountered, the specified creator will be used to create the ParameterSetter. The attributes of that element will be passed to the creator so that it can create the setter.- Parameters:
typeID
-creator
-
-
registerConstantCreator
public void registerConstantCreator(String constantTypeID, ParameterSetterCreator creator)
Register a setter creator to be used for constant setters during sweeper creation. When a parameter element whose "constant type" attribute is equal to the specified typeID is encountered, the specified creator will be used to create the ParameterSetter. The attributes of that element will be passed to the creator so that it can create the constant setter.- Parameters:
constantTypeID
- matches agains the constant_type attribute.creator
-
-
startElement
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException
- Specified by:
startElement
in interfaceContentHandler
- Overrides:
startElement
in classDefaultHandler
- Throws:
SAXException
-
endElement
public void endElement(String uri, String localName, String qName) throws SAXException
- Specified by:
endElement
in interfaceContentHandler
- Overrides:
endElement
in classDefaultHandler
- Throws:
SAXException
-
isDouble
protected boolean isDouble(String val)
-
isLong
protected boolean isLong(String val)
-
isFloat
protected boolean isFloat(String val)
-
isInt
protected boolean isInt(Double value)
-
-