1 5 6 package org.exoplatform.services.workflow.impl; 7 8 import org.jbpm.model.definition.Definition; 9 import org.jbpm.util.xml.Dom4jHelper; 10 import org.dom4j.Element; 11 import org.dom4j.DocumentException; 12 import org.exoplatform.services.workflow.*; 13 14 import java.util.Locale ; 15 import java.util.Map ; 16 import java.util.HashMap ; 17 import java.util.Iterator ; 18 19 24 public class WorkflowFormsServiceImpl implements WorkflowFormsService { 25 26 29 private static Map allForms = new HashMap (); 30 31 public void addForms(Definition definition, 32 WorkflowExecutionService executionService, 33 Locale locale) { 34 if (!allForms.containsKey(definition.getId())) { 35 Map stateNameToForms = new HashMap (); 36 byte[] bytes = executionService.getFile(definition.getId(), "forms.xml"); 37 Iterator iter = null; 38 try { 39 iter = Dom4jHelper.getRootElement(bytes).elements("form").iterator(); 40 } catch (DocumentException e) { 41 e.printStackTrace(); 42 } 43 while (iter.hasNext()) { 44 Element formElement = (Element) iter.next(); 45 Form formConfiguration = new FormImpl(definition.getId(), formElement, 46 executionService, locale); 47 stateNameToForms.put(formConfiguration.getStateName(), 48 formConfiguration); 49 } 50 51 allForms.put(definition.getId(), stateNameToForms); 52 } 53 } 54 55 public Form getForm(Long definitionId, String stateName) { 56 Form formConfiguration = null; 57 if (definitionId == null) 58 throw new NullPointerException ("definitionId is null in Form.getForm"); 59 if (stateName == null) 60 throw new NullPointerException ("stateName is null in Form.getForm"); 61 62 Map stateNameToForms = (Map ) allForms.get(definitionId); 63 if (stateNameToForms == null) 64 throw new IllegalArgumentException ("forms for definition '" + definitionId + 65 "' were not yet initialised"); 66 formConfiguration = (Form) stateNameToForms.get(stateName); 67 if (stateNameToForms == null) 68 throw new IllegalArgumentException ("no form was specified for state '" 69 + stateName + "' in definition '" + definitionId + "'"); 70 71 return formConfiguration; 72 } 73 } 74 | Popular Tags |