/*
 * This is part of Geomajas, a GIS framework, http://www.geomajas.org/.
 *
 * Copyright 2008-2015 Geosparc nv, http://www.geosparc.com/, Belgium.
 *
 * The program is available in open source according to the GNU Affero
 * General Public License. All contributions in this program are covered
 * by the Geomajas Contributors License Agreement. For full licensing
 * details, see LICENSE.txt in the project root.
 */
package org.geomajas.plugin.printing.component.service;

import java.util.LinkedHashMap;
import java.util.Map;

import org.geomajas.configuration.RasterLayerInfo;
import org.geomajas.configuration.VectorLayerInfo;
import org.geomajas.configuration.client.ClientApplicationInfo;
import org.geomajas.configuration.client.ClientMapInfo;
import org.geomajas.layer.RasterLayer;
import org.geomajas.layer.VectorLayer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Trimmed down configuration service for printing.
 * 
 * @author Jan De Moerloose
 */
@Component()
public class PrintConfigurationServiceImpl implements PrintConfigurationService {

	@Autowired(required = false)
	protected Map<String, ClientApplicationInfo> applicationMap = new LinkedHashMap<String, ClientApplicationInfo>();

	@Autowired(required = false)
	protected Map<String, VectorLayer> vectorLayerMap = new LinkedHashMap<String, VectorLayer>();

	@Autowired(required = false)
	protected Map<String, RasterLayer> rasterLayerMap = new LinkedHashMap<String, RasterLayer>();

	public ClientMapInfo getMapInfo(String mapId, String applicationId) {
		if (null == mapId || null == applicationId) {
			return null;
		}
		ClientApplicationInfo application = applicationMap.get(applicationId);
		if (application != null) {
			for (ClientMapInfo map : application.getMaps()) {
				if (mapId.equals(map.getId())) {
					return map;
				}
			}
		}
		return null;
	}

	public RasterLayerInfo getRasterLayerInfo(String layerId) {
		return layerId == null ? null : rasterLayerMap.get(layerId).getLayerInfo();
	}

	public VectorLayerInfo getVectorLayerInfo(String layerId) {
		return layerId == null ? null : vectorLayerMap.get(layerId).getLayerInfo();
	}

}

@@ -473,63 +473,8 @@
 e;%0A%0A
-import java.util.LinkedHashMap;%0Aimport java.util.Map;%0A%0A
 impo
@@ -614,35 +614,27 @@
 lient.Client
-Application
+Map
 Info;%0Aimport
@@ -651,120 +651,36 @@
 jas.
-configuration.client.ClientMapInfo;%0Aimport org.geomajas.layer.RasterLayer;%0Aimport org.geomajas.layer.VectorLayer
+service.ConfigurationService
 ;%0Aim
@@ -878,16 +878,43 @@
 erloose%0A
+ * @author Jan Venstermans%0A
  */%0A@Com
@@ -1020,392 +1020,59 @@
 ired
-(required = false)%0A%09protected Map%3CString, ClientApplicationInfo%3E applicationMap = new LinkedHashMap%3CString, ClientApplicationInfo%3E();%0A%0A%09@Autowired(required = false)%0A%09protected Map%3CString, VectorLayer%3E vectorLayerMap = new LinkedHashMap%3CString, VectorLayer%3E();%0A%0A%09@Autowired(required = false)%0A%09protected Map%3CString, RasterLayer%3E rasterLayerMap = new LinkedHashMap%3CString, RasterLayer%3E()
+%0A%09private ConfigurationService configurationService
 ;%0A%0A%09
@@ -1156,17 +1156,17 @@
 ull 
-=
+!
 = mapId 
 %7C%7C n
@@ -1165,17 +1165,17 @@
 pId 
-%7C%7C
+&&
  null 
-=
+!
 = ap
@@ -1203,237 +1203,58 @@
 urn 
-null;%0A%09%09%7D%0A%09%09ClientApplicationInfo application = applicationMap.get(applicationId);%0A%09%09if (application != null) %7B%0A%09%09%09for (ClientMapInfo map : application.getMaps()) %7B%0A%09%09%09%09if (mapId.equals(map.getId())) %7B%0A%09%09%09%09%09return map;%0A%09%09%09%09%7D%0A%09%09%09%7D
+configurationService.getMap(mapId, applicationId);
 %0A%09%09%7D
@@ -1368,17 +1368,41 @@
  null : 
-r
+configurationService.getR
 asterLay
@@ -1399,31 +1399,24 @@
 tRasterLayer
-Map.get
 (layerId).ge
@@ -1528,17 +1528,41 @@
  null : 
-v
+configurationService.getV
 ectorLay
@@ -1567,15 +1567,8 @@
 ayer
-Map.get
 (lay

make PrintConfigurationServiceImpl wrap ConfigurationService