
cz.wicketstuff.boss.flow.util.processor.FlowSwitchStateProcessorCollection 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.util.processor;
import java.io.Serializable;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import cz.wicketstuff.boss.flow.model.IFlowCarter;
import cz.wicketstuff.boss.flow.processor.condition.IFlowMatchedSwitchProcessor;
import cz.wicketstuff.boss.flow.processor.condition.IFlowSwitchProcessor;
public class FlowSwitchStateProcessorCollection
implements IFlowSwitchProcessor, Serializable, Iterable> {
private static final long serialVersionUID = 1L;
private static final Logger log = LoggerFactory.getLogger(FlowSwitchStateProcessorCollection.class);
private final List> processors;
public FlowSwitchStateProcessorCollection() {
this(null);
}
public FlowSwitchStateProcessorCollection(
List> processors) {
this.processors = createList(processors);
}
@Override
public String resolveSwitchExpression(IFlowCarter flow,
String switchExpression) {
if(log.isDebugEnabled()) {
log.debug("resolveSwitchExpression: " + switchExpression);
}
if(log.isTraceEnabled()) {
log.trace("flow: " + flow.toString());
}
for(IFlowMatchedSwitchProcessor processor : processors) {
if(processor.match(switchExpression, flow)) {
return processor.resolveSwitchExpression(flow, switchExpression);
}
}
return null;
}
public List> createList(List> processors) {
if(processors == null) {
return new CopyOnWriteArrayList>();
} else {
return new CopyOnWriteArrayList>(processors);
}
}
public boolean add(IFlowMatchedSwitchProcessor processor) {
return processors.add(processor);
}
public boolean remove(IFlowMatchedSwitchProcessor processor) {
return processors.remove(processor);
}
@Override
public Iterator> iterator() {
return processors.iterator();
}
@Override
protected void finalize() throws Throwable {
if(processors != null) {
processors.clear();
}
super.finalize();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy