public static StateMachineFactory load(URL url) throws SAXException, IOException, ParserConfigurationException { return load(url.openStream()); }
public static StateMachineFactory load(File model) throws FileNotFoundException, SAXException, IOException, ParserConfigurationException { return load(new FileInputStream(model)); }
/** * It will first check model file from file path, if it does not exist, it will try classpath then. * @param path * @return * @throws Exception */ public static StateMachineFactory load(String path) throws FileNotFoundException, SAXException, IOException, ParserConfigurationException { InputStream in; File f = new File(path); if(f.exists()) in = new FileInputStream(f); else { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); if (classLoader == null) { classLoader = StateMachineFactory.class.getClassLoader(); } in = classLoader.getResource(path).openStream(); } return load(in); }
public static void main(String[] args) { try { StateMachineFactory f = StateMachineFactory.load("sample.xstate"); StateMachine sm = f.create("vip flow"); System.out.println("Start state: " + sm.getCurrentState().getId()); notify(sm, "pass"); notify(sm, "pass"); notify(sm, "pass"); notify(sm, "pass"); notify(sm, "pass"); System.out.println("End state: " + sm.getCurrentState().getId()); } catch (Exception e) { e.printStackTrace(); } }
public static void main(String[] args) { try { StateMachineFactory f = StateMachineFactory.load("sample.xstate"); StateMachine sm = f.create("DB Health Lifecycle"); System.out.println("Start state: " + sm.getCurrentState().getId()); notify(sm, "initialize"); notify(sm, "markdown"); notify(sm, "markup"); notify(sm, "shutdown"); System.out.println("End state: " + sm.getCurrentState().getId()); showSourceAndTargetEvent(sm); } catch (Exception e) { e.printStackTrace(); } }