package mir.producer.reader;
import java.io.File;
+import java.io.Reader;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.Vector;
import mir.producer.CompositeProducerNode;
import mir.producer.ProducerFactory;
import mir.producer.ProducerNode;
import mir.producer.SimpleProducerVerb;
-import mir.util.XMLReader;
-import mir.util.*;
+import mir.util.ExceptionFunctions;
+import mir.util.xml.XMLParserEngine;
+import mir.util.xml.XMLParserExc;
+import mir.util.xml.XMLParserFailure;
public class ProducerConfigReader {
private ProducerNodeBuilderLibrary builderLibrary;
super();
};
- public void parseFile(String aFileName, ProducerNodeBuilderLibrary aBuilderLibrary, List aProducerFactories) throws ProducerConfigFailure {
- parseFile(aFileName, aBuilderLibrary, aProducerFactories, new Vector());
- }
-
- public void parseFile(String aFileName, ProducerNodeBuilderLibrary aBuilderLibrary, List aProducerFactories, List aUsedFiles) throws ProducerConfigFailure {
+ public void parse(Reader aReader, ProducerNodeBuilderLibrary aBuilderLibrary, List aProducerFactories) throws ProducerConfigFailure {
try {
- XMLReader reader = new XMLReader();
- aUsedFiles.add(new File(aFileName));
-
builderLibrary = aBuilderLibrary;
scriptedNodeBuilderLibrary = new ProducerNodeBuilderLibrary();
- reader.parseFile(aFileName, new RootSectionHandler(aProducerFactories));
+ XMLParserEngine.getInstance().parse("", aReader, new RootSectionHandler(aProducerFactories));
}
catch (Throwable e) {
Throwable root = ExceptionFunctions.traceCauseException(e);
- if ((root instanceof XMLReader.XMLReaderExc) && ((XMLReader.XMLReaderExc) root).getHasLocation()) {
- XMLReader.XMLReaderExc f = (XMLReader.XMLReaderExc) root;
- throw new ProducerConfigFailure("'" + f.getMessage()+"' in " + f.getFilename()+"(line " + f.getLineNr()+", column " + f.getColumnNr() + ")", e);
+ if ((root instanceof XMLParserExc) && ((XMLParserExc) root).getHasLocation()) {
+ XMLParserExc f = (XMLParserExc) root;
+ throw new ProducerConfigFailure(f.getMessage()+" on line " + f.getLineNr()+", column " + f.getColumnNr(), e);
}
throw new ProducerConfigFailure(root);
}
}
+ public void parse(File aFile, ProducerNodeBuilderLibrary aBuilderLibrary, List aProducerFactories) throws ProducerConfigFailure {
+ try {
+ builderLibrary = aBuilderLibrary;
+ scriptedNodeBuilderLibrary = new ProducerNodeBuilderLibrary();
+
+ XMLParserEngine.getInstance().parse("", aFile, new RootSectionHandler(aProducerFactories));
+
+ }
+ catch (Throwable e) {
+ Throwable root = ExceptionFunctions.traceCauseException(e);
+ if ((root instanceof XMLParserExc) && ((XMLParserExc) root).getHasLocation()) {
+ XMLParserExc f = (XMLParserExc) root;
+ throw new ProducerConfigFailure(f.getMessage()+" on line " + f.getLineNr()+", column " + f.getColumnNr(), e);
+ }
+ throw new ProducerConfigFailure(root);
+ }
+ }
- public class RootSectionHandler extends XMLReader.AbstractSectionHandler {
+ public class RootSectionHandler extends mir.util.xml.AbstractSectionHandler {
private List producers;
public RootSectionHandler(List aProducers) {
producers = aProducers;
}
- public XMLReader.SectionHandler startElement(String aTag, Map anAttributes) throws XMLReader.XMLReaderExc {
+ public mir.util.xml.SectionHandler startElement(String aTag, Map anAttributes) throws XMLParserExc {
if (aTag.equals("producers")) {
return new ProducersSectionHandler(producers);
}
else
- throw new XMLReader.XMLReaderExc("Tag 'producers' expected, tag '"+aTag+"' found");
+ throw new XMLParserExc("Tag 'producers' expected, tag '"+aTag+"' found");
}
- public void endElement(XMLReader.SectionHandler aHandler) {
+ public void endElement(mir.util.xml.SectionHandler aHandler) {
}
public void finishSection() {
}
}
-
private final static String PRODUCER_NAME_ATTRIBUTE = "name";
private final static String[] PRODUCER_REQUIRED_ATTRIBUTES = { PRODUCER_NAME_ATTRIBUTE };
private final static String[] PRODUCER_OPTIONAL_ATTRIBUTES = { };
private final static String[] NODE_DEFINITION_REQUIRED_ATTRIBUTES = { NODE_DEFINITION_NAME_ATTRIBUTE };
private final static String[] NODE_DEFINITION_OPTIONAL_ATTRIBUTES = { };
- public class ProducersSectionHandler extends XMLReader.AbstractSectionHandler {
+ public class ProducersSectionHandler extends mir.util.xml.AbstractSectionHandler {
private List producers;
private Set producerNames;
private String name;
producerNames = new HashSet();
}
- public XMLReader.SectionHandler startElement(String aTag, Map anAttributes) throws XMLReader.XMLReaderExc {
+ public mir.util.xml.SectionHandler startElement(String aTag, Map anAttributes) throws XMLParserExc {
if (aTag.equals("producer")) {
- XMLReaderTool.checkAttributes(anAttributes,
+ mir.util.xml.XMLReaderTool.checkAttributes(anAttributes,
PRODUCER_REQUIRED_ATTRIBUTES,
PRODUCER_OPTIONAL_ATTRIBUTES);
name = (String) anAttributes.get(PRODUCER_NAME_ATTRIBUTE);
- XMLReaderTool.checkValidIdentifier(name);
+ mir.util.xml.XMLReaderTool.checkValidIdentifier(name);
if (producerNames.contains(name))
- throw new XMLReader.XMLReaderExc("Duplicate producer name: '" +
+ throw new XMLParserExc("Duplicate producer name: '" +
name + "'");
name = (String) anAttributes.get(PRODUCER_NAME_ATTRIBUTE);
return new ProducerSectionHandler(name);
}
else if (aTag.equals("nodedefinition")) {
- XMLReaderTool.checkAttributes(anAttributes,
+ mir.util.xml.XMLReaderTool.checkAttributes(anAttributes,
NODE_DEFINITION_REQUIRED_ATTRIBUTES,
NODE_DEFINITION_OPTIONAL_ATTRIBUTES);
name = (String) anAttributes.get(NODE_DEFINITION_NAME_ATTRIBUTE);
- XMLReaderTool.checkValidIdentifier(name);
+ mir.util.xml.XMLReaderTool.checkValidIdentifier(name);
name = (String) anAttributes.get(NODE_DEFINITION_NAME_ATTRIBUTE);
return new NodeDefinitionSectionHandler(name);
}
- throw new XMLReader.XMLReaderExc("Unexpected tag: " + aTag);
+ throw new XMLParserExc("Unexpected tag: " + aTag);
}
- public void endElement(XMLReader.SectionHandler aHandler) throws XMLReader.XMLReaderExc {
+ public void endElement(mir.util.xml.SectionHandler aHandler) throws XMLParserExc {
if (aHandler instanceof ProducerSectionHandler) {
producers.add(((ProducerSectionHandler) aHandler).getProducerFactory());
producerNames.add(((ProducerSectionHandler) aHandler).getProducerFactory().getName());
new DefaultProducerNodeBuilders.ScriptedProducerNodeBuilder.factory(
((NodeDefinitionSectionHandler) aHandler).getDefinition()));
}
- else throw new XMLReader.XMLReaderExc("ProducersSectionHandler.endElement Internal error: Unexpected handler: " + aHandler.getClass().getName());
+ else throw new XMLParserExc("ProducersSectionHandler.endElement Internal error: Unexpected handler: " + aHandler.getClass().getName());
}
public void finishSection() {
}
}
- public class ProducerSectionHandler extends XMLReader.AbstractSectionHandler {
+ public class ProducerSectionHandler extends mir.util.xml.AbstractSectionHandler {
private ProducerFactory producerFactory;
private String factoryName;
factoryName = aName;
}
- public XMLReader.SectionHandler startElement(String aTag, Map anAttributes) throws XMLReader.XMLReaderExc {
+ public mir.util.xml.SectionHandler startElement(String aTag, Map anAttributes) throws XMLParserExc {
if (aTag.equals("verbs")) {
if (verbs!=null)
- throw new XMLReader.XMLReaderExc("Verbs already processed");
+ throw new XMLParserExc("Verbs already processed");
if (body!=null)
- throw new XMLReader.XMLReaderExc("Verbs should come before body");
+ throw new XMLParserExc("Verbs should come before body");
else
return new ProducerVerbsSectionHandler();
}
if (body==null)
return new ProducerNodeSectionHandler();
else
- throw new XMLReader.XMLReaderExc("Body already processed");
+ throw new XMLParserExc("Body already processed");
}
- throw new XMLReader.XMLReaderExc("Unexpected tag: '"+aTag+"'");
+ throw new XMLParserExc("Unexpected tag: '"+aTag+"'");
}
- public void endElement(XMLReader.SectionHandler aHandler) throws XMLReader.XMLReaderExc {
+ public void endElement(mir.util.xml.SectionHandler aHandler) throws XMLParserExc {
if (aHandler instanceof ProducerNodeSectionHandler) {
body = ((ProducerNodeSectionHandler) aHandler).getProducerNode();
}
verbNodes = ((ProducerVerbsSectionHandler) aHandler).getVerbNodes();
defaultVerb = ((ProducerVerbsSectionHandler) aHandler).getDefaultVerb();
}
- else throw new XMLReader.XMLReaderExc("ProducerSectionHandler.endElement Internal error: Unexpected handler: " + aHandler.getClass().getName());
+ else throw new XMLParserExc("ProducerSectionHandler.endElement Internal error: Unexpected handler: " + aHandler.getClass().getName());
}
- public void finishSection() throws XMLReader.XMLReaderExc {
+ public void finishSection() throws XMLParserExc {
if (verbs==null)
- throw new XMLReader.XMLReaderExc("No verbs defined");
+ throw new XMLParserExc("No verbs defined");
if (body==null)
- throw new XMLReader.XMLReaderExc("No body defined");
+ throw new XMLParserExc("No body defined");
producerFactory = new ScriptedProducerFactory(factoryName, verbs, verbNodes, body, defaultVerb);
}
private final static String[] PRODUCER_VERB_REQUIRED_ATTRIBUTES = { PRODUCER_VERB_NAME_ATTRIBUTE };
private final static String[] PRODUCER_VERB_OPTIONAL_ATTRIBUTES = { PRODUCER_VERB_DEFAULT_ATTRIBUTE, PRODUCER_VERB_DESCRIPTION_ATTRIBUTE };
- public class ProducerVerbsSectionHandler extends XMLReader.AbstractSectionHandler {
+ public class ProducerVerbsSectionHandler extends mir.util.xml.AbstractSectionHandler {
private Map verbNodes;
private List verbs;
private String defaultVerb;
public ProducerVerbsSectionHandler() {
verbNodes = new HashMap();
- verbs = new Vector();
+ verbs = new ArrayList();
defaultVerb = null;
}
- public XMLReader.SectionHandler startElement(String aTag, Map anAttributes) throws XMLReader.XMLReaderExc {
+ public mir.util.xml.SectionHandler startElement(String aTag, Map anAttributes) throws XMLParserExc {
if (aTag.equals("verb")) {
- XMLReaderTool.checkAttributes(anAttributes,
+ mir.util.xml.XMLReaderTool.checkAttributes(anAttributes,
PRODUCER_VERB_REQUIRED_ATTRIBUTES,
PRODUCER_VERB_OPTIONAL_ATTRIBUTES);
currentVerb = (String) anAttributes.get(PRODUCER_VERB_NAME_ATTRIBUTE);
- XMLReaderTool.checkValidIdentifier(currentVerb);
+ mir.util.xml.XMLReaderTool.checkValidIdentifier(currentVerb);
if (verbNodes.containsKey(currentVerb))
- throw new XMLReader.XMLReaderExc("Duplicate definition of verb '" +
+ throw new XMLParserExc("Duplicate definition of verb '" +
currentVerb + "'");
if (anAttributes.containsKey(PRODUCER_VERB_DEFAULT_ATTRIBUTE)) {
if (defaultVerb != null)
- throw new XMLReader.XMLReaderExc("Default verb already declared");
+ throw new XMLParserExc("Default verb already declared");
defaultVerb = currentVerb;
}
return new ProducerNodeSectionHandler();
}
else
- throw new XMLReader.XMLReaderExc("Only 'verb' tags allowed here, '" + aTag + "' encountered.");
+ throw new XMLParserExc("Only 'verb' tags allowed here, '" + aTag + "' encountered.");
}
- public void endElement(XMLReader.SectionHandler aHandler) {
+ public void endElement(mir.util.xml.SectionHandler aHandler) {
verbNodes.put(currentVerb, ((ProducerNodeSectionHandler) aHandler).getProducerNode());
verbs.add(new SimpleProducerVerb(currentVerb, currentVerbDescription));
}
}
}
- public class EmptySectionHandler extends XMLReader.AbstractSectionHandler {
- public XMLReader.SectionHandler startElement(String aTag, Map anAttributes) throws XMLReader.XMLReaderExc {
- throw new XMLReader.XMLReaderExc("No tags are allowed here");
+ public class EmptySectionHandler extends mir.util.xml.AbstractSectionHandler {
+ public mir.util.xml.SectionHandler startElement(String aTag, Map anAttributes) throws XMLParserExc {
+ throw new XMLParserExc("No tags are allowed here");
}
- public void endElement(XMLReader.SectionHandler aHandler) {
+ public void endElement(mir.util.xml.SectionHandler aHandler) {
}
public void finishSection() {
}
}
- public class MultiProducerNodeSectionHandler extends XMLReader.AbstractSectionHandler {
+ public class MultiProducerNodeSectionHandler extends mir.util.xml.AbstractSectionHandler {
private Map nodeParameters;
private Set validNodeParameters;
private String currentNodeParameter;
this("", new HashSet(), aValidNodeParameters);
}
- public XMLReader.SectionHandler startElement(String aTag, Map anAttributes) throws XMLReader.XMLReaderExc {
+ public mir.util.xml.SectionHandler startElement(String aTag, Map anAttributes) throws XMLParserExc {
if (!validNodeParameters.contains(aTag))
- throw new XMLReader.XMLReaderExc("Invalid node parameter: '" + aTag + "'");
+ throw new XMLParserExc("Invalid node parameter: '" + aTag + "'");
else if (nodeParameters.containsKey(aTag))
- throw new XMLReader.XMLReaderExc("Node parameter: '" + aTag + "' already specified");
+ throw new XMLParserExc("Node parameter: '" + aTag + "' already specified");
else if (anAttributes.size()>0)
- throw new XMLReader.XMLReaderExc("No parameters are allowed here");
+ throw new XMLParserExc("No parameters are allowed here");
currentNodeParameter = aTag;
return new ProducerNodeSectionHandler(scriptedNodeName, allowedNodeParameterReferences);
}
- public void endElement(XMLReader.SectionHandler aHandler) throws XMLReader.XMLReaderExc {
+ public void endElement(mir.util.xml.SectionHandler aHandler) throws XMLParserExc {
if (aHandler instanceof ProducerNodeSectionHandler) {
nodeParameters.put(currentNodeParameter, ((ProducerNodeSectionHandler) aHandler).getProducerNode());
}
else {
- throw new XMLReader.XMLReaderExc("Internal error: unknown section handler '" + aHandler.getClass().getName() + "'" );
+ throw new XMLParserExc("Internal error: unknown section handler '" + aHandler.getClass().getName() + "'" );
}
}
}
}
- public class ProducerNodeSectionHandler extends XMLReader.AbstractSectionHandler {
+ public class ProducerNodeSectionHandler extends mir.util.xml.AbstractSectionHandler {
private CompositeProducerNode producerNode;
private ProducerNodeBuilder currentBuilder;
private String scriptedNodeName;
this("", new HashSet());
}
- public XMLReader.SectionHandler startElement(String aTag, Map anAttributes) throws XMLReader.XMLReaderExc {
+ public mir.util.xml.SectionHandler startElement(String aTag, Map anAttributes) throws XMLParserExc {
try {
if (allowedNodeParameterReferences.contains( (aTag))) {
if (!anAttributes.isEmpty()) {
- throw new XMLReader.XMLReaderExc("No attributes allowed");
+ throw new XMLParserExc("No attributes allowed");
}
currentBuilder = new DefaultProducerNodeBuilders.
}
}
else
- throw new XMLReader.XMLReaderExc("Unknown producer node tag: '" + aTag + "'");
+ throw new XMLParserExc("Unknown producer node tag: '" + aTag + "'");
}
catch (Throwable t) {
- throw new XMLReader.XMLReaderFailure(t);
+ throw new XMLParserFailure(t);
}
}
- public void endElement(XMLReader.SectionHandler aHandler) throws XMLReader.XMLReaderExc {
+ public void endElement(mir.util.xml.SectionHandler aHandler) throws XMLParserExc {
try {
if (aHandler instanceof ProducerNodeSectionHandler) {
currentBuilder.setSubNode(
// deliberately empty: nothing expected, so nothing to process
}
else {
- throw new XMLReader.XMLReaderExc(
+ throw new XMLParserExc(
"Internal error: unknown section handler '" +
aHandler.getClass().getName() + "'");
}
currentBuilder = null;
}
catch (Throwable t) {
- throw new XMLReader.XMLReaderFailure(t);
+ throw new XMLParserFailure(t);
}
}
}
}
- public class NodeDefinitionSectionHandler extends XMLReader.AbstractSectionHandler {
+ public class NodeDefinitionSectionHandler extends mir.util.xml.AbstractSectionHandler {
private ScriptedProducerNodeDefinition nodeDefinition;
private ProducerNode body;
private Map stringParameters;
name = aName;
}
- public XMLReader.SectionHandler startElement(String aTag, Map anAttributes) throws XMLReader.XMLReaderExc {
+ public mir.util.xml.SectionHandler startElement(String aTag, Map anAttributes) throws XMLParserExc {
if (aTag.equals("parameters")) {
if (!anAttributes.isEmpty()) {
- throw new XMLReader.XMLReaderExc( "No attributes allowed for tag 'parameters'" );
+ throw new XMLParserExc( "No attributes allowed for tag 'parameters'" );
}
if (nodeParameters!=null) {
- throw new XMLReader.XMLReaderExc( "Parameters have already been declared" );
+ throw new XMLParserExc( "Parameters have already been declared" );
}
if (body!=null) {
- throw new XMLReader.XMLReaderExc( "Parameters should come before definition in nodedefinition '" + name +"'" );
+ throw new XMLParserExc( "Parameters should come before definition in nodedefinition '" + name +"'" );
}
return new NodeDefinitionParametersSectionHandler();
}
else if (aTag.equals("definition")) {
if (nodeParameters==null)
- throw new XMLReader.XMLReaderExc( "Parameters should come before definition in nodedefinition '" + name +"'" );
+ throw new XMLParserExc( "Parameters should come before definition in nodedefinition '" + name +"'" );
return new ProducerNodeSectionHandler(name, nodeParameters.keySet());
}
- else throw new XMLReader.XMLReaderExc("Only 'definition' or 'parameters' tags allowed here, '" + aTag + "' encountered.");
+ else throw new XMLParserExc("Only 'definition' or 'parameters' tags allowed here, '" + aTag + "' encountered.");
}
- public void endElement(XMLReader.SectionHandler aHandler) {
+ public void endElement(mir.util.xml.SectionHandler aHandler) {
if (aHandler instanceof NodeDefinitionParametersSectionHandler) {
stringParameters = ((NodeDefinitionParametersSectionHandler) aHandler).getStringParameters();
integerParameters = ((NodeDefinitionParametersSectionHandler) aHandler).getIntegerParameters();
}
}
- public void finishSection() throws XMLReader.XMLReaderExc {
+ public void finishSection() throws XMLParserExc {
Iterator i;
if (body == null)
- throw new XMLReader.XMLReaderExc( "Definition missing" );
+ throw new XMLParserExc( "Definition missing" );
nodeDefinition = new ScriptedProducerNodeDefinition(name);
private final static String[] NODE_DEFINITION_PARAMETER_OPTIONAL_ATTRIBUTES = { NODE_DEFINITION_PARAMETER_DEFAULTVALUE_ATTRIBUTE };
private final static String[] NODE_DEFINITION_NODE_PARAMETER_OPTIONAL_ATTRIBUTES = { };
- public class NodeDefinitionParametersSectionHandler extends XMLReader.AbstractSectionHandler {
+ public class NodeDefinitionParametersSectionHandler extends mir.util.xml.AbstractSectionHandler {
private Map nodeParameters;
private Map stringParameters;
private Map integerParameters;
integerParameters = new HashMap();
}
- public XMLReader.SectionHandler startElement(String aTag, Map anAttributes) throws XMLReader.XMLReaderExc {
+ public mir.util.xml.SectionHandler startElement(String aTag, Map anAttributes) throws XMLParserExc {
String parameterName;
String defaultValue;
if (aTag.equals("node")) {
- XMLReaderTool.checkAttributes(anAttributes,
+ mir.util.xml.XMLReaderTool.checkAttributes(anAttributes,
NODE_DEFINITION_PARAMETER_REQUIRED_ATTRIBUTES,
NODE_DEFINITION_NODE_PARAMETER_OPTIONAL_ATTRIBUTES);
parameterName = (String) anAttributes.get(
NODE_DEFINITION_PARAMETER_NAME_ATTRIBUTE);
if (nodeParameters.containsKey(parameterName))
- throw new XMLReader.XMLReaderExc("Duplicate parameter name: '" +
+ throw new XMLParserExc("Duplicate parameter name: '" +
parameterName + "'");
- XMLReaderTool.checkValidIdentifier(parameterName);
+ mir.util.xml.XMLReaderTool.checkValidIdentifier(parameterName);
nodeParameters.put(parameterName, parameterName);
return new EmptySectionHandler();
}
else if (aTag.equals("string") || aTag.equals("integer")) {
- XMLReaderTool.checkAttributes(anAttributes,
+ mir.util.xml.XMLReaderTool.checkAttributes(anAttributes,
NODE_DEFINITION_PARAMETER_REQUIRED_ATTRIBUTES,
NODE_DEFINITION_PARAMETER_OPTIONAL_ATTRIBUTES);
parameterName = (String) anAttributes.get(
if (stringParameters.containsKey(parameterName) ||
integerParameters.containsKey(parameterName))
- throw new XMLReader.XMLReaderExc("Duplicate parameter name: '" +
+ throw new XMLParserExc("Duplicate parameter name: '" +
parameterName + "'");
- XMLReaderTool.checkValidIdentifier(parameterName);
+ mir.util.xml.XMLReaderTool.checkValidIdentifier(parameterName);
defaultValue = (String) anAttributes.get(
NODE_DEFINITION_PARAMETER_DEFAULTVALUE_ATTRIBUTE);
return new EmptySectionHandler();
}
else
- throw new XMLReader.XMLReaderExc(
+ throw new XMLParserExc(
"Only 'string', 'integer' and 'node' tags allowed here, '" + aTag + "' encountered.");
}
- public void endElement(XMLReader.SectionHandler aHandler) {
+ public void endElement(mir.util.xml.SectionHandler aHandler) {
}
public void finishSection() {