List of usage examples for org.apache.commons.scxml.env SimpleErrorHandler SimpleErrorHandler
public SimpleErrorHandler()
From source file:com.korwe.thecore.scxml.ScxmlMessageProcessor.java
@Override public void initialize(String sessionId) { super.initialize(sessionId); try {// w ww .j ava 2 s. co m String scxmlPath = CoreConfig.getInstance().getProperty("scxml_path"); if (LOG.isDebugEnabled()) { LOG.debug("SCXML path = " + scxmlPath); } File scfile = new File(scxmlPath); if (LOG.isDebugEnabled()) { LOG.debug("Absolute path: [" + scfile.getAbsolutePath() + "]"); } InputSource source = new InputSource(new BufferedReader(new FileReader(scxmlPath))); scxml = SCXMLParser.parse(source, new SimpleErrorHandler()); exec = new SCXMLExecutor(new JexlEvaluator(), new SimpleDispatcher(), new SimpleErrorReporter()); exec.setStateMachine(scxml); exec.addListener(scxml, new SimpleSCXMLListener()); exec.registerInvokerClass("x-coremessage", SendCoreMessageInvoker.class); Context context = new JexlContext(); context.set("sessionId", sessionId); context.set("lastMsg", null); exec.setRootContext(context); exec.go(); } catch (Exception e) { LOG.error("Failed to parse SCXML", e); } }
From source file:ch.shaktipat.saraswati.internal.common.AbstractStateMachine.java
/** * Primary constructor, object instantiation incurs parsing cost. * * @param scxmlDocument The URL pointing to the SCXML document that * describes the "lifecycle" of the * instances of this class. * @param rootCtx The root context for this instance. * @param evaluator The expression evaluator for this instance. * * @see Context/* w w w .j a v a2s. c o m*/ * @see Evaluator */ public AbstractStateMachine(final URL scxmlDocument, final Context rootCtx, final Evaluator evaluator) { log = LogFactory.getLog(this.getClass()); ErrorHandler errHandler = new SimpleErrorHandler(); try { stateMachine = SCXMLParser.parse(scxmlDocument, errHandler); } catch (IOException ioe) { logError(ioe); } catch (SAXException sae) { logError(sae); } catch (ModelException me) { logError(me); } initialize(stateMachine, rootCtx, evaluator); }
From source file:com.headstrong.fusion.statemachine.SCXMLStateMachine.java
/** * Initializes the state machine.//from w w w. ja v a2s .c o m * * @throws StateMachineException */ public void init() throws StateMachineException { // Create a list of custom actions, add as many as are needed // currently only one custom action is exposed which internally would // execute action service registered by the component. // Need to take care of the parsing part. SCXML scxml = null; URL url = null; File tempConfigFile = null; try { tempConfigFile = this.persistConfiguration(this.definition); url = tempConfigFile.toURI().toURL(); } catch (MalformedURLException e) { logger.error( "Error persisting the configuration in temp file for state machine id " + this.getId() + ".", e); throw new StateMachineException( "Error creating the state machine for state machine id " + this.getId() + ".", e); } catch (IOException e) { logger.error( "Error persisting the configuration in temp file for state machine id " + this.getId() + ".", e); throw new StateMachineException( "Error creating the state machine for state machine id " + this.getId() + ".", e); } try { Digester scxmlParser = SCXMLParser.newInstance(null, new URLResolver(url), getCustomActions()); scxmlParser.addObjectCreate("*/" + CUSTOM_ACTION_SERVICE + "/properties", HashMap.class); scxmlParser.addSetNext("*/" + CUSTOM_ACTION_SERVICE + "/properties", "setProperties"); // call the put method on the top object on the digester stack // passing the key attribute as the 0th parameter // and the element body text as the 1th parameter.. scxmlParser.addCallMethod("*/" + CUSTOM_ACTION_SERVICE + "/properties/property", "put", 2); scxmlParser.addCallParam("*/" + CUSTOM_ACTION_SERVICE + "/properties/property", 0, "name"); scxmlParser.addCallParam("*/" + CUSTOM_ACTION_SERVICE + "/properties/property", 1, "value"); scxmlParser.setErrorHandler(new SimpleErrorHandler()); scxml = (SCXML) scxmlParser.parse(url.toString()); SCXMLParser.updateSCXML(scxml); } catch (IOException e) { logger.error( "Error persisting the configuration in temp file for state machine id " + this.getId() + "."); throw new StateMachineException( "Error creating the state machine for state machine id " + this.getId() + ".", e); } catch (SAXException e) { logger.error("Error parsing the configuration for state machine id " + this.getId() + "."); throw new StateMachineException( "Error creating the state machine for state machine id " + this.getId() + ".", e); } catch (ModelException e) { logger.error("Error persisting the configuration for state machine id " + this.getId() + "."); throw new StateMachineException( "Error creating the state machine for state machine id " + this.getId() + ".", e); } // Once done remove the file. tempConfigFile.delete(); // initialize the executor. scxmlExecutor = new SCXMLExecutor(); scxmlExecutor.setStateMachine(scxml); scxmlExecutor.setEvaluator(this.getEvaluator()); scxmlExecutor.setErrorReporter(this.getErrorReporter()); scxmlExecutor.setEventdispatcher(this.getEventDispatcher(scxmlExecutor)); scxmlExecutor.addListener(scxml, new SimpleSCXMLListener()); scxmlExecutor.registerInvokerClass("scxml", SimpleSCXMLInvoker.class); scxmlExecutor.setRootContext(scxmlExecutor.getEvaluator().newContext(null)); }
From source file:de.dfki.iui.mmds.scxml.engine.impl.SCXMLEngineImpl.java
/** * Load the SCXML object representing this state machine. * /*from w ww. j a va 2 s . c o m*/ * @param scxmlDocument * The URL pointing to the SCXML document that describes the * "lifecycle" of the instances of this class. * @return Returns the stateMachine. */ private SCXML load(final URL scxmlDocument) { log = LogFactory.getLog(this.getClass()); // logInfo(log.getClass().getName()); if (log.isDebugEnabled()) { // logInfo("debub enabled"); } ErrorHandler errHandler = new SimpleErrorHandler(); try { List customActions = new ArrayList(); CustomAction ca = new CustomAction("http://www.dfki.de/mmds/scxml/customaction", "raise", Raise.class); customActions.add(ca); SCXML stateMachine = SCXMLParser.parse(scxmlDocument, errHandler, customActions); // logInfo("SCXML loaded"); return stateMachine; } catch (IOException ioe) { logError(ioe); } catch (SAXException sae) { logError(sae); } catch (ModelException me) { logError(me); } return null; }
From source file:org.dishevelled.piccolo.identify.AbstractIdNode.java
/** * Create a new abstract id node with the specified value. * * @param value value for this id node/*from w w w . j av a2 s . com*/ */ protected AbstractIdNode(final Object value) { this.value = value; iconSize = DEFAULT_ICON_SIZE; iconState = DEFAULT_ICON_STATE; iconTextDirection = DEFAULT_ICON_TEXT_DIRECTION; iconBundleImageNode = new IconBundleImageNode(); nameTextNode = new NameTextNode(); dragHandler = new DragHandler(); mouseoverHandler = new MouseoverHandler(); addInputEventListener(dragHandler); addInputEventListener(mouseoverHandler); if (stateMachine == null) { try { URL stateChart = getClass().getResource("stateChart.xml"); stateMachine = SCXMLParser.parse(stateChart, new SimpleErrorHandler()); } catch (Exception e) { // ignore } } stateMachineSupport = new StateMachineSupport(this, stateMachine); }
From source file:org.dishevelled.piccolo.sprite.statemachine.AbstractStateMachineSprite.java
/** * Load the state machine resource with the specified name, if any. Any exceptions thrown * will be ignored./*from ww w. jav a 2 s . c o m*/ * * @param cls class * @param name name * @return the state machine resource with the specified name, or <code>null</code> * if no such resource exists */ protected static final <T> SCXML loadStateMachine(final Class<T> cls, final String name) { SCXML stateMachine = null; try { stateMachine = SCXMLParser.parse(cls.getResource(name), new SimpleErrorHandler()); } catch (IOException e) { // ignore } catch (SAXException e) { // ignore } catch (ModelException e) { // ignore } return stateMachine; }