@Test public void testWillGo() { State state = new State(); String xml = "<state name=\"state\">\n" + " <paths>\n" + " <path to=\"1\" expr=\"i==1\"/>\n" + " <path to=\"2\" expr=\"i==2\"/>\n" + " </paths>\n" + " </state>"; Document document = null; try { document = DocumentHelper.parseText(xml); } catch (DocumentException e) { e.printStackTrace(); } StateLike s = state.parse(document.getRootElement()); Map m = new HashMap(); m.put("i", 2); String result = null; try { result = s.willGo(m); } catch (Throwable e) { e.printStackTrace(); } Assert.assertEquals("2", result); }
@Override public StateLike parse(Element elem) { super.parse(elem); if (elem.attributeValue(REPEATLIST_TAG) != null) { repeatList = elem.attributeValue(REPEATLIST_TAG); } if (elem.attributeValue(IGNOREWEEKEND_TAG) != null) { ignoreWeekend = Boolean.valueOf(elem.attributeValue(IGNOREWEEKEND_TAG)); } List<Element> invokesPaths = elem.selectNodes(INVOKES_TAG); for (Element node : invokesPaths) { for (Iterator i = node.elementIterator(); i.hasNext(); ) { Element child = (Element)i.next(); try { invokes.add(InvokableFactory.newInstance(child.getName(), child)); } catch (RuntimeException re) { logger.error(String.format("实例Invokable类型时候出错，类型为： %s , 异常为： %s", child.getName(), re.toString())); throw re; } catch (Throwable e) { logger.error(String.format("实例Invokable类型时候出错，类型为： %s , 异常为： %s", child.getName(), e.toString())); throw new UndeclaredThrowableException(e, "error happened when newInstance Invokable class:" + child.getName()); } } } return this; }
State extends RunnableState { @Override public StateLike parse(Element elem) { super.parse(elem); if (elem.attributeValue(REPEATLIST_TAG) != null) { repeatList = elem.attributeValue(REPEATLIST_TAG); } if (elem.attributeValue(IGNOREWEEKEND_TAG) != null) { ignoreWeekend = Boolean.valueOf(elem.attributeValue(IGNOREWEEKEND_TAG)); } List<Element> invokesPaths = elem.selectNodes(INVOKES_TAG); for (Element node : invokesPaths) { for (Iterator i = node.elementIterator(); i.hasNext(); ) { Element child = (Element)i.next(); try { invokes.add(InvokableFactory.newInstance(child.getName(), child)); } catch (RuntimeException re) { logger.error(String.format("实例Invokable类型时候出错，类型为： %s , 异常为： %s", child.getName(), re.toString())); throw re; } catch (Throwable e) { logger.error(String.format("实例Invokable类型时候出错，类型为： %s , 异常为： %s", child.getName(), e.toString())); throw new UndeclaredThrowableException(e, "error happened when newInstance Invokable class:" + child.getName()); } } } return this; } }
State extends RunnableState { @Override public StateLike parse(Element elem) { super.parse(elem); if (elem.attributeValue(REPEATLIST_TAG) != null) { repeatList = elem.attributeValue(REPEATLIST_TAG); } if (elem.attributeValue(IGNOREWEEKEND_TAG) != null) { ignoreWeekend = Boolean.valueOf(elem.attributeValue(IGNOREWEEKEND_TAG)); } List<Element> invokesPaths = elem.selectNodes(INVOKES_TAG); for (Element node : invokesPaths) { for (Iterator i = node.elementIterator(); i.hasNext(); ) { Element child = (Element)i.next(); try { invokes.add(InvokableFactory.newInstance(child.getName(), child)); } catch (RuntimeException re) { logger.error(String.format("实例Invokable类型时候出错，类型为： %s , 异常为： %s", child.getName(), re.toString())); throw re; } catch (Throwable e) { logger.error(String.format("实例Invokable类型时候出错，类型为： %s , 异常为： %s", child.getName(), e.toString())); throw new UndeclaredThrowableException(e, "error happened when newInstance Invokable class:" + child.getName()); } } } return this; }  }
State extends RunnableState { @Override public StateLike parse(Element elem) { super.parse(elem); if (elem.attributeValue(REPEATLIST_TAG) != null) { repeatList = elem.attributeValue(REPEATLIST_TAG); } if (elem.attributeValue(IGNOREWEEKEND_TAG) != null) { ignoreWeekend = Boolean.valueOf(elem.attributeValue(IGNOREWEEKEND_TAG)); } List<Element> invokesPaths = elem.selectNodes(INVOKES_TAG); for (Element node : invokesPaths) { for (Iterator i = node.elementIterator(); i.hasNext(); ) { Element child = (Element)i.next(); try { invokes.add(InvokableFactory.newInstance(child.getName(), child)); } catch (RuntimeException re) { logger.error(String.format("实例Invokable类型时候出错，类型为： %s , 异常为： %s", child.getName(), re.toString())); throw re; } catch (Throwable e) { logger.error(String.format("实例Invokable类型时候出错，类型为： %s , 异常为： %s", child.getName(), e.toString())); throw new UndeclaredThrowableException(e, "error happened when newInstance Invokable class:" + child.getName()); } } } return this; }  @Override Result execute(Map<String, Object> context); @Override StateLike parse(Element elem); String getRepeatList(); void setRepeatList(String repeatList); Boolean getIgnoreWeekend(); void setIgnoreWeekend(Boolean ignoreWeekend); }
State extends RunnableState { @Override public StateLike parse(Element elem) { super.parse(elem); if (elem.attributeValue(REPEATLIST_TAG) != null) { repeatList = elem.attributeValue(REPEATLIST_TAG); } if (elem.attributeValue(IGNOREWEEKEND_TAG) != null) { ignoreWeekend = Boolean.valueOf(elem.attributeValue(IGNOREWEEKEND_TAG)); } List<Element> invokesPaths = elem.selectNodes(INVOKES_TAG); for (Element node : invokesPaths) { for (Iterator i = node.elementIterator(); i.hasNext(); ) { Element child = (Element)i.next(); try { invokes.add(InvokableFactory.newInstance(child.getName(), child)); } catch (RuntimeException re) { logger.error(String.format("实例Invokable类型时候出错，类型为： %s , 异常为： %s", child.getName(), re.toString())); throw re; } catch (Throwable e) { logger.error(String.format("实例Invokable类型时候出错，类型为： %s , 异常为： %s", child.getName(), e.toString())); throw new UndeclaredThrowableException(e, "error happened when newInstance Invokable class:" + child.getName()); } } } return this; }  @Override Result execute(Map<String, Object> context); @Override StateLike parse(Element elem); String getRepeatList(); void setRepeatList(String repeatList); Boolean getIgnoreWeekend(); void setIgnoreWeekend(Boolean ignoreWeekend);  }