1 package org.tigris.scarab.workflow; 2 3 48 49 import java.util.List ; 50 51 import org.apache.turbine.Turbine; 52 import org.tigris.scarab.tools.localization.L10NKeySet; 53 import org.tigris.scarab.util.ScarabException; 54 55 64 public class WorkflowFactory 65 { 66 67 private static ThreadLocal forceUseDefault = new ThreadLocal (); 68 69 77 public static void setForceUseDefault(boolean value) 78 { 79 forceUseDefault.set(value ? Boolean.TRUE : Boolean.FALSE); 80 } 81 82 90 public static boolean getForceUseDefault() 91 { 92 return Boolean.TRUE.equals(forceUseDefault.get()); 93 } 94 95 105 public static Workflow getInstance() throws ScarabException 106 { 107 Workflow wf = null; 108 String className = null; 109 try 110 { 111 if (getForceUseDefault()) 112 { 113 wf = (Workflow) DefaultWorkflow.class.newInstance(); 114 } 115 else 116 { 117 List classNames = Turbine.getConfiguration() 118 .getList("scarab.workflow.classname"); 119 if (classNames.size() > 0) 120 { 121 className = (String ) classNames.get(0); 122 } 123 124 Class wfClass = (className != null ? Class.forName(className) : 125 DefaultWorkflow.class); 126 wf = (Workflow) wfClass.newInstance(); 127 } 128 } 129 catch (InstantiationException ie) 130 { 131 throw new ScarabException(L10NKeySet.ExceptionInstantiation, className, ie); 132 } 133 catch (IllegalAccessException iae) 134 { 135 throw new ScarabException(L10NKeySet.ExceptionIllegalAccess, className, iae); 136 } 137 catch (ClassNotFoundException cnfe) 138 { 139 throw new ScarabException(L10NKeySet.ExceptionClassNotFound, className, cnfe); 140 } 141 return wf; 142 } 143 } 144 | Popular Tags |