
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
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
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