/*
 * Created on Jun 30, 2006
 */
package org.griphyn.vdl.mapping;

import java.util.HashMap;
import java.util.Map;

import org.griphyn.vdl.mapping.file.AirsnMapper;
import org.griphyn.vdl.mapping.file.CSVMapper;
import org.griphyn.vdl.mapping.file.ConcurrentMapper;
import org.griphyn.vdl.mapping.file.FileSystemArrayMapper;
import org.griphyn.vdl.mapping.file.FixedArrayFileMapper;
import org.griphyn.vdl.mapping.file.SingleFileMapper;
import org.griphyn.vdl.mapping.file.ROIMapper;
import org.griphyn.vdl.mapping.file.RegularExpressionMapper;
import org.griphyn.vdl.mapping.file.SimpleFileMapper;

public class MapperFactory {
	private static Map mappers = new HashMap();

	static {
		registerMapper("simple_mapper", SimpleFileMapper.class);
		registerMapper("single_file_mapper", SingleFileMapper.class);
		registerMapper("fixed_array_mapper", FixedArrayFileMapper.class);
        registerMapper("concurrent_mapper", ConcurrentMapper.class);
        registerMapper("filesys_mapper", FileSystemArrayMapper.class);
        registerMapper("regexp_mapper", RegularExpressionMapper.class);
        registerMapper("csv_mapper", CSVMapper.class);
        registerMapper("airsn_mapper", AirsnMapper.class);
        registerMapper("roi_mapper", ROIMapper.class);
	}

	public synchronized static Mapper getMapper(String type, Map params) throws InvalidMapperException {
		Class cls = (Class) mappers.get(type);
		if (cls == null) {
			throw new InvalidMapperException(type);
		}
		try {
			Mapper mapper = (Mapper) cls.newInstance();
			mapper.setParams(params);
            return mapper;
		}
		catch (InvalidMappingParameterException e) {
			throw new InvalidMapperException(type + ": " + e.getMessage(), e);
		}
		catch (Exception e) {
			throw new InvalidMapperException(type, e);
		}
	}

	public static void registerMapper(String type, String cls) throws ClassNotFoundException {
		registerMapper(type, MapperFactory.class.getClassLoader().loadClass(cls));
	}

	public synchronized static void registerMapper(String type, Class cls) {
		mappers.put(type, cls);
	}

}

@@ -866,32 +866,26 @@
 per.class);%0A
-        
+%09%09
 registerMapp
@@ -929,32 +929,26 @@
 per.class);%0A
-        
+%09%09
 registerMapp
@@ -994,32 +994,26 @@
 per.class);%0A
-        
+%09%09
 registerMapp
@@ -1060,32 +1060,26 @@
 per.class);%0A
-        
+%09%09
 registerMapp
@@ -1109,32 +1109,26 @@
 per.class);%0A
-        
+%09%09
 registerMapp
@@ -1166,24 +1166,18 @@
 class);%0A
-        
+%09%09
 register
@@ -1518,20 +1518,11 @@
 s);%0A
-            
+%09%09%09
 retu

make whitespace consistent in MapperFactory