
org.geomajas.internal.service.pipeline.PipelineServiceImpl Maven / Gradle / Ivy
/*
* This file is part of Geomajas, a component framework for building
* rich Internet applications (RIA) with sophisticated capabilities for the
* display, analysis and management of geographic information.
* It is a building block that allows developers to add maps
* and other geographic data capabilities to their web applications.
*
* Copyright 2008-2010 Geosparc, http://www.geosparc.com, Belgium
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
package org.geomajas.internal.service.pipeline;
import org.geomajas.global.ExceptionCode;
import org.geomajas.global.GeomajasException;
import org.geomajas.service.pipeline.PipelineContext;
import org.geomajas.service.pipeline.PipelineHook;
import org.geomajas.service.pipeline.PipelineInfo;
import org.geomajas.service.pipeline.PipelineService;
import org.geomajas.service.pipeline.PipelineStep;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
/**
* Service which is allows "executing" a pipeline.
*
* @param type of response object for the pipeline
*
* @author Joachim Van der Auwera
*/
@Component
public class PipelineServiceImpl implements PipelineService {
@Autowired
private ApplicationContext applicationContext;
/** @inheritDoc */
public void execute(String key, String layerId, PipelineContext context, RESPONSE response)
throws GeomajasException {
execute(getPipeline(key, layerId), context, response);
}
/** @inheritDoc */
public void execute(PipelineInfo pipeline, PipelineContext startContext, RESPONSE response)
throws GeomajasException {
PipelineContext context = startContext;
if (null == context) {
context = createContext();
}
for (PipelineStep step : pipeline.getPipeline()) {
if (context.isFinished()) {
break;
}
step.execute(context, response);
}
}
/** @inheritDoc */
public PipelineInfo getPipeline(String pipelineName, String layerId) throws GeomajasException {
PipelineInfo layerPipeline = null;
PipelineInfo defaultPipeline = null;
Collection pipelines = applicationContext.getBeansOfType(PipelineInfo.class).values();
for (PipelineInfo pipeline : pipelines) {
if (pipeline.getPipelineName().equals(pipelineName)) {
String lid = pipeline.getLayerId();
if (null == lid) {
defaultPipeline = pipeline;
} else if (lid.equals(layerId)) {
layerPipeline = pipeline;
}
}
}
if (null == layerPipeline) {
layerPipeline = defaultPipeline;
}
if (null == layerPipeline) {
throw new GeomajasException(ExceptionCode.PIPELINE_UNKNOWN, pipelineName, layerId);
}
extendPipeline(layerPipeline);
return layerPipeline;
}
private void extendPipeline(PipelineInfo pipeline) throws GeomajasException {
if (null == pipeline.getPipeline() && null != pipeline.getDelegatePipeline()) {
PipelineInfo delegate = pipeline.getDelegatePipeline();
extendPipeline(delegate);
Map> extensions = pipeline.getExtensions();
List> steps;
if (null == extensions) {
steps = delegate.getPipeline();
} else {
steps = new ArrayList>(delegate.getPipeline());
int count = 0;
for (int i = steps.size() - 1 ; i >= 0 ; i--) {
PipelineStep step = steps.get(i);
if (step instanceof PipelineHook) {
PipelineStep ext = extensions.get(step.getId());
if (null != ext) {
steps.add(i + 1, ext);
count++;
}
}
}
if (count != extensions.size()) {
throw new GeomajasException(ExceptionCode.PIPELINE_UNSATISFIED_EXTENSION,
pipeline.getPipelineName(), pipeline.getLayerId());
}
}
pipeline.setPipeline(steps);
}
}
/** @inheritDoc */
public PipelineContext createContext() {
return new PipelineContextImpl();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy