01: /*
02: * $Id: ConditionHandler.java 401 2005-01-07 13:20:01Z hengels $
03: * (c) Copyright 2004 con:cern development team.
04: *
05: * This file is part of con:cern (http://concern.sf.net).
06: *
07: * con:cern is free software; you can redistribute it and/or modify
08: * it under the terms of the GNU Lesser General Public License
09: * as published by the Free Software Foundation; either version 2.1
10: * of the License, or (at your option) any later version.
11: *
12: * Please see COPYING for the complete licence.
13: */
14: package org.concern.model.cpd;
15:
16: import org.concern.model.Condition;
17: import org.xml.sax.Attributes;
18: import org.xml.sax.SAXException;
19:
20: public class ConditionHandler extends ScopeHandler {
21: private Condition condition;
22: private TextHandler descriptionHandler = new TextHandler();
23: private EnvironmentEntryHandler environmentEntryHandler = new EnvironmentEntryHandler();
24:
25: public ConditionHandler() {
26: }
27:
28: public Condition getCondition() {
29: return condition;
30: }
31:
32: public void startElement(String uri, String localName,
33: String qName, Attributes attributes) throws SAXException {
34: condition = new Condition(attributes.getValue("name"));
35: condition.setImplementation(attributes.getValue("class"));
36: condition.setTemporal("true".equals(attributes
37: .getValue("temporal")));
38: }
39:
40: public void characters(char ch[], int start, int length)
41: throws SAXException {
42: }
43:
44: public void endElement(String uri, String localName, String qName)
45: throws SAXException {
46: }
47:
48: public ScopeHandler getHandler(String localName, String qName) {
49: if ("description".equals(qName))
50: return descriptionHandler;
51: else if ("env-entry".equals(qName))
52: return environmentEntryHandler;
53: else
54: throw new RuntimeException("unexpected tag " + localName
55: + " " + qName);
56: }
57:
58: public void fetchChild(ScopeHandler handler) {
59: if (handler == descriptionHandler)
60: condition.setDescription(descriptionHandler.getText());
61: else if (handler == environmentEntryHandler)
62: condition.getEnvironment().add(
63: environmentEntryHandler.getEnvironmentEntry());
64: }
65: }
|