
cz.wicketstuff.boss.flow.processor.basic.NamedFlowStateDataFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of boss-flow Show documentation
Show all versions of boss-flow Show documentation
Workflow control and configuration java framework
/*
* Et netera, http://boss.etnetera.cz - Copyright (C) 2012
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License (version 2.1) as published by the Free Software
* Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* See the GNU Lesser General Public License for more details:
* http://www.gnu.org/licenses/lgpl-3.0.txt
*
*/
package cz.wicketstuff.boss.flow.processor.basic;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import cz.wicketstuff.boss.flow.model.IFlowState;
import cz.wicketstuff.boss.flow.processor.IFlowStateDataFactory;
import cz.wicketstuff.boss.flow.processor.NoSuchStateException;
import cz.wicketstuff.boss.flow.processor.StateDataException;
public class NamedFlowStateDataFactory implements IFlowStateDataFactory, Serializable {
private static final long serialVersionUID = 1L;
private Map> stateDataMap;
private boolean exceptionIfStateNotExist;
public NamedFlowStateDataFactory() {
this(null);
}
public NamedFlowStateDataFactory(
Map> stateDataMap) {
this(stateDataMap, false);
}
public NamedFlowStateDataFactory(
Map> stateDataMap,
boolean exceptionIfStateNotExist) {
this.stateDataMap = stateDataMap;
this.exceptionIfStateNotExist = exceptionIfStateNotExist;
}
@Override
public Serializable createStateData(IFlowState flowState) throws NoSuchStateException, StateDataException {
Class c = getStateDataMap().get(flowState.getStateName());
if(c == null) {
if(exceptionIfStateNotExist) {
throw new NoSuchStateException("Cannot find state '" + flowState.getStateName() + "'");
}
return null;
}
try {
return c.newInstance();
} catch (InstantiationException e) {
throw new StateDataException("Cannot instantiate class for '" + c.getName() + "' for state '" + flowState.getStateName() + "', probably the constructor thrown an exception", e);
} catch (IllegalAccessException e) {
throw new StateDataException("Cannot instantiate class for '" + c.getName() + "' for state '" + flowState.getStateName() + "', probably constructor is private or an interface is mapped instead a regular class.", e);
}
}
public boolean isExceptionIfStateNotExist() {
return exceptionIfStateNotExist;
}
public void setExceptionIfStateNotExist(boolean exceptionIfStateNotExist) {
this.exceptionIfStateNotExist = exceptionIfStateNotExist;
}
public Map> getStateDataMap() {
if(stateDataMap == null) {
stateDataMap = new HashMap>();
}
return stateDataMap;
}
public void setStateDataMap(Map> stateDataMap) {
this.stateDataMap = stateDataMap;
}
@Override
protected void finalize() throws Throwable {
if(stateDataMap != null) {
stateDataMap.clear();
stateDataMap = null;
}
super.finalize();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy