01: /*
02: * $Id: EnvironmentEntryHandler.java 404 2005-01-28 17:06:24Z 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.EnvironmentEntry;
17: import org.xml.sax.Attributes;
18: import org.xml.sax.SAXException;
19:
20: public class EnvironmentEntryHandler extends ScopeHandler {
21: private EnvironmentEntry environmentEntry;
22: private TextHandler envEntryNameHandler = new TextHandler();
23: private TextHandler envEntryDescriptionHandler = new TextHandler();
24: private TextHandler envEntryTypeHandler = new TextHandler();
25: private TextHandler envEntryValueHandler = new TextHandler();
26:
27: public EnvironmentEntryHandler() {
28: }
29:
30: public EnvironmentEntry getEnvironmentEntry() {
31: return environmentEntry;
32: }
33:
34: public void startElement(String uri, String localName,
35: String qName, Attributes attributes) throws SAXException {
36: environmentEntry = new EnvironmentEntry();
37: }
38:
39: public void characters(char ch[], int start, int length)
40: throws SAXException {
41: }
42:
43: public void endElement(String uri, String localName, String qName)
44: throws SAXException {
45: }
46:
47: public ScopeHandler getHandler(String localName, String qName) {
48: if ("env-entry-name".equals(qName))
49: return envEntryNameHandler;
50: else if ("description".equals(qName))
51: return envEntryDescriptionHandler;
52: else if ("env-entry-type".equals(qName))
53: return envEntryTypeHandler;
54: else if ("env-entry-value".equals(qName))
55: return envEntryValueHandler;
56: else
57: throw new RuntimeException("unexpected tag " + localName
58: + " " + qName);
59: }
60:
61: public void fetchChild(ScopeHandler handler) {
62: if (handler == envEntryNameHandler)
63: environmentEntry.setName(envEntryNameHandler.getText());
64: else if (handler == envEntryDescriptionHandler)
65: environmentEntry.setDescription(envEntryDescriptionHandler
66: .getText());
67: else if (handler == envEntryTypeHandler)
68: environmentEntry.setType(envEntryTypeHandler.getText());
69: else if (handler == envEntryValueHandler)
70: environmentEntry.setValue(envEntryValueHandler.getText());
71: }
72: }
|