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;
35 import java.io.FileInputStream;
36 import java.io.FileNotFoundException;
37 import java.io.IOException;
38 import java.util.HashMap;
39 import java.util.HashSet;
40 import java.util.Iterator;
41 import java.util.List;
44 import java.util.Stack;
45 import java.util.Vector;
47 import javax.xml.parsers.ParserConfigurationException;
48 import javax.xml.parsers.SAXParser;
49 import javax.xml.parsers.SAXParserFactory;
51 import mir.producer.CompositeProducerNode;
52 import mir.producer.ProducerFactory;
53 import mir.producer.ProducerNode;
54 import mir.producer.SimpleProducerVerb;
56 import org.xml.sax.Attributes;
57 import org.xml.sax.InputSource;
58 import org.xml.sax.Locator;
59 import org.xml.sax.SAXException;
60 import org.xml.sax.SAXParseException;
61 import org.xml.sax.helpers.DefaultHandler;
63 public class ProducerConfigReader {
64 private ProducerNodeBuilderLibrary builderLibrary;
65 private ProducerNodeBuilderLibrary scriptedNodeBuilderLibrary;
67 public ProducerConfigReader() {
71 public void parseFile(String aFileName, ProducerNodeBuilderLibrary aBuilderLibrary, List aProducerFactories) throws ProducerConfigFailure {
72 parseFile(aFileName, aBuilderLibrary, aProducerFactories, new Vector());
75 public void parseFile(String aFileName, ProducerNodeBuilderLibrary aBuilderLibrary, List aProducerFactories, List aUsedFiles) throws ProducerConfigFailure {
77 builderLibrary = aBuilderLibrary;
78 scriptedNodeBuilderLibrary = new ProducerNodeBuilderLibrary();
80 SAXParserFactory parserFactory = SAXParserFactory.newInstance();
82 parserFactory.setNamespaceAware(false);
83 parserFactory.setValidating(true);
85 ProducerConfigHandler handler = new ProducerConfigHandler(parserFactory, aProducerFactories, aUsedFiles);
87 handler.includeFile(aFileName);
90 if (e instanceof SAXParseException && ((SAXParseException) e).getException() instanceof ProducerConfigFailure) {
91 throw (ProducerConfigFailure) ((SAXParseException) e).getException();
94 throw new ProducerConfigFailure( e );
99 private class ProducerConfigHandler extends DefaultHandler {
100 private Locator locator;
101 private Stack includeFileStack;
102 private SAXParserFactory parserFactory;
103 private SectionsManager manager;
104 private List usedFiles;
105 private InputSource inputSource;
107 public ProducerConfigHandler(SAXParserFactory aParserFactory, List aProducers, List aUsedFiles) {
110 includeFileStack=new Stack();
111 parserFactory=aParserFactory;
112 includeFileStack = new Stack();
113 manager = new SectionsManager();
114 usedFiles = aUsedFiles;
116 manager.pushHandler(new RootSectionHandler(aProducers));
119 public String getLocatorDescription(Locator aLocator) {
120 return aLocator.getPublicId()+" ("+aLocator.getLineNumber()+")";
123 public void setDocumentLocator(Locator aLocator) {
127 private void includeFile(String aFileName) throws ProducerConfigExc, ProducerConfigFailure, SAXParseException, SAXException {
132 if (!includeFileStack.empty())
133 file = new File(new File((String) includeFileStack.peek()).getParent(), aFileName);
135 file = new File(aFileName);
137 System.err.println("about to include "+file.getCanonicalPath());
139 if (includeFileStack.contains(file.getCanonicalPath())) {
140 throw new ProducerConfigExc("recursive inclusion of file "+file.getCanonicalPath());
145 parser=parserFactory.newSAXParser();
147 inputSource = new InputSource(new FileInputStream(file));
148 inputSource.setPublicId(file.getCanonicalPath());
150 includeFileStack.push(file.getCanonicalPath());
152 parser.parse(inputSource, this);
155 includeFileStack.pop();
158 catch (ParserConfigurationException e) {
159 throw new ProducerConfigExc("Internal exception while including \""+aFileName+"\": "+e.getMessage());
161 catch (SAXParseException e) {
164 catch (ProducerConfigFailure e) {
167 catch (FileNotFoundException e) {
168 throw new ProducerConfigExc("Include file \""+aFileName+"\" not found: "+e.getMessage());
170 catch (IOException e) {
171 throw new ProducerConfigExc("unable to open include file \""+aFileName+"\": "+e.getMessage());
175 public void startElement(String aUri, String aTag, String aQualifiedName, Attributes anAttributes) throws SAXException {
180 if (aQualifiedName.equals("include")) {
181 String fileName=anAttributes.getValue("file");
183 if (fileName==null) {
184 throw new ProducerConfigExc("include has no file attribute");
187 includeFile(fileName);
190 attributesMap = new HashMap();
191 for (i=0; i<anAttributes.getLength(); i++)
192 attributesMap.put(anAttributes.getQName(i), anAttributes.getValue(i));
194 manager.pushHandler( manager.currentHandler().startElement(aQualifiedName, attributesMap) );
197 catch (ProducerConfigExc e) {
198 throw new SAXParseException(e.getMessage(), locator, new ProducerConfigExc("Config error at ["+getLocatorDescription(locator)+"]: "+e.getMessage()));
200 catch (Exception e) {
201 throw new SAXException(e);
205 public void endElement(String aUri, String aTag, String aQualifiedName) throws SAXException {
208 if (!aQualifiedName.equals("include")) {
209 SectionHandler handler = manager.popHandler();
211 handler.finishSection();
213 if (!manager.isEmpty()) {
214 manager.currentHandler().endElement(handler);
218 catch (ProducerConfigExc e) {
219 throw new SAXParseException(e.getMessage(), locator, new ProducerConfigExc("Config error at ["+getLocatorDescription(locator)+"]: "+e.getMessage()));
221 catch (Exception e) {
222 throw new SAXException(e);
226 public void characters(char[] aBuffer, int aStart, int anEnd) throws SAXParseException {
227 String text = new String(aBuffer, aStart, anEnd).trim();
228 if ( text.length() > 0) {
229 throw new SAXParseException("Text not allowed", locator, new ProducerConfigExc("Config error at ["+getLocatorDescription(locator)+"]: Text not allowed"));
234 public class SectionsManager {
237 public SectionsManager() {
238 handlerStack = new Stack();
241 public void pushHandler(SectionHandler aSectionHandler) {
242 handlerStack.push(aSectionHandler);
245 public SectionHandler popHandler() {
246 return (SectionHandler) handlerStack.pop();
249 public SectionHandler currentHandler() {
250 return (SectionHandler) handlerStack.peek();
253 public boolean isEmpty() {
254 return handlerStack.isEmpty();
258 public abstract class SectionHandler {
259 public abstract SectionHandler startElement(String aTag, Map anAttributes) throws ProducerConfigExc;
261 public abstract void endElement(SectionHandler aHandler) throws ProducerConfigExc;
265 public void finishSection() throws ProducerConfigExc {
269 public class RootSectionHandler extends SectionHandler {
270 private List producers;
272 public RootSectionHandler(List aProducers) {
273 producers = aProducers;
276 public SectionHandler startElement(String aTag, Map anAttributes) throws ProducerConfigExc {
277 if (aTag.equals("producers")) {
278 return new ProducersSectionHandler(producers);
281 throw new ProducerConfigExc ("Tag 'producers' expected, tag '"+aTag+"' found");
284 public void endElement(SectionHandler aHandler) {
287 public void finishSection() throws ProducerConfigExc {
292 private final static String PRODUCER_NAME_ATTRIBUTE = "name";
293 private final static String[] PRODUCER_REQUIRED_ATTRIBUTES = { PRODUCER_NAME_ATTRIBUTE };
294 private final static String[] PRODUCER_OPTIONAL_ATTRIBUTES = { };
296 private final static String NODE_DEFINITION_NAME_ATTRIBUTE = "name";
297 private final static String[] NODE_DEFINITION_REQUIRED_ATTRIBUTES = { NODE_DEFINITION_NAME_ATTRIBUTE };
298 private final static String[] NODE_DEFINITION_OPTIONAL_ATTRIBUTES = { };
300 public class ProducersSectionHandler extends SectionHandler {
301 private List producers;
302 private Set producerNames;
305 public ProducersSectionHandler(List aProducers) {
306 producers = aProducers;
307 producerNames = new HashSet();
310 public SectionHandler startElement(String aTag, Map anAttributes) throws ProducerConfigExc {
312 if (aTag.equals("producer")) {
313 ReaderTool.checkAttributes(anAttributes, PRODUCER_REQUIRED_ATTRIBUTES, PRODUCER_OPTIONAL_ATTRIBUTES);
315 name = (String) anAttributes.get(PRODUCER_NAME_ATTRIBUTE);
316 ReaderTool.checkValidIdentifier( name );
318 if (producerNames.contains(name))
319 throw new ProducerConfigExc("Duplicate producer name: '" + name + "'");
321 name = (String) anAttributes.get(PRODUCER_NAME_ATTRIBUTE);
323 return new ProducerSectionHandler(name);
325 else if (aTag.equals("nodedefinition")) {
326 ReaderTool.checkAttributes(anAttributes, NODE_DEFINITION_REQUIRED_ATTRIBUTES, NODE_DEFINITION_OPTIONAL_ATTRIBUTES);
328 name = (String) anAttributes.get(NODE_DEFINITION_NAME_ATTRIBUTE);
329 ReaderTool.checkValidIdentifier( name );
331 // if (producers.containsKey(name))
332 // throw new ProducerConfigExc("Duplicate producer name: '" + name + "'");
334 name = (String) anAttributes.get(NODE_DEFINITION_NAME_ATTRIBUTE);
336 return new NodeDefinitionSectionHandler(name);
339 throw new ProducerConfigExc("Unexpected tag: "+aTag );
342 public void endElement(SectionHandler aHandler) throws ProducerConfigExc {
343 if (aHandler instanceof ProducerSectionHandler) {
344 producers.add(((ProducerSectionHandler) aHandler).getProducerFactory());
345 producerNames.add(((ProducerSectionHandler) aHandler).getProducerFactory().getName());
347 else if (aHandler instanceof NodeDefinitionSectionHandler) {
348 scriptedNodeBuilderLibrary.registerFactory(name,
349 new DefaultProducerNodeBuilders.ScriptedProducerNodeBuilder.factory(
350 ((NodeDefinitionSectionHandler) aHandler).getDefinition()));
352 else throw new ProducerConfigExc("ProducersSectionHandler.endElement Internal error: Unexpected handler: " + aHandler.getClass().getName());
355 public void finishSection() throws ProducerConfigExc {
359 public class ProducerSectionHandler extends SectionHandler {
360 private ProducerFactory producerFactory;
361 private String factoryName;
363 private ProducerNode body;
364 private Map verbNodes;
366 private String defaultVerb;
368 public ProducerSectionHandler(String aName) {
372 public SectionHandler startElement(String aTag, Map anAttributes) throws ProducerConfigExc {
373 if (aTag.equals("verbs")) {
375 throw new ProducerConfigExc("Verbs already processed");
377 throw new ProducerConfigExc("Verbs should come before body");
379 return new ProducerVerbsSectionHandler();
381 else if (aTag.equals("body")) {
383 return new ProducerNodeSectionHandler();
385 throw new ProducerConfigExc("Body already processed");
387 throw new ProducerConfigExc("Unexpected tag: '"+aTag+"'");
390 public void endElement(SectionHandler aHandler) throws ProducerConfigExc {
391 if (aHandler instanceof ProducerNodeSectionHandler) {
392 body = ((ProducerNodeSectionHandler) aHandler).getProducerNode();
394 else if (aHandler instanceof ProducerVerbsSectionHandler)
396 verbs = ((ProducerVerbsSectionHandler) aHandler).getVerbs();
397 verbNodes = ((ProducerVerbsSectionHandler) aHandler).getVerbNodes();
398 defaultVerb = ((ProducerVerbsSectionHandler) aHandler).getDefaultVerb();
400 else throw new ProducerConfigExc("ProducerSectionHandler.endElement Internal error: Unexpected handler: " + aHandler.getClass().getName());
403 public void finishSection() throws ProducerConfigExc {
405 throw new ProducerConfigExc("No verbs defined");
408 throw new ProducerConfigExc("No body defined");
410 producerFactory = new ScriptedProducerFactory(factoryName, verbs, verbNodes, body, defaultVerb);
413 public ProducerFactory getProducerFactory() {
414 return producerFactory;
418 private final static String PRODUCER_VERB_NAME_ATTRIBUTE = "name";
419 private final static String PRODUCER_VERB_DESCRIPTION_ATTRIBUTE = "description";
420 private final static String PRODUCER_VERB_DEFAULT_ATTRIBUTE = "default";
421 private final static String[] PRODUCER_VERB_REQUIRED_ATTRIBUTES = { PRODUCER_VERB_NAME_ATTRIBUTE };
422 private final static String[] PRODUCER_VERB_OPTIONAL_ATTRIBUTES = { PRODUCER_VERB_DEFAULT_ATTRIBUTE, PRODUCER_VERB_DESCRIPTION_ATTRIBUTE };
424 public class ProducerVerbsSectionHandler extends SectionHandler {
425 private Map verbNodes;
427 private String defaultVerb;
428 private String currentVerb;
429 private String currentVerbDescription;
431 public ProducerVerbsSectionHandler() {
432 verbNodes = new HashMap();
433 verbs = new Vector();
437 public SectionHandler startElement(String aTag, Map anAttributes) throws ProducerConfigExc {
438 if (aTag.equals("verb")) {
439 ReaderTool.checkAttributes(anAttributes, PRODUCER_VERB_REQUIRED_ATTRIBUTES, PRODUCER_VERB_OPTIONAL_ATTRIBUTES);
440 currentVerb = (String) anAttributes.get( PRODUCER_VERB_NAME_ATTRIBUTE );
442 ReaderTool.checkValidIdentifier( currentVerb );
444 if (verbNodes.containsKey(currentVerb))
445 throw new ProducerConfigExc( "Duplicate definition of verb '" + currentVerb + "'" );
447 if (anAttributes.containsKey(PRODUCER_VERB_DEFAULT_ATTRIBUTE)) {
448 if (defaultVerb!=null)
449 throw new ProducerConfigExc( "Default verb already declared" );
451 defaultVerb = currentVerb;
454 if (anAttributes.containsKey( PRODUCER_VERB_DESCRIPTION_ATTRIBUTE ))
455 currentVerbDescription = (String) anAttributes.get( PRODUCER_VERB_DESCRIPTION_ATTRIBUTE );
457 currentVerbDescription = "";
459 return new ProducerNodeSectionHandler();
461 else throw new ProducerConfigExc("Only 'verb' tags allowed here, '" + aTag + "' encountered.");
464 public void endElement(SectionHandler aHandler) {
465 verbNodes.put(currentVerb, ((ProducerNodeSectionHandler) aHandler).getProducerNode());
466 verbs.add(new SimpleProducerVerb(currentVerb, currentVerbDescription));
469 public void finishSection() {
472 public String getDefaultVerb() {
476 public List getVerbs() {
480 public Map getVerbNodes() {
485 public class EmptySectionHandler extends SectionHandler {
486 public SectionHandler startElement(String aTag, Map anAttributes) throws ProducerConfigExc {
487 throw new ProducerConfigExc("No tags are allowed here");
490 public void endElement(SectionHandler aHandler) {
495 public class MultiProducerNodeSectionHandler extends SectionHandler {
496 private Map nodeParameters;
497 private Set validNodeParameters;
498 private String currentNodeParameter;
499 private String scriptedNodeName;
500 private Set allowedNodeParameterReferences;
502 public MultiProducerNodeSectionHandler(String aScriptedNodeName, Set anAllowedNodeParameterReferences, Set aValidNodeParameters) {
503 allowedNodeParameterReferences = anAllowedNodeParameterReferences;
504 scriptedNodeName = aScriptedNodeName;
505 validNodeParameters = aValidNodeParameters;
506 nodeParameters = new HashMap();
508 public MultiProducerNodeSectionHandler(Set aValidNodeParameters) {
509 this("", new HashSet(), aValidNodeParameters);
512 public SectionHandler startElement(String aTag, Map anAttributes) throws ProducerConfigExc {
513 if (!validNodeParameters.contains(aTag))
514 throw new ProducerConfigExc("Invalid node parameter: '" + aTag + "'");
515 else if (nodeParameters.containsKey(aTag))
516 throw new ProducerConfigExc("Node parameter: '" + aTag + "' already specified");
517 else if (anAttributes.size()>0)
518 throw new ProducerConfigExc("No parameters are allowed here");
520 currentNodeParameter = aTag;
522 return new ProducerNodeSectionHandler(scriptedNodeName, validNodeParameters);
525 public void endElement(SectionHandler aHandler) throws ProducerConfigExc {
526 if (aHandler instanceof ProducerNodeSectionHandler) {
527 nodeParameters.put(currentNodeParameter, ((ProducerNodeSectionHandler) aHandler).getProducerNode());
530 throw new ProducerConfigExc("Internal error: unknown section handler '" + aHandler.getClass().getName() + "'" );
534 public Map getNodeParameters() {
535 return nodeParameters;
539 public class ProducerNodeSectionHandler extends SectionHandler {
540 private CompositeProducerNode producerNode;
541 private ProducerNodeBuilder currentBuilder;
542 private String scriptedNodeName;
543 private Set allowedNodeParameterReferences;
545 public ProducerNodeSectionHandler(String aScriptedNodeName, Set anAllowedNodeParameterReferences) {
546 producerNode = new CompositeProducerNode();
547 scriptedNodeName = aScriptedNodeName;
548 allowedNodeParameterReferences = anAllowedNodeParameterReferences;
551 public ProducerNodeSectionHandler() {
552 this("", new HashSet());
555 public SectionHandler startElement(String aTag, Map anAttributes) throws ProducerConfigExc {
556 if (allowedNodeParameterReferences.contains((aTag))) {
557 if (!anAttributes.isEmpty()) {
558 throw new ProducerConfigExc( "No attributes allowed" );
561 currentBuilder = new DefaultProducerNodeBuilders.ScriptedProducerParameterNodeBuilder(scriptedNodeName, aTag);
562 // producerNode.addSubNode(
563 // new ScriptedProducerNodeDefinition.NodeParameterProducerNode(scriptedNodeName, aTag));
564 return new EmptySectionHandler();
566 else if (scriptedNodeBuilderLibrary.hasBuilderForName(aTag) || builderLibrary.hasBuilderForName((aTag))) {
568 if (scriptedNodeBuilderLibrary.hasBuilderForName(aTag))
569 currentBuilder = scriptedNodeBuilderLibrary.constructBuilder(aTag);
571 currentBuilder = builderLibrary.constructBuilder(aTag);
573 currentBuilder.setAttributes(anAttributes);
574 if (currentBuilder.getAvailableSubNodes().isEmpty()) {
575 return new EmptySectionHandler();
577 if (currentBuilder.getAvailableSubNodes().size()>1)
578 return new MultiProducerNodeSectionHandler(scriptedNodeName, allowedNodeParameterReferences, currentBuilder.getAvailableSubNodes());
579 else if (currentBuilder.getAvailableSubNodes().size()<1)
580 return new EmptySectionHandler();
582 return new ProducerNodeSectionHandler(scriptedNodeName, allowedNodeParameterReferences);
586 throw new ProducerConfigExc("Unknown producer node tag: '" + aTag + "'");
589 public void endElement(SectionHandler aHandler) throws ProducerConfigExc {
590 if (aHandler instanceof ProducerNodeSectionHandler) {
591 currentBuilder.setSubNode((String) (currentBuilder.getAvailableSubNodes().iterator().next()),
592 ((ProducerNodeSectionHandler) aHandler).getProducerNode());
594 else if (aHandler instanceof MultiProducerNodeSectionHandler) {
599 nodeParameters = ((MultiProducerNodeSectionHandler) aHandler).getNodeParameters();
600 i = nodeParameters.entrySet().iterator();
601 while (i.hasNext()) {
602 entry = (Map.Entry) i.next();
603 currentBuilder.setSubNode((String) entry.getKey(), (ProducerNode) entry.getValue());
606 else if (aHandler instanceof EmptySectionHandler) {
607 // deliberately empty: nothing expected, so nothing to process
610 throw new ProducerConfigExc("Internal error: unknown section handler '" + aHandler.getClass().getName() + "'" );
613 producerNode.addSubNode(currentBuilder.constructNode());
614 currentBuilder = null;
617 public ProducerNode getProducerNode() {
618 if (producerNode.getNrSubNodes()==1) {
619 return producerNode.getSubNode(0);
627 public class NodeDefinitionSectionHandler extends SectionHandler {
628 private ScriptedProducerNodeDefinition nodeDefinition;
629 private ProducerNode body;
630 private Map stringParameters;
631 private Map integerParameters;
632 private Map nodeParameters;
635 public NodeDefinitionSectionHandler(String aName) {
637 nodeParameters = null;
638 stringParameters = null;
639 integerParameters = null;
643 public SectionHandler startElement(String aTag, Map anAttributes) throws ProducerConfigExc {
644 if (aTag.equals("parameters")) {
645 if (!anAttributes.isEmpty()) {
646 throw new ProducerConfigExc( "No attributes allowed for tag 'parameters'" );
648 if (nodeParameters!=null) {
649 throw new ProducerConfigExc( "Parameters have already been declared" );
652 throw new ProducerConfigExc( "Parameters should come before definition" );
655 return new NodeDefinitionParametersSectionHandler();
657 else if (aTag.equals("definition")) {
658 return new ProducerNodeSectionHandler(name, nodeParameters.keySet());
660 else throw new ProducerConfigExc("Only 'definition' or 'parameters' tags allowed here, '" + aTag + "' encountered.");
663 public void endElement(SectionHandler aHandler) {
664 if (aHandler instanceof NodeDefinitionParametersSectionHandler) {
665 stringParameters = ((NodeDefinitionParametersSectionHandler) aHandler).getStringParameters();
666 integerParameters = ((NodeDefinitionParametersSectionHandler) aHandler).getIntegerParameters();
667 nodeParameters = ((NodeDefinitionParametersSectionHandler) aHandler).getNodeParameters();
669 else if (aHandler instanceof ProducerNodeSectionHandler) {
670 body = ((ProducerNodeSectionHandler) aHandler).getProducerNode();
674 public void finishSection() throws ProducerConfigExc {
677 throw new ProducerConfigExc( "Definition missing" );
679 nodeDefinition = new ScriptedProducerNodeDefinition(name);
681 nodeDefinition.setBody(body);
683 i = nodeParameters.keySet().iterator();
684 while (i.hasNext()) {
685 nodeDefinition.addNodeParameter((String) i.next());
688 i = stringParameters.entrySet().iterator();
689 while (i.hasNext()) {
690 Map.Entry entry = (Map.Entry) i.next();
691 nodeDefinition.addStringParameter((String) entry.getKey(), (String) entry.getValue());
694 i = integerParameters.entrySet().iterator();
695 while (i.hasNext()) {
696 Map.Entry entry = (Map.Entry) i.next();
697 nodeDefinition.addIntegerParameter((String) entry.getKey(), (String) entry.getValue());
701 public ScriptedProducerNodeDefinition getDefinition() {
702 return nodeDefinition;
706 private final static String NODE_DEFINITION_PARAMETER_NAME_ATTRIBUTE = "name";
707 private final static String NODE_DEFINITION_PARAMETER_DEFAULTVALUE_ATTRIBUTE = "defaultvalue";
708 private final static String[] NODE_DEFINITION_PARAMETER_REQUIRED_ATTRIBUTES = { NODE_DEFINITION_PARAMETER_NAME_ATTRIBUTE };
709 private final static String[] NODE_DEFINITION_PARAMETER_OPTIONAL_ATTRIBUTES = { NODE_DEFINITION_PARAMETER_DEFAULTVALUE_ATTRIBUTE };
710 private final static String[] NODE_DEFINITION_NODE_PARAMETER_OPTIONAL_ATTRIBUTES = { };
712 public class NodeDefinitionParametersSectionHandler extends SectionHandler {
713 private Map nodeParameters;
714 private Map stringParameters;
715 private Map integerParameters;
717 public NodeDefinitionParametersSectionHandler() {
718 nodeParameters = new HashMap();
719 stringParameters = new HashMap();
720 integerParameters = new HashMap();
723 public SectionHandler startElement(String aTag, Map anAttributes) throws ProducerConfigExc {
724 String parameterName;
727 if (aTag.equals("node")) {
728 ReaderTool.checkAttributes(anAttributes, NODE_DEFINITION_PARAMETER_REQUIRED_ATTRIBUTES, NODE_DEFINITION_NODE_PARAMETER_OPTIONAL_ATTRIBUTES);
729 parameterName = (String) anAttributes.get( NODE_DEFINITION_PARAMETER_NAME_ATTRIBUTE );
731 if (nodeParameters.containsKey(parameterName))
732 throw new ProducerConfigExc("Duplicate parameter name: '" + parameterName + "'");
734 ReaderTool.checkValidIdentifier( parameterName );
736 nodeParameters.put(parameterName, parameterName);
738 return new EmptySectionHandler();
740 else if (aTag.equals("string") || aTag.equals("integer")) {
741 ReaderTool.checkAttributes(anAttributes, NODE_DEFINITION_PARAMETER_REQUIRED_ATTRIBUTES, NODE_DEFINITION_PARAMETER_OPTIONAL_ATTRIBUTES);
742 parameterName = (String) anAttributes.get( NODE_DEFINITION_PARAMETER_NAME_ATTRIBUTE );
744 if (stringParameters.containsKey(parameterName) || integerParameters.containsKey(parameterName))
745 throw new ProducerConfigExc("Duplicate parameter name: '" + parameterName + "'");
747 ReaderTool.checkValidIdentifier( parameterName );
749 defaultValue = (String) anAttributes.get( NODE_DEFINITION_PARAMETER_DEFAULTVALUE_ATTRIBUTE );
751 if (aTag.equals("string"))
752 stringParameters.put(parameterName, defaultValue);
754 integerParameters.put(parameterName, defaultValue);
756 return new EmptySectionHandler();
758 else throw new ProducerConfigExc("Only 'string', 'integer' and 'node' tags allowed here, '" + aTag + "' encountered.");
762 public void endElement(SectionHandler aHandler) {
765 public void finishSection() {
768 public Map getNodeParameters() {
769 return nodeParameters;
772 public Map getStringParameters() {
773 return stringParameters;
776 public Map getIntegerParameters() {
777 return integerParameters;