001: /*
002: * $Id: ProcessHandler.java 569 2005-10-28 07:29:49Z hengels $
003: * (c) Copyright 2004 con:cern development team.
004: *
005: * This file is part of con:cern (http://concern.sf.net).
006: *
007: * con:cern is free software; you can redistribute it and/or modify
008: * it under the terms of the GNU Lesser General Public License
009: * as published by the Free Software Foundation; either version 2.1
010: * of the License, or (at your option) any later version.
011: *
012: * Please see COPYING for the complete licence.
013: */
014: package org.concern.model.cpd;
015:
016: import org.concern.model.Process;
017: import org.xml.sax.Attributes;
018: import org.xml.sax.SAXException;
019:
020: public class ProcessHandler extends ScopeHandler {
021: private Process process;
022: private TextHandler descriptionHandler = new TextHandler();
023: private LoaderHandler loaderHandler = new LoaderHandler();
024: private CollaborationHandler collaborationHandler = new CollaborationHandler();
025: private ActorHandler actorHandler = new ActorHandler();
026: private ConditionHandler conditionHandler = new ConditionHandler();
027: private ActivityHandler activityHandler = new ActivityHandler();
028: private EventHandler eventHandler = new EventHandler();
029: private ListenerHandler listenerHandler = new ListenerHandler();
030: private EnvironmentEntryHandler environmentEntryHandler = new EnvironmentEntryHandler();
031: private AttributeHandler attributeHandler = new AttributeHandler();
032:
033: public ProcessHandler() {
034: }
035:
036: public Process getProcess() {
037: return process;
038: }
039:
040: public void startElement(String uri, String localName,
041: String qName, Attributes attributes) throws SAXException {
042: process = new Process(attributes.getValue("name"));
043: process.setSubject(attributes.getValue("subject"));
044: }
045:
046: public void characters(char ch[], int start, int length)
047: throws SAXException {
048: }
049:
050: public void endElement(String uri, String localName, String qName)
051: throws SAXException {
052: }
053:
054: public ScopeHandler getHandler(String localName, String qName) {
055: if ("condition".equals(qName))
056: return conditionHandler;
057: else if ("activity".equals(qName))
058: return activityHandler;
059: else if ("synchronous-activity".equals(qName))
060: return activityHandler;
061: else if ("asynchronous-activity".equals(qName))
062: return activityHandler;
063: else if ("event".equals(qName))
064: return eventHandler;
065: else if ("listener".equals(qName))
066: return listenerHandler;
067: else if ("loader".equals(qName))
068: return loaderHandler;
069: else if ("actor".equals(qName))
070: return actorHandler;
071: else if ("collaboration".equals(qName))
072: return collaborationHandler;
073: else if ("description".equals(qName))
074: return descriptionHandler;
075: else if ("env-entry".equals(qName))
076: return environmentEntryHandler;
077: else if ("attribute".equals(qName))
078: return attributeHandler;
079: else
080: throw new RuntimeException("unexpected tag " + localName
081: + " " + qName);
082: }
083:
084: public void fetchChild(ScopeHandler handler) {
085: if (handler == conditionHandler)
086: process.addCondition(conditionHandler.getCondition());
087: if (handler == activityHandler)
088: process.addActivity(activityHandler.getActivity());
089: else if (handler == listenerHandler)
090: process.addListener(listenerHandler.getListener());
091: else if (handler == eventHandler)
092: process.addEvent(eventHandler.getEvent());
093: else if (handler == actorHandler)
094: process.addActor(actorHandler.getActor());
095: else if (handler == collaborationHandler)
096: process.addCollaborator(collaborationHandler
097: .getCollaboration());
098: else if (handler == loaderHandler)
099: process.setLoader(loaderHandler.getLoader());
100: else if (handler == descriptionHandler)
101: process.setDescription(descriptionHandler.getText());
102: else if (handler == environmentEntryHandler)
103: process.getEnvironment().add(
104: environmentEntryHandler.getEnvironmentEntry());
105: else if (handler == attributeHandler)
106: process.set(attributeHandler.getAttribute().getName(),
107: attributeHandler.getAttribute().getValue());
108: }
109: }
|