gt: 		if (internalConfig.isTransformCoordinates()) {
context: /*
   * This file is part of the 3D City Database Importer/Exporter.
   * Copyright (c) 2007 - 2013
   * Institute for Geodesy and Geoinformation Science
   * Technische Universitaet Berlin, Germany
   * http://www.gis.tu-berlin.de/
   * 
   * The 3D City Database Importer/Exporter program is free software:
   * you can redistribute it and/or modify it under the terms of the
   * GNU Lesser 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 Lesser General Public License for more details.
   * 
   * You should have received a copy of the GNU Lesser General Public
   * License along with this program. If not, see 
   * <http://www.gnu.org/licenses/>.
   * 
   * The development of the 3D City Database Importer/Exporter has 
   * been financially supported by the following cooperation partners:
   * 
   * Business Location Center, Berlin <http://www.businesslocationcenter.de/>
   * virtualcitySYSTEMS GmbH, Berlin <http://www.virtualcitysystems.de/>
   * Berlin Senate of Business, Technology and Women <http://www.berlin.de/sen/wtf/>
   */
  package de.tub.citydb.modules.citygml.exporter.controller;
  
  import java.io.File;
  import java.io.FileOutputStream;
  import java.io.IOException;
  import java.io.OutputStreamWriter;
  import java.sql.SQLException;
  import java.util.EnumMap;
  import java.util.HashMap;
  import java.util.concurrent.atomic.AtomicBoolean;
  
  import javax.xml.transform.stream.StreamResult;
  
  import org.citygml4j.builder.jaxb.JAXBBuilder;
  import org.citygml4j.builder.jaxb.xml.io.writer.JAXBModelWriter;
  import org.citygml4j.builder.jaxb.xml.io.writer.JAXBOutputFactory;
  import org.citygml4j.model.citygml.CityGMLClass;
  import org.citygml4j.model.gml.GMLClass;
  import org.citygml4j.model.module.Module;
  import org.citygml4j.model.module.ModuleContext;
  import org.citygml4j.model.module.citygml.AppearanceModule;
  import org.citygml4j.model.module.citygml.CityGMLModule;
  import org.citygml4j.model.module.citygml.CityGMLModuleType;
  import org.citygml4j.model.module.citygml.CityGMLVersion;
  import org.citygml4j.model.module.citygml.CoreModule;
  import org.citygml4j.util.xml.SAXEventBuffer;
  import org.citygml4j.util.xml.SAXWriter;
  import org.citygml4j.xml.io.writer.CityGMLWriteException;
  import org.citygml4j.xml.io.writer.CityModelInfo;
  import org.xml.sax.SAXException;
  
  import de.tub.citydb.api.concurrent.SingleWorkerPool;
  import de.tub.citydb.api.concurrent.WorkerPool;
  import de.tub.citydb.api.database.DatabaseSrs;
  import de.tub.citydb.api.event.Event;
  import de.tub.citydb.api.event.EventDispatcher;
  import de.tub.citydb.api.event.EventHandler;
  import de.tub.citydb.api.gui.BoundingBox;
  import de.tub.citydb.config.Config;
  import de.tub.citydb.config.internal.Internal;
  import de.tub.citydb.config.project.database.Database;
  import de.tub.citydb.config.project.exporter.ExportAppearance;
  import de.tub.citydb.config.project.filter.TileNameSuffixMode;
  import de.tub.citydb.config.project.filter.TileSuffixMode;
  import de.tub.citydb.config.project.filter.Tiling;
  import de.tub.citydb.config.project.filter.TilingMode;
  import de.tub.citydb.database.DatabaseConnectionPool;
  import de.tub.citydb.log.Logger;
  import de.tub.citydb.modules.citygml.common.database.cache.CacheManager;
  import de.tub.citydb.modules.citygml.common.database.cache.model.CacheTableModelEnum;
  import de.tub.citydb.modules.citygml.common.database.gmlid.DBGmlIdLookupServerEnum;
  import de.tub.citydb.modules.citygml.common.database.gmlid.DBGmlIdLookupServerManager;
  import de.tub.citydb.modules.citygml.common.database.xlink.DBXlink;
  import de.tub.citydb.modules.citygml.exporter.concurrent.DBExportWorkerFactory;
  import de.tub.citydb.modules.citygml.exporter.concurrent.DBExportXlinkWorkerFactory;
  import de.tub.citydb.modules.citygml.exporter.database.content.DBSplitter;
  import de.tub.citydb.modules.citygml.exporter.database.content.DBSplittingResult;
  import de.tub.citydb.modules.citygml.exporter.database.gmlid.DBExportCache;
  import de.tub.citydb.modules.common.concurrent.IOWriterWorkerFactory;
  import de.tub.citydb.modules.common.event.EventType;
  import de.tub.citydb.modules.common.event.FeatureCounterEvent;
  import de.tub.citydb.modules.common.event.GeometryCounterEvent;
  import de.tub.citydb.modules.common.event.InterruptEvent;
  import de.tub.citydb.modules.common.event.StatusDialogMessage;
  import de.tub.citydb.modules.common.event.StatusDialogTitle;
  import de.tub.citydb.modules.common.filter.ExportFilter;
  import de.tub.citydb.util.Util;
  import de.tub.citydb.util.database.DBUtil;
  import de.tub.citydb.util.database.IndexStatusInfo.IndexType;
  
  public class Exporter implements EventHandler {
  	private final Logger LOG = Logger.getInstance();
  
  	private final JAXBBuilder jaxbBuilder;
  	private final DatabaseConnectionPool dbPool;
  	private final Config config;
  	private final EventDispatcher eventDispatcher;
  	private DBSplitter dbSplitter;
  
  	private volatile boolean shouldRun = true;
  	private AtomicBoolean isInterrupted = new AtomicBoolean(false);
  
  	private WorkerPool<DBSplittingResult> dbWorkerPool;
  	private SingleWorkerPool<SAXEventBuffer> ioWriterPool;
  	private WorkerPool<DBXlink> xlinkExporterPool;
  	private CacheManager cacheManager;
  	private DBGmlIdLookupServerManager lookupServerManager;
  	private ExportFilter exportFilter;
  	private boolean useTiling;
  
  	private EnumMap<CityGMLClass, Long> totalFeatureCounterMap;
  	private EnumMap<GMLClass, Long> totalGeometryCounterMap;
  	private EnumMap<CityGMLClass, Long> featureCounterMap;
  	private EnumMap<GMLClass, Long> geometryCounterMap;
  
  	public Exporter(JAXBBuilder jaxbBuilder, DatabaseConnectionPool dbPool, Config config, EventDispatcher eventDispatcher) {
  		this.jaxbBuilder = jaxbBuilder;
  		this.dbPool = dbPool;
  		this.config = config;
  		this.eventDispatcher = eventDispatcher;
  
  		featureCounterMap = new EnumMap<CityGMLClass, Long>(CityGMLClass.class);
  		geometryCounterMap = new EnumMap<GMLClass, Long>(GMLClass.class);
  		totalFeatureCounterMap = new EnumMap<CityGMLClass, Long>(CityGMLClass.class);
  		totalGeometryCounterMap = new EnumMap<GMLClass, Long>(GMLClass.class);
  	}
  	
  	public void cleanup() {
  		eventDispatcher.removeEventHandler(this);
  	}
  
  	public boolean doProcess() {
  		// get config shortcuts
  		de.tub.citydb.config.project.system.System system = config.getProject().getExporter().getSystem();
  		Database database = config.getProject().getDatabase();
  
  		// worker pool settings
  		int minThreads = system.getThreadPool().getDefaultPool().getMinThreads();
  		int maxThreads = system.getThreadPool().getDefaultPool().getMaxThreads();
  
  		// calc queueSize
  		// how to properly calculate?
  		//int dbQueueSize = maxThreads * 20;
  		//int writerQueueSize = maxThreads * 100;
  
  		// gml:id lookup cache update
  		int lookupCacheBatchSize = database.getUpdateBatching().getGmlIdLookupServerBatchValue();		
  
  		// adding listeners
  		eventDispatcher.addEventHandler(EventType.FEATURE_COUNTER, this);
  		eventDispatcher.addEventHandler(EventType.GEOMETRY_COUNTER, this);
  		eventDispatcher.addEventHandler(EventType.INTERRUPT, this);
  
  		// checking workspace... this should be improved in future...
  //		Workspace workspace = database.getWorkspaces().getExportWorkspace();
  //		if (shouldRun && !workspace.getName().toUpperCase().equals("LIVE")) {
  //			boolean workspaceExists = dbPool.existsWorkspace(workspace);
  //
  //			String name = "'" + workspace.getName().trim() + "'";
  //			String timestamp = workspace.getTimestamp().trim();
  //			if (timestamp.trim().length() > 0)
  //				name += " at timestamp " + timestamp;
  //
  //			if (!workspaceExists) {
  //				LOG.error("Database workspace " + name + " is not available.");
  //				return false;
  //			} else 
  //				LOG.info("Switching to database workspace " + name + '.');
  //		}
  
  		// set module context according to CityGML version and create SAX writer
  		CityGMLVersion version = config.getProject().getExporter().getCityGMLVersion().toCityGMLVersion();
  		ModuleContext moduleContext = new ModuleContext(version);
  		CityModelInfo cityModel = new CityModelInfo();
  
  		SAXWriter saxWriter = new SAXWriter();
  		saxWriter.setWriteEncoding(true);
  		saxWriter.setIndentString("  ");
  		saxWriter.setHeaderComment("Written by " + this.getClass().getPackage().getImplementationTitle() + ", version \"" +
  				this.getClass().getPackage().getImplementationVersion() + '"', 
  				this.getClass().getPackage().getImplementationVendor());
  		saxWriter.setDefaultNamespace(moduleContext.getModule(CityGMLModuleType.CORE).getNamespaceURI());
  
  		for (Module module : moduleContext.getModules()) {
  			if (module instanceof CoreModule)
  				continue;
  
  			if (version != CityGMLVersion.v0_4_0 &&
  					!config.getProject().getExporter().getAppearances().isSetExportAppearance() &&
  					module instanceof AppearanceModule)
  				continue;
  
  			saxWriter.setPrefix(module.getNamespacePrefix(), module.getNamespaceURI());
  			if (module instanceof CityGMLModule)
  				saxWriter.setSchemaLocation(module.getNamespaceURI(), module.getSchemaLocation());
  		}
  
  		// checking file
  		Internal internalConfig = config.getInternal();
  		File exportFile = new File(internalConfig.getExportFileName());
  		String fileName = exportFile.getName();
  		String folderName = new File(exportFile.getAbsolutePath()).getParent();
  
  		String fileExtension = Util.getFileExtension(fileName);		
  		if (fileExtension == null)
  			fileExtension = "gml";
  		else
  			fileName = Util.stripFileExtension(fileName);
  
  		// create export folder
  		File folder = new File(folderName);
  		if (!folder.exists() && !folder.mkdirs()) {
  			LOG.error("Failed to create folder '" + folderName + "'.");
  			return false;
  		}
  
  		// set target reference system for export
  		DatabaseSrs targetSRS = config.getProject().getExporter().getTargetSRS();
  		if (!targetSRS.isSupported())
  			targetSRS = dbPool.getActiveConnectionMetaData().getReferenceSystem();
  
  		internalConfig.setExportTargetSRS(targetSRS);
  		internalConfig.setTransformCoordinates(targetSRS.isSupported() && 
  				targetSRS.getSrid() != dbPool.getActiveConnectionMetaData().getReferenceSystem().getSrid());
  
  