List of usage examples for org.apache.commons.scxml2.model CustomAction CustomAction
public CustomAction(final String namespaceURI, final String localName, final Class<? extends Action> actionClass)
From source file:org.onehippo.repository.scxml.RepositorySCXMLRegistry.java
private SCXMLDefinition readSCXMLDefinition(final String scxmlDefId, final Node scxmlDefNode) throws SCXMLException { String scxmlDefPath;//from ww w . j a v a 2s . co m String scxmlSource; final List<CustomAction> customActions = new ArrayList<>(); String className = null; try { scxmlDefPath = scxmlDefNode.getPath(); scxmlSource = scxmlDefNode.getProperty(SCXML_SOURCE).getString(); if (StringUtils.isBlank(scxmlSource)) { log.error("SCXML definition source is blank at '{}'. '{}'.", scxmlDefNode.getPath(), scxmlSource); } for (final Node actionNode : new NodeIterable(scxmlDefNode.getNodes())) { if (!actionNode.isNodeType(SCXML_ACTION)) { continue; } String namespace = actionNode.getProperty(SCXML_ACTION_NAMESPACE).getString(); className = actionNode.getProperty(SCXML_ACTION_CLASSNAME).getString(); @SuppressWarnings("unchecked") Class<? extends Action> actionClass = (Class<Action>) Thread.currentThread().getContextClassLoader() .loadClass(className); customActions.add(new CustomAction(namespace, actionNode.getName(), actionClass)); } } catch (ClassNotFoundException e) { throw new SCXMLException("Failed to find the custom action class: " + className, e); } catch (RepositoryException e) { throw new SCXMLException("Failed to read custom actions from repository. " + e.getLocalizedMessage(), e); } catch (Exception e) { throw new SCXMLException("Failed to load custom actions. " + e.getLocalizedMessage(), e); } try { Configuration configuration = createSCXMLReaderConfiguration(scxmlDefPath, customActions); SCXML scxml = SCXMLReader.read(new StreamSource(new StringReader(scxmlSource)), configuration); return new SCXMLDefinitionImpl(scxmlDefId, scxmlDefPath, scxml); } catch (IOException e) { throw new SCXMLException( "IO error while reading SCXML definition at '" + scxmlDefPath + "'. " + e.getLocalizedMessage(), e); } catch (ModelException e) { throw new SCXMLException( "Invalid SCXML model definition at '" + scxmlDefPath + "'. " + e.getLocalizedMessage(), e); } catch (XMLStreamException e) { throw new SCXMLException("Failed to read SCXML XML stream at '" + scxmlDefPath + "'. " + naturalizeXMLStreamExceptionMessage(e), e); } }