01: /*
02: * $Id: EventHandler.java 476 2005-07-11 17:25:19Z 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.Event;
17: import org.xml.sax.Attributes;
18: import org.xml.sax.SAXException;
19:
20: public class EventHandler extends ScopeHandler {
21: private Event event;
22: private TextHandler postconditionHandler = new TextHandler();
23: private TextHandler descriptionHandler = new TextHandler();
24: private InteractionHandler interactionHandler = new InteractionHandler();
25: private EnvironmentEntryHandler environmentEntryHandler = new EnvironmentEntryHandler();
26: private AttributeHandler attributeHandler = new AttributeHandler();
27:
28: public EventHandler() {
29: }
30:
31: public Event getEvent() {
32: return event;
33: }
34:
35: public void startElement(String uri, String localName,
36: String qName, Attributes attributes) throws SAXException {
37: event = new Event(attributes.getValue("name"));
38: event.setImplementation(attributes.getValue("class"));
39: event.setUser("true".equals(attributes.getValue("user")));
40: }
41:
42: public void characters(char ch[], int start, int length)
43: throws SAXException {
44: }
45:
46: public void endElement(String uri, String localName, String qName)
47: throws SAXException {
48: }
49:
50: public ScopeHandler getHandler(String localName, String qName) {
51: if ("postcondition".equals(qName))
52: return postconditionHandler;
53: else if ("description".equals(qName))
54: return descriptionHandler;
55: else if ("interaction".equals(qName))
56: return interactionHandler;
57: else if ("env-entry".equals(qName))
58: return environmentEntryHandler;
59: else if ("attribute".equals(qName))
60: return attributeHandler;
61: else
62: throw new RuntimeException("unexpected tag " + localName
63: + " " + qName);
64: }
65:
66: public void fetchChild(ScopeHandler handler) {
67: if (handler == postconditionHandler)
68: event.setPostcondition(postconditionHandler.getText());
69: else if (handler == descriptionHandler)
70: event.setDescription(descriptionHandler.getText());
71: else if (handler == interactionHandler)
72: event.setInteraction(interactionHandler.getInteraction());
73: else if (handler == environmentEntryHandler)
74: event.getEnvironment().add(
75: environmentEntryHandler.getEnvironmentEntry());
76: else if (handler == attributeHandler)
77: event.set(attributeHandler.getAttribute().getName(),
78: attributeHandler.getAttribute().getValue());
79: }
80: }
|