01: /*
02: * $Id: ActorHandler.java 543 2005-10-06 09:09:08Z nebulosu $
03: * (c) Copyright 2004 con:cern development team.
04: *
05: * This file is part of con:cern (http://concern.org).
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.xml.sax.Attributes;
17: import org.xml.sax.SAXException;
18: import org.concern.model.Actor;
19:
20: public class ActorHandler extends ScopeHandler {
21: private Actor actor;
22: private TextHandler descriptionHandler = new TextHandler();
23: private EnvironmentEntryHandler environmentEntryHandler = new EnvironmentEntryHandler();
24:
25: public ActorHandler() {
26: }
27:
28: public Actor getActor() {
29: return actor;
30: }
31:
32: public void startElement(String uri, String localName,
33: String qName, Attributes attributes) throws SAXException {
34: actor = new Actor(attributes.getValue("name"));
35: actor.setImplementation(attributes.getValue("class"));
36: }
37:
38: public void characters(char ch[], int start, int length)
39: throws SAXException {
40: }
41:
42: public void endElement(String uri, String localName, String qName)
43: throws SAXException {
44: }
45:
46: public ScopeHandler getHandler(String localName, String qName) {
47: if ("description".equals(qName))
48: return descriptionHandler;
49: else if ("env-entry".equals(qName))
50: return environmentEntryHandler;
51: else
52: throw new RuntimeException("unexpected tag " + localName
53: + " " + qName);
54: }
55:
56: public void fetchChild(ScopeHandler handler) {
57: if (handler == descriptionHandler)
58: actor.setDescription(descriptionHandler.getText());
59: else if (handler == environmentEntryHandler)
60: actor.getEnvironment().add(
61: environmentEntryHandler.getEnvironmentEntry());
62: }
63: }
|