Return-Path: Delivered-To: apmail-cocoon-lenya-cvs-archive@cocoon.apache.org Received: (qmail 64664 invoked by uid 500); 28 May 2003 15:31:57 -0000 Mailing-List: contact lenya-cvs-help@cocoon.apache.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Post: List-Help: List-Unsubscribe: List-Subscribe: Reply-To: "Lenya CVS Mailing List" Delivered-To: mailing list lenya-cvs@cocoon.apache.org Received: (qmail 64653 invoked from network); 28 May 2003 15:31:57 -0000 Date: 28 May 2003 15:31:57 -0000 Message-ID: <20030528153157.17164.qmail@icarus.apache.org> From: andreas@apache.org To: cocoon-lenya-cvs@apache.org Subject: cvs commit: cocoon-lenya/src/java/org/apache/lenya/cms/workflow/impl WorkflowBuilder.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N andreas 2003/05/28 08:31:56 Modified: src/java/org/apache/lenya/cms/workflow/impl WorkflowBuilder.java Log: formatting changed Revision Changes Path 1.4 +75 -54 cocoon-lenya/src/java/org/apache/lenya/cms/workflow/impl/WorkflowBuilder.java Index: WorkflowBuilder.java =================================================================== RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/workflow/impl/WorkflowBuilder.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- WorkflowBuilder.java 27 May 2003 15:27:19 -0000 1.3 +++ WorkflowBuilder.java 28 May 2003 15:31:56 -0000 1.4 @@ -11,11 +11,13 @@ import java.util.HashMap; import java.util.Map; import javax.xml.parsers.ParserConfigurationException; + import org.apache.lenya.cms.workflow.Action; import org.apache.lenya.cms.workflow.Condition; import org.apache.lenya.cms.workflow.Event; import org.apache.lenya.cms.workflow.State; import org.apache.lenya.cms.workflow.Workflow; +import org.apache.lenya.cms.workflow.WorkflowBuildException; import org.apache.lenya.xml.DocumentHelper; import org.apache.lenya.xml.NamespaceHelper; import org.w3c.dom.Document; @@ -28,42 +30,46 @@ * @author andreas */ public class WorkflowBuilder { - + /** Creates a new instance of WorkflowBuilder */ public WorkflowBuilder() { } - + public static final String NAMESPACE = "http://www.lenya.org/2003/workflow"; public static final String DEFAULT_PREFIX = "wf"; - - public Workflow buildWorkflow(File file) - throws WorkflowBuildException { + + public Workflow buildWorkflow(File file) throws WorkflowBuildException { Workflow workflow; - + try { Document document = DocumentHelper.readDocument(file); workflow = buildWorkflow(document); - } - catch (Exception e) { + } catch (Exception e) { throw new WorkflowBuildException(e); } - + return workflow; } - + public Workflow buildWorkflow(Document document) - throws ParserConfigurationException, SAXException, IOException, WorkflowBuildException { - - NamespaceHelper helper = new NamespaceHelper(NAMESPACE, DEFAULT_PREFIX, document); - + throws + ParserConfigurationException, + SAXException, + IOException, + WorkflowBuildException { + + NamespaceHelper helper = + new NamespaceHelper(NAMESPACE, DEFAULT_PREFIX, document); + Element root = document.getDocumentElement(); State initialState = null; - + Map states = new HashMap(); Map events = new HashMap(); - + // load states - NodeList stateElements = root.getElementsByTagNameNS(NAMESPACE, STATE_ELEMENT); + NodeList stateElements = + root.getElementsByTagNameNS(NAMESPACE, STATE_ELEMENT); for (int i = 0; i < stateElements.getLength(); i++) { Element element = (Element) stateElements.item(i); StateImpl state = buildState(element); @@ -73,36 +79,41 @@ initialState = state; } } - + assert initialState != null; WorkflowImpl workflow = new WorkflowImpl(initialState); - + // load events - NodeList eventElements = root.getElementsByTagNameNS(NAMESPACE, EVENT_ELEMENT); + NodeList eventElements = + root.getElementsByTagNameNS(NAMESPACE, EVENT_ELEMENT); for (int i = 0; i < eventElements.getLength(); i++) { EventImpl event = buildEvent((Element) eventElements.item(i)); String id = event.getId(); events.put(id, event); } - + // load transitions - NodeList transitionElements = root.getElementsByTagNameNS(NAMESPACE, TRANSITION_ELEMENT); + NodeList transitionElements = + root.getElementsByTagNameNS(NAMESPACE, TRANSITION_ELEMENT); for (int i = 0; i < transitionElements.getLength(); i++) { - TransitionImpl transition - = buildTransition((Element) transitionElements.item(i), states, events); + TransitionImpl transition = + buildTransition( + (Element) transitionElements.item(i), + states, + events); workflow.addTransition(transition); } - + return workflow; } - + protected boolean isInitialStateElement(Element element) { assert element.getLocalName().equals(STATE_ELEMENT); String initialAttribute = element.getAttribute(INITIAL_ATTRIBUTE); return initialAttribute != null && (initialAttribute.equals("yes") || initialAttribute.equals("true")); } - + public static final String STATE_ELEMENT = "state"; public static final String TRANSITION_ELEMENT = "transition"; public static final String EVENT_ELEMENT = "event"; @@ -113,80 +124,90 @@ public static final String SOURCE_ATTRIBUTE = "source"; public static final String DESTINATION_ATTRIBUTE = "destination"; public static final String CLASS_ATTRIBUTE = "class"; - + protected StateImpl buildState(Element element) { assert element.getLocalName().equals(STATE_ELEMENT); - + String id = element.getAttribute(ID_ATTRIBUTE); StateImpl state = new StateImpl(id); return state; } - - protected TransitionImpl buildTransition(Element element, Map states, Map events) - throws WorkflowBuildException { + + protected TransitionImpl buildTransition( + Element element, + Map states, + Map events) + throws WorkflowBuildException { assert element.getLocalName().equals(TRANSITION_ELEMENT); - + String sourceId = element.getAttribute(SOURCE_ATTRIBUTE); String destinationId = element.getAttribute(DESTINATION_ATTRIBUTE); - + assert sourceId != null; assert destinationId != null; - + State source = (State) states.get(sourceId); State destination = (State) states.get(destinationId); - + assert source != null; assert destination != null; - + TransitionImpl transition = new TransitionImpl(source, destination); - + // set event - Element eventElement - = (Element) element.getElementsByTagNameNS(NAMESPACE, EVENT_ELEMENT).item(0); + Element eventElement = + (Element) element.getElementsByTagNameNS( + NAMESPACE, + EVENT_ELEMENT).item( + 0); String id = eventElement.getAttribute(ID_ATTRIBUTE); assert id != null; - + Event event = (Event) events.get(id); assert event != null; - + transition.setEvent(event); - + // load conditions - NodeList conditionElements = element.getElementsByTagNameNS(NAMESPACE, CONDITION_ELEMENT); + NodeList conditionElements = + element.getElementsByTagNameNS(NAMESPACE, CONDITION_ELEMENT); for (int i = 0; i < conditionElements.getLength(); i++) { - Condition condition = buildCondition((Element) conditionElements.item(i)); + Condition condition = + buildCondition((Element) conditionElements.item(i)); transition.addCondition(condition); } - + // load actions - NodeList actionElements = element.getElementsByTagNameNS(NAMESPACE, ACTION_ELEMENT); + NodeList actionElements = + element.getElementsByTagNameNS(NAMESPACE, ACTION_ELEMENT); for (int i = 0; i < actionElements.getLength(); i++) { Action action = buildAction((Element) actionElements.item(i)); transition.addAction(action); } - + return transition; } - + protected EventImpl buildEvent(Element element) { String id = element.getAttribute(ID_ATTRIBUTE); assert id != null; EventImpl event = new EventImpl(id); return event; } - + protected Condition buildCondition(Element element) - throws WorkflowBuildException { + throws WorkflowBuildException { String className = element.getAttribute(CLASS_ATTRIBUTE); String expression = DocumentHelper.getSimpleElementText(element); - Condition condition = ConditionFactory.createCondition(className, expression); + Condition condition = + ConditionFactory.createCondition(className, expression); return condition; } - + protected Action buildAction(Element element) { String id = element.getAttribute(ID_ATTRIBUTE); Action action = new ActionImpl(id); return action; } - + } --------------------------------------------------------------------- To unsubscribe, e-mail: lenya-cvs-unsubscribe@cocoon.apache.org For additional commands, e-mail: lenya-cvs-help@cocoon.apache.org