01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: Xml2ElementModel.java 3634 2007-01-08 21:42:24Z gbevin $
07: */
08: package com.uwyn.rife.gui.model;
09:
10: import com.uwyn.rife.gui.model.exceptions.GuiModelException;
11: import com.uwyn.rife.xml.Xml2Data;
12: import org.xml.sax.Attributes;
13:
14: public class Xml2ElementModel extends Xml2Data {
15: private StringBuilder mCharacterData = null;
16: private ElementModel mCurrentElement = null;
17: private SubmissionModel mCurrentSubmission = null;
18: private ParticlePropertyModel mCurrentParticleProperty = null;
19:
20: public ElementModel getElementModel() {
21: return mCurrentElement;
22: }
23:
24: public void startDocument() {
25: mCharacterData = new StringBuilder();
26: mCurrentElement = null;
27: mCurrentSubmission = null;
28: mCurrentParticleProperty = null;
29: }
30:
31: public void endDocument() {
32: mCharacterData = null;
33: mCurrentSubmission = null;
34: mCurrentParticleProperty = null;
35: }
36:
37: public void startElement(String namespaceURI, String localName,
38: String qName, Attributes atts) {
39: try {
40: if (qName.equals("element")) {
41: mCurrentElement = new ElementModel(atts.getValue("id"));
42: String implementation = atts.getValue("implementation");
43: if (implementation != null) {
44: mCurrentElement.setImplementation(implementation);
45: }
46: } else if (qName.equals("exit")) {
47: mCurrentParticleProperty = mCurrentElement.addExit(atts
48: .getValue("name"));
49: } else if (qName.equals("input")) {
50: mCurrentParticleProperty = mCurrentElement
51: .addInput(atts.getValue("name"));
52: } else if (qName.equals("output")) {
53: mCurrentParticleProperty = mCurrentElement
54: .addOutput(atts.getValue("name"));
55: } else if (qName.equals("param")) {
56: mCurrentParticleProperty = mCurrentSubmission
57: .addParameter(atts.getValue("name"));
58: } else if (qName.equals("submission")) {
59: mCurrentSubmission = mCurrentElement.addSubmission(atts
60: .getValue("name"));
61: } else if (qName.equals("description")) {
62: mCharacterData = new StringBuilder();
63: }
64: } catch (GuiModelException e) {
65: mCurrentElement = null;
66: }
67: }
68:
69: public void endElement(String namespaceURI, String localName,
70: String qName) {
71: if (qName.equals("description")) {
72: if (mCurrentParticleProperty != null) {
73: mCurrentParticleProperty.setDescription(mCharacterData
74: .toString());
75: } else if (mCurrentSubmission != null) {
76: mCurrentSubmission.setDescription(mCharacterData
77: .toString());
78: } else if (mCurrentElement != null) {
79: mCurrentElement.setDescription(mCharacterData
80: .toString());
81: }
82: mCharacterData = new StringBuilder();
83: } else if (qName.equals("exit") || qName.equals("input")
84: || qName.equals("output") || qName.equals("param")) {
85: mCurrentParticleProperty = null;
86: } else if (qName.equals("submission")) {
87: mCurrentSubmission = null;
88: }
89: }
90:
91: public void characters(char[] ch, int start, int length) {
92: if (length > 0) {
93: mCharacterData
94: .append(String.copyValueOf(ch, start, length));
95: }
96: }
97: }
|