Search in sources :

Example 1 with StateMachine

use of org.cristalise.kernel.lifecycle.instance.stateMachine.StateMachine in project kernel by cristal-ise.

the class StateMachineCache method buildObject.

@Override
public StateMachine buildObject(String name, int version, ItemPath path, String data) throws InvalidDataException {
    try {
        StateMachine thisStateMachine = (StateMachine) Gateway.getMarshaller().unmarshall(data);
        thisStateMachine.validate();
        thisStateMachine.setName(name);
        thisStateMachine.setVersion(version);
        thisStateMachine.setItemPath(path);
        return thisStateMachine;
    } catch (Exception ex) {
        Logger.error(ex);
        throw new InvalidDataException("Could not unmarshall State Machine '" + name + "' v" + version + ": " + ex.getMessage());
    }
}
Also used : StateMachine(org.cristalise.kernel.lifecycle.instance.stateMachine.StateMachine) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException)

Example 2 with StateMachine

use of org.cristalise.kernel.lifecycle.instance.stateMachine.StateMachine in project kernel by cristal-ise.

the class Job method getTransition.

public Transition getTransition() {
    if (transition != null && transitionResolved == false) {
        Logger.msg(8, "Job.getTransition() - actProps:" + actProps);
        try {
            StateMachine sm = LocalObjectLoader.getStateMachine(actProps);
            transition = sm.getTransition(transition.getId());
            transitionResolved = true;
        } catch (Exception e) {
            Logger.error(e);
            return transition;
        }
    }
    return transition;
}
Also used : StateMachine(org.cristalise.kernel.lifecycle.instance.stateMachine.StateMachine) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) InvalidItemPathException(org.cristalise.kernel.lookup.InvalidItemPathException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) PersistencyException(org.cristalise.kernel.common.PersistencyException) InvalidAgentPathException(org.cristalise.kernel.lookup.InvalidAgentPathException)

Example 3 with StateMachine

use of org.cristalise.kernel.lifecycle.instance.stateMachine.StateMachine in project kernel by cristal-ise.

the class StandardClient method getRequiredStateMachine.

/**
 * CRISTAL-iSE clients should use the StateMachine information to implement application logic. This method loads the
 * required StateMachine using different cristal-ise configuration.
 *
 * @param propPrefix the Property Name prefix to find client specific configuration
 * @param namesSpaceDefault default value to load bootstrap file if no configuration was provided
 * @param bootfileDefault default value to load bootstrap file if no configuration was provided
 * @return the initialised StateMachine object
 * @throws InvalidDataException Missing/Incorrect configuration data
 */
protected static StateMachine getRequiredStateMachine(String propPrefix, String namesSpaceDefault, String bootfileDefault) throws InvalidDataException {
    if (StringUtils.isBlank(propPrefix))
        throw new InvalidDataException("propertyPrefix must contain a value");
    String smName = Gateway.getProperties().getString(propPrefix + ".StateMachine.name");
    int smVersion = Gateway.getProperties().getInt(propPrefix + ".StateMachine.version");
    try {
        if (StringUtils.isNotBlank(smName) && smVersion != -1) {
            return LocalObjectLoader.getStateMachine(smName, smVersion);
        } else {
            Logger.warning("StandardClient.getRequiredStateMachine() - SM Name and/or Version was not specified, trying to load from bootsrap resource.");
            String stateMachineNS = Gateway.getProperties().getString(propPrefix + ".StateMachine.namespace", namesSpaceDefault);
            String stateMachinePath = Gateway.getProperties().getString(propPrefix + ".StateMachine.bootfile", bootfileDefault);
            return (StateMachine) Gateway.getMarshaller().unmarshall(Gateway.getResource().getTextResource(stateMachineNS, stateMachinePath));
        }
    } catch (Exception e) {
        Logger.error(e);
        throw new InvalidDataException(e.getMessage());
    }
}
Also used : StateMachine(org.cristalise.kernel.lifecycle.instance.stateMachine.StateMachine) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException)

Example 4 with StateMachine

use of org.cristalise.kernel.lifecycle.instance.stateMachine.StateMachine in project kernel by cristal-ise.

the class MainTest method testStateMachine.

@Test
public void testStateMachine() throws Exception {
    Logger.msg("Validating test state machine");
    String smXml = FileStringUtility.url2String(MainTest.class.getResource("/TestStateMachine.xml"));
    StateMachine sm = (StateMachine) Gateway.getMarshaller().unmarshall(smXml);
    sm.validate();
    assert sm.isCoherent() : "Test StateMachine is reporting that it is not coherent";
}
Also used : StateMachine(org.cristalise.kernel.lifecycle.instance.stateMachine.StateMachine) Test(org.junit.Test)

Aggregations

StateMachine (org.cristalise.kernel.lifecycle.instance.stateMachine.StateMachine)4 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)3 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)1 PersistencyException (org.cristalise.kernel.common.PersistencyException)1 InvalidAgentPathException (org.cristalise.kernel.lookup.InvalidAgentPathException)1 InvalidItemPathException (org.cristalise.kernel.lookup.InvalidItemPathException)1 Test (org.junit.Test)1