
cz.wicketstuff.boss.flow.util.processor.FlowConditionStateProcessorCollection 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.CannotProcessConditionException;
import cz.wicketstuff.boss.flow.processor.condition.IFlowConditionProcessor;
import cz.wicketstuff.boss.flow.processor.condition.IFlowMatchedConditionProcessor;
public class FlowConditionStateProcessorCollection
implements IFlowConditionProcessor, Serializable, Iterable> {
private static final long serialVersionUID = 1L;
private static final Logger log = LoggerFactory.getLogger(FlowConditionStateProcessorCollection.class);
private final List> processors;
public FlowConditionStateProcessorCollection() {
this(null);
}
public FlowConditionStateProcessorCollection(
List> processors) {
this.processors = createList(processors);
}
@Override
public boolean ifCondition(String conditionExpression, IFlowCarter flow)
throws CannotProcessConditionException {
if(log.isDebugEnabled()) {
log.debug("ifCondition conditionExpression: " + conditionExpression);
}
if(log.isTraceEnabled()) {
log.trace("flow: " + flow.toString());
}
for(IFlowMatchedConditionProcessor processor : processors) {
if(processor.match(conditionExpression, flow)) {
return processor.ifCondition(conditionExpression, flow);
}
}
throw new CannotProcessConditionException("Condition hasn't been matched and processed. Probably it is an uknown expression.");
}
public List> createList(List> processors) {
if(processors == null) {
return new CopyOnWriteArrayList>();
} else {
return new CopyOnWriteArrayList>(processors);
}
}
public boolean add(IFlowMatchedConditionProcessor processor) {
return processors.add(processor);
}
public boolean remove(IFlowMatchedConditionProcessor 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