2 * Copyright (C) 2001, 2002 The Mir-coders group
4 * This file is part of Mir.
6 * Mir is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * Mir is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Mir; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * In addition, as a special exception, The Mir-coders gives permission to link
21 * the code of this program with the com.oreilly.servlet library, any library
22 * licensed under the Apache Software License, The Sun (tm) Java Advanced
23 * Imaging library (JAI), The Sun JIMI library (or with modified versions of
24 * the above that use the same license as the above), and distribute linked
25 * combinations including the two. You must obey the GNU General Public
26 * License in all respects for all of the code used other than the above
27 * mentioned libraries. If you modify this file, you may extend this exception
28 * to your version of the file, but you are not obligated to do so. If you do
29 * not wish to do so, delete this exception statement from your version.
32 package mir.producer.reader;
36 import java.lang.System;
37 import org.xml.sax.helpers.DefaultHandler;
39 import javax.xml.parsers.ParserConfigurationException;
40 import javax.xml.parsers.SAXParser;
41 import javax.xml.parsers.SAXParserFactory;
44 import mir.config.exceptions.*;
45 import mir.producer.*;
47 //import mir.producer.exceptions.*;
48 import mir.misc.Location;
50 public class ProducerConfigReader {
51 private ProducerNodeBuilderLibrary builderLibrary;
52 private ProducerNodeBuilderLibrary scriptedNodeBuilderLibrary;
54 public ProducerConfigReader() {
58 public void parseFile(String aFileName, ProducerNodeBuilderLibrary aBuilderLibrary, List aProducerFactories) throws ProducerConfigFailure {
59 parseFile(aFileName, aBuilderLibrary, aProducerFactories, new Vector());
62 public void parseFile(String aFileName, ProducerNodeBuilderLibrary aBuilderLibrary, List aProducerFactories, List aUsedFiles) throws ProducerConfigFailure {
64 builderLibrary = aBuilderLibrary;
65 scriptedNodeBuilderLibrary = new ProducerNodeBuilderLibrary();
67 SAXParserFactory parserFactory = SAXParserFactory.newInstance();
69 parserFactory.setNamespaceAware(false);
70 parserFactory.setValidating(true);
72 ProducerConfigHandler handler = new ProducerConfigHandler(parserFactory, aProducerFactories, aUsedFiles);
74 handler.includeFile(aFileName);
77 if (e instanceof SAXParseException && ((SAXParseException) e).getException() instanceof ProducerConfigFailure) {
78 throw (ProducerConfigFailure) ((SAXParseException) e).getException();
81 throw new ProducerConfigFailure( e );
86 private class ProducerConfigHandler extends DefaultHandler {
87 private Locator locator;
88 private Stack includeFileStack;
89 private SAXParserFactory parserFactory;
90 private SectionsManager manager;
91 private List usedFiles;
92 private InputSource inputSource;
94 public ProducerConfigHandler(SAXParserFactory aParserFactory, List aProducers, List aUsedFiles) {
97 includeFileStack=new Stack();
98 parserFactory=aParserFactory;
99 includeFileStack = new Stack();
100 manager = new SectionsManager();
101 usedFiles = aUsedFiles;
103 manager.pushHandler(new RootSectionHandler(aProducers));
106 public String getLocatorDescription(Locator aLocator) {
107 return aLocator.getPublicId()+" ("+aLocator.getLineNumber()+")";
110 public void setDocumentLocator(Locator aLocator) {
114 private void includeFile(String aFileName) throws ProducerConfigExc, ProducerConfigFailure, SAXParseException, SAXException {
119 if (!includeFileStack.empty())
120 file = new File(new File((String) includeFileStack.peek()).getParent(), aFileName);
122 file = new File(aFileName);
124 System.err.println("about to include "+file.getCanonicalPath());
126 if (includeFileStack.contains(file.getCanonicalPath())) {
127 throw new ProducerConfigExc("recursive inclusion of file "+file.getCanonicalPath());
132 parser=parserFactory.newSAXParser();
134 inputSource = new InputSource(new FileInputStream(file));
135 inputSource.setPublicId(file.getCanonicalPath());
137 includeFileStack.push(file.getCanonicalPath());
139 parser.parse(inputSource, this);
142 includeFileStack.pop();
145 catch (ParserConfigurationException e) {
146 throw new ProducerConfigExc("Internal exception while including \""+aFileName+"\": "+e.getMessage());
148 catch (SAXParseException e) {
151 catch (ProducerConfigFailure e) {
154 catch (FileNotFoundException e) {
155 throw new ProducerConfigExc("Include file \""+aFileName+"\" not found: "+e.getMessage());
157 catch (IOException e) {
158 throw new ProducerConfigExc("unable to open include file \""+aFileName+"\": "+e.getMessage());
162 public void startElement(String aUri, String aTag, String aQualifiedName, Attributes anAttributes) throws SAXException {
167 if (aQualifiedName.equals("include")) {
168 String fileName=anAttributes.getValue("file");
170 if (fileName==null) {
171 throw new ProducerConfigExc("include has no file attribute");
174 includeFile(fileName);
177 attributesMap = new HashMap();
178 for (i=0; i<anAttributes.getLength(); i++)
179 attributesMap.put(anAttributes.getQName(i), anAttributes.getValue(i));
181 manager.pushHandler( manager.currentHandler().startElement(aQualifiedName, attributesMap) );
184 catch (ProducerConfigExc e) {
185 throw new SAXParseException(e.getMessage(), locator, new ProducerConfigExc("Config error at ["+getLocatorDescription(locator)+"]: "+e.getMessage()));
187 catch (Exception e) {
188 throw new SAXException(e);
192 public void endElement(String aUri, String aTag, String aQualifiedName) throws SAXException {
195 if (!aQualifiedName.equals("include")) {
196 SectionHandler handler = manager.popHandler();
198 handler.finishSection();
200 if (!manager.isEmpty()) {
201 manager.currentHandler().endElement(handler);
205 catch (ProducerConfigExc e) {
206 throw new SAXParseException(e.getMessage(), locator, new ProducerConfigExc("Config error at ["+getLocatorDescription(locator)+"]: "+e.getMessage()));
208 catch (Exception e) {
209 throw new SAXException(e);
213 public void characters(char[] aBuffer, int aStart, int anEnd) throws SAXParseException {
214 String text = new String(aBuffer, aStart, anEnd).trim();
215 if ( text.length() > 0) {
216 throw new SAXParseException("Text not allowed", locator, new ProducerConfigExc("Config error at ["+getLocatorDescription(locator)+"]: Text not allowed"));
221 public class SectionsManager {
224 public SectionsManager() {
225 handlerStack = new Stack();
228 public void pushHandler(SectionHandler aSectionHandler) {
229 handlerStack.push(aSectionHandler);
232 public SectionHandler popHandler() {
233 return (SectionHandler) handlerStack.pop();
236 public SectionHandler currentHandler() {
237 return (SectionHandler) handlerStack.peek();
240 public boolean isEmpty() {
241 return handlerStack.isEmpty();
245 public abstract class SectionHandler {
246 public abstract SectionHandler startElement(String aTag, Map anAttributes) throws ProducerConfigExc;
248 public abstract void endElement(SectionHandler aHandler) throws ProducerConfigExc;
252 public void finishSection() throws ProducerConfigExc {
256 public class RootSectionHandler extends SectionHandler {
257 private List producers;
259 public RootSectionHandler(List aProducers) {
260 producers = aProducers;
263 public SectionHandler startElement(String aTag, Map anAttributes) throws ProducerConfigExc {
264 if (aTag.equals("producers")) {
265 return new ProducersSectionHandler(producers);
268 throw new ProducerConfigExc ("Tag 'producers' expected, tag '"+aTag+"' found");
271 public void endElement(SectionHandler aHandler) {
274 public void finishSection() throws ProducerConfigExc {
279 private final static String PRODUCER_NAME_ATTRIBUTE = "name";
280 private final static String[] PRODUCER_REQUIRED_ATTRIBUTES = { PRODUCER_NAME_ATTRIBUTE };
281 private final static String[] PRODUCER_OPTIONAL_ATTRIBUTES = { };
283 private final static String NODE_DEFINITION_NAME_ATTRIBUTE = "name";
284 private final static String[] NODE_DEFINITION_REQUIRED_ATTRIBUTES = { NODE_DEFINITION_NAME_ATTRIBUTE };
285 private final static String[] NODE_DEFINITION_OPTIONAL_ATTRIBUTES = { };
287 public class ProducersSectionHandler extends SectionHandler {
288 private List producers;
289 private Set producerNames;
292 public ProducersSectionHandler(List aProducers) {
293 producers = aProducers;
294 producerNames = new HashSet();
297 public SectionHandler startElement(String aTag, Map anAttributes) throws ProducerConfigExc {
299 if (aTag.equals("producer")) {
300 ReaderTool.checkAttributes(anAttributes, PRODUCER_REQUIRED_ATTRIBUTES, PRODUCER_OPTIONAL_ATTRIBUTES);
302 name = (String) anAttributes.get(PRODUCER_NAME_ATTRIBUTE);
303 ReaderTool.checkValidIdentifier( name );
305 if (producerNames.contains(name))
306 throw new ProducerConfigExc("Duplicate producer name: '" + name + "'");
308 name = (String) anAttributes.get(PRODUCER_NAME_ATTRIBUTE);
310 return new ProducerSectionHandler(name);
312 else if (aTag.equals("nodedefinition")) {
313 ReaderTool.checkAttributes(anAttributes, NODE_DEFINITION_REQUIRED_ATTRIBUTES, NODE_DEFINITION_OPTIONAL_ATTRIBUTES);
315 name = (String) anAttributes.get(NODE_DEFINITION_NAME_ATTRIBUTE);
316 ReaderTool.checkValidIdentifier( name );
318 // if (producers.containsKey(name))
319 // throw new ProducerConfigExc("Duplicate producer name: '" + name + "'");
321 name = (String) anAttributes.get(NODE_DEFINITION_NAME_ATTRIBUTE);
323 return new NodeDefinitionSectionHandler(name);
326 throw new ProducerConfigExc("Unexpected tag: "+aTag );
329 public void endElement(SectionHandler aHandler) throws ProducerConfigExc {
330 if (aHandler instanceof ProducerSectionHandler) {
331 producers.add(((ProducerSectionHandler) aHandler).getProducerFactory());
332 producerNames.add(((ProducerSectionHandler) aHandler).getProducerFactory().getName());
334 else if (aHandler instanceof NodeDefinitionSectionHandler) {
335 scriptedNodeBuilderLibrary.registerFactory(name,
336 new DefaultProducerNodeBuilders.ScriptedProducerNodeBuilder.factory(
337 ((NodeDefinitionSectionHandler) aHandler).getDefinition()));
339 else throw new ProducerConfigExc("ProducersSectionHandler.endElement Internal error: Unexpected handler: " + aHandler.getClass().getName());
342 public void finishSection() throws ProducerConfigExc {
346 public class ProducerSectionHandler extends SectionHandler {
347 private ProducerFactory producerFactory;
348 private String factoryName;
350 private ProducerNode body;
351 private Map verbNodes;
353 private String defaultVerb;
355 public ProducerSectionHandler(String aName) {
359 public SectionHandler startElement(String aTag, Map anAttributes) throws ProducerConfigExc {
360 if (aTag.equals("verbs")) {
362 throw new ProducerConfigExc("Verbs already processed");
364 throw new ProducerConfigExc("Verbs should come before body");
366 return new ProducerVerbsSectionHandler();
368 else if (aTag.equals("body")) {
370 return new ProducerNodeSectionHandler();
372 throw new ProducerConfigExc("Body already processed");
374 throw new ProducerConfigExc("Unexpected tag: '"+aTag+"'");
377 public void endElement(SectionHandler aHandler) throws ProducerConfigExc {
378 if (aHandler instanceof ProducerNodeSectionHandler) {
379 body = ((ProducerNodeSectionHandler) aHandler).getProducerNode();
381 else if (aHandler instanceof ProducerVerbsSectionHandler)
383 verbs = ((ProducerVerbsSectionHandler) aHandler).getVerbs();
384 verbNodes = ((ProducerVerbsSectionHandler) aHandler).getVerbNodes();
385 defaultVerb = ((ProducerVerbsSectionHandler) aHandler).getDefaultVerb();
387 else throw new ProducerConfigExc("ProducerSectionHandler.endElement Internal error: Unexpected handler: " + aHandler.getClass().getName());
390 public void finishSection() throws ProducerConfigExc {
392 throw new ProducerConfigExc("No verbs defined");
395 throw new ProducerConfigExc("No body defined");
397 producerFactory = new ScriptedProducerFactory(factoryName, verbs, verbNodes, body, defaultVerb);
400 public ProducerFactory getProducerFactory() {
401 return producerFactory;
405 private final static String PRODUCER_VERB_NAME_ATTRIBUTE = "name";
406 private final static String PRODUCER_VERB_DESCRIPTION_ATTRIBUTE = "description";
407 private final static String PRODUCER_VERB_DEFAULT_ATTRIBUTE = "default";
408 private final static String[] PRODUCER_VERB_REQUIRED_ATTRIBUTES = { PRODUCER_VERB_NAME_ATTRIBUTE };
409 private final static String[] PRODUCER_VERB_OPTIONAL_ATTRIBUTES = { PRODUCER_VERB_DEFAULT_ATTRIBUTE, PRODUCER_VERB_DESCRIPTION_ATTRIBUTE };
411 public class ProducerVerbsSectionHandler extends SectionHandler {
412 private Map verbNodes;
414 private String defaultVerb;
415 private String currentVerb;
416 private String currentVerbDescription;
418 public ProducerVerbsSectionHandler() {
419 verbNodes = new HashMap();
420 verbs = new Vector();
424 public SectionHandler startElement(String aTag, Map anAttributes) throws ProducerConfigExc {
425 if (aTag.equals("verb")) {
426 ReaderTool.checkAttributes(anAttributes, PRODUCER_VERB_REQUIRED_ATTRIBUTES, PRODUCER_VERB_OPTIONAL_ATTRIBUTES);
427 currentVerb = (String) anAttributes.get( PRODUCER_VERB_NAME_ATTRIBUTE );
429 ReaderTool.checkValidIdentifier( currentVerb );
431 if (verbNodes.containsKey(currentVerb))
432 throw new ProducerConfigExc( "Duplicate definition of verb '" + currentVerb + "'" );
434 if (anAttributes.containsKey(PRODUCER_VERB_DEFAULT_ATTRIBUTE)) {
435 if (defaultVerb!=null)
436 throw new ProducerConfigExc( "Default verb already declared" );
438 defaultVerb = currentVerb;
441 if (anAttributes.containsKey( PRODUCER_VERB_DESCRIPTION_ATTRIBUTE ))
442 currentVerbDescription = (String) anAttributes.get( PRODUCER_VERB_DESCRIPTION_ATTRIBUTE );
444 currentVerbDescription = "";
446 return new ProducerNodeSectionHandler();
448 else throw new ProducerConfigExc("Only 'verb' tags allowed here, '" + aTag + "' encountered.");
451 public void endElement(SectionHandler aHandler) {
452 verbNodes.put(currentVerb, ((ProducerNodeSectionHandler) aHandler).getProducerNode());
453 verbs.add(new SimpleProducerVerb(currentVerb, currentVerbDescription));
456 public void finishSection() {
459 public String getDefaultVerb() {
463 public List getVerbs() {
467 public Map getVerbNodes() {
472 public class EmptySectionHandler extends SectionHandler {
473 public SectionHandler startElement(String aTag, Map anAttributes) throws ProducerConfigExc {
474 throw new ProducerConfigExc("No tags are allowed here");
477 public void endElement(SectionHandler aHandler) {
482 public class MultiProducerNodeSectionHandler extends SectionHandler {
483 private Map nodeParameters;
484 private Set validNodeParameters;
485 private String currentNodeParameter;
486 private String scriptedNodeName;
487 private Set allowedNodeParameterReferences;
489 public MultiProducerNodeSectionHandler(String aScriptedNodeName, Set anAllowedNodeParameterReferences, Set aValidNodeParameters) {
490 allowedNodeParameterReferences = anAllowedNodeParameterReferences;
491 scriptedNodeName = aScriptedNodeName;
492 validNodeParameters = aValidNodeParameters;
493 nodeParameters = new HashMap();
495 public MultiProducerNodeSectionHandler(Set aValidNodeParameters) {
496 this("", new HashSet(), aValidNodeParameters);
499 public SectionHandler startElement(String aTag, Map anAttributes) throws ProducerConfigExc {
500 if (!validNodeParameters.contains(aTag))
501 throw new ProducerConfigExc("Invalid node parameter: '" + aTag + "'");
502 else if (nodeParameters.containsKey(aTag))
503 throw new ProducerConfigExc("Node parameter: '" + aTag + "' already specified");
504 else if (anAttributes.size()>0)
505 throw new ProducerConfigExc("No parameters are allowed here");
507 currentNodeParameter = aTag;
509 return new ProducerNodeSectionHandler(scriptedNodeName, validNodeParameters);
512 public void endElement(SectionHandler aHandler) throws ProducerConfigExc {
513 if (aHandler instanceof ProducerNodeSectionHandler) {
514 nodeParameters.put(currentNodeParameter, ((ProducerNodeSectionHandler) aHandler).getProducerNode());
517 throw new ProducerConfigExc("Internal error: unknown section handler '" + aHandler.getClass().getName() + "'" );
521 public Map getNodeParameters() {
522 return nodeParameters;
526 public class ProducerNodeSectionHandler extends SectionHandler {
527 private CompositeProducerNode producerNode;
528 private ProducerNodeBuilder currentBuilder;
529 private String scriptedNodeName;
530 private Set allowedNodeParameterReferences;
532 public ProducerNodeSectionHandler(String aScriptedNodeName, Set anAllowedNodeParameterReferences) {
533 producerNode = new CompositeProducerNode();
534 scriptedNodeName = aScriptedNodeName;
535 allowedNodeParameterReferences = anAllowedNodeParameterReferences;
538 public ProducerNodeSectionHandler() {
539 this("", new HashSet());
542 public SectionHandler startElement(String aTag, Map anAttributes) throws ProducerConfigExc {
543 if (allowedNodeParameterReferences.contains((aTag))) {
544 if (!anAttributes.isEmpty()) {
545 throw new ProducerConfigExc( "No attributes allowed" );
548 currentBuilder = new DefaultProducerNodeBuilders.ScriptedProducerParameterNodeBuilder(scriptedNodeName, aTag);
549 // producerNode.addSubNode(
550 // new ScriptedProducerNodeDefinition.NodeParameterProducerNode(scriptedNodeName, aTag));
551 return new EmptySectionHandler();
553 else if (scriptedNodeBuilderLibrary.hasBuilderForName(aTag) || builderLibrary.hasBuilderForName((aTag))) {
555 if (scriptedNodeBuilderLibrary.hasBuilderForName(aTag))
556 currentBuilder = scriptedNodeBuilderLibrary.constructBuilder(aTag);
558 currentBuilder = builderLibrary.constructBuilder(aTag);
560 currentBuilder.setAttributes(anAttributes);
561 if (currentBuilder.getAvailableSubNodes().isEmpty()) {
562 return new EmptySectionHandler();
564 if (currentBuilder.getAvailableSubNodes().size()>1)
565 return new MultiProducerNodeSectionHandler(scriptedNodeName, allowedNodeParameterReferences, currentBuilder.getAvailableSubNodes());
566 else if (currentBuilder.getAvailableSubNodes().size()<1)
567 return new EmptySectionHandler();
569 return new ProducerNodeSectionHandler(scriptedNodeName, allowedNodeParameterReferences);
573 throw new ProducerConfigExc("Unknown producer node tag: '" + aTag + "'");
576 public void endElement(SectionHandler aHandler) throws ProducerConfigExc {
577 if (aHandler instanceof ProducerNodeSectionHandler) {
578 currentBuilder.setSubNode((String) (currentBuilder.getAvailableSubNodes().iterator().next()),
579 ((ProducerNodeSectionHandler) aHandler).getProducerNode());
581 else if (aHandler instanceof MultiProducerNodeSectionHandler) {
586 nodeParameters = ((MultiProducerNodeSectionHandler) aHandler).getNodeParameters();
587 i = nodeParameters.entrySet().iterator();
588 while (i.hasNext()) {
589 entry = (Map.Entry) i.next();
590 currentBuilder.setSubNode((String) entry.getKey(), (ProducerNode) entry.getValue());
593 else if (aHandler instanceof EmptySectionHandler) {
594 // deliberately empty: nothing expected, so nothing to process
597 throw new ProducerConfigExc("Internal error: unknown section handler '" + aHandler.getClass().getName() + "'" );
600 producerNode.addSubNode(currentBuilder.constructNode());
601 currentBuilder = null;
604 public ProducerNode getProducerNode() {
605 if (producerNode.getNrSubNodes()==1) {
606 return producerNode.getSubNode(0);
614 public class NodeDefinitionSectionHandler extends SectionHandler {
615 private ScriptedProducerNodeDefinition nodeDefinition;
616 private ProducerNode body;
617 private Map stringParameters;
618 private Map integerParameters;
619 private Map nodeParameters;
622 public NodeDefinitionSectionHandler(String aName) {
624 nodeParameters = null;
625 stringParameters = null;
626 integerParameters = null;
630 public SectionHandler startElement(String aTag, Map anAttributes) throws ProducerConfigExc {
631 if (aTag.equals("parameters")) {
632 if (!anAttributes.isEmpty()) {
633 throw new ProducerConfigExc( "No attributes allowed for tag 'parameters'" );
635 if (nodeParameters!=null) {
636 throw new ProducerConfigExc( "Parameters have already been declared" );
639 throw new ProducerConfigExc( "Parameters should come before definition" );
642 return new NodeDefinitionParametersSectionHandler();
644 else if (aTag.equals("definition")) {
645 return new ProducerNodeSectionHandler(name, nodeParameters.keySet());
647 else throw new ProducerConfigExc("Only 'definition' or 'parameters' tags allowed here, '" + aTag + "' encountered.");
650 public void endElement(SectionHandler aHandler) {
651 if (aHandler instanceof NodeDefinitionParametersSectionHandler) {
652 stringParameters = ((NodeDefinitionParametersSectionHandler) aHandler).getStringParameters();
653 integerParameters = ((NodeDefinitionParametersSectionHandler) aHandler).getIntegerParameters();
654 nodeParameters = ((NodeDefinitionParametersSectionHandler) aHandler).getNodeParameters();
656 else if (aHandler instanceof ProducerNodeSectionHandler) {
657 body = ((ProducerNodeSectionHandler) aHandler).getProducerNode();
661 public void finishSection() throws ProducerConfigExc {
664 throw new ProducerConfigExc( "Definition missing" );
666 nodeDefinition = new ScriptedProducerNodeDefinition(name);
668 nodeDefinition.setBody(body);
670 i = nodeParameters.keySet().iterator();
671 while (i.hasNext()) {
672 nodeDefinition.addNodeParameter((String) i.next());
675 i = stringParameters.entrySet().iterator();
676 while (i.hasNext()) {
677 Map.Entry entry = (Map.Entry) i.next();
678 nodeDefinition.addStringParameter((String) entry.getKey(), (String) entry.getValue());
681 i = integerParameters.entrySet().iterator();
682 while (i.hasNext()) {
683 Map.Entry entry = (Map.Entry) i.next();
684 nodeDefinition.addIntegerParameter((String) entry.getKey(), (String) entry.getValue());
688 public ScriptedProducerNodeDefinition getDefinition() {
689 return nodeDefinition;
693 private final static String NODE_DEFINITION_PARAMETER_NAME_ATTRIBUTE = "name";
694 private final static String NODE_DEFINITION_PARAMETER_DEFAULTVALUE_ATTRIBUTE = "defaultvalue";
695 private final static String[] NODE_DEFINITION_PARAMETER_REQUIRED_ATTRIBUTES = { NODE_DEFINITION_PARAMETER_NAME_ATTRIBUTE };
696 private final static String[] NODE_DEFINITION_PARAMETER_OPTIONAL_ATTRIBUTES = { NODE_DEFINITION_PARAMETER_DEFAULTVALUE_ATTRIBUTE };
697 private final static String[] NODE_DEFINITION_NODE_PARAMETER_OPTIONAL_ATTRIBUTES = { };
699 public class NodeDefinitionParametersSectionHandler extends SectionHandler {
700 private Map nodeParameters;
701 private Map stringParameters;
702 private Map integerParameters;
704 public NodeDefinitionParametersSectionHandler() {
705 nodeParameters = new HashMap();
706 stringParameters = new HashMap();
707 integerParameters = new HashMap();
710 public SectionHandler startElement(String aTag, Map anAttributes) throws ProducerConfigExc {
711 String parameterName;
714 if (aTag.equals("node")) {
715 ReaderTool.checkAttributes(anAttributes, NODE_DEFINITION_PARAMETER_REQUIRED_ATTRIBUTES, NODE_DEFINITION_NODE_PARAMETER_OPTIONAL_ATTRIBUTES);
716 parameterName = (String) anAttributes.get( NODE_DEFINITION_PARAMETER_NAME_ATTRIBUTE );
718 if (nodeParameters.containsKey(parameterName))
719 throw new ProducerConfigExc("Duplicate parameter name: '" + parameterName + "'");
721 ReaderTool.checkValidIdentifier( parameterName );
723 nodeParameters.put(parameterName, parameterName);
725 return new EmptySectionHandler();
727 else if (aTag.equals("string") || aTag.equals("integer")) {
728 ReaderTool.checkAttributes(anAttributes, NODE_DEFINITION_PARAMETER_REQUIRED_ATTRIBUTES, NODE_DEFINITION_PARAMETER_OPTIONAL_ATTRIBUTES);
729 parameterName = (String) anAttributes.get( NODE_DEFINITION_PARAMETER_NAME_ATTRIBUTE );
731 if (stringParameters.containsKey(parameterName) || integerParameters.containsKey(parameterName))
732 throw new ProducerConfigExc("Duplicate parameter name: '" + parameterName + "'");
734 ReaderTool.checkValidIdentifier( parameterName );
736 defaultValue = (String) anAttributes.get( NODE_DEFINITION_PARAMETER_DEFAULTVALUE_ATTRIBUTE );
738 if (aTag.equals("string"))
739 stringParameters.put(parameterName, defaultValue);
741 integerParameters.put(parameterName, defaultValue);
743 return new EmptySectionHandler();
745 else throw new ProducerConfigExc("Only 'string', 'integer' and 'node' tags allowed here, '" + aTag + "' encountered.");
749 public void endElement(SectionHandler aHandler) {
752 public void finishSection() {
755 public Map getNodeParameters() {
756 return nodeParameters;
759 public Map getStringParameters() {
760 return stringParameters;
763 public Map getIntegerParameters() {
764 return integerParameters;