/*
 * Copyright (c) 2009-2013 Topi Nieminen
 */
package com.appspot.relaxe.env;

import org.apache.log4j.Logger;

import com.appspot.relaxe.DefaultValueAssignerFactory;
import com.appspot.relaxe.DefaultValueExtractorFactory;
import com.appspot.relaxe.ValueAssignerFactory;
import com.appspot.relaxe.ValueExtractorFactory;


/**
 * TODO: This needs to be fixed. DefaultImplementation should not extend a DefaultEnvironment.
 * We should not to require implementation object to be serializable.
 */

public abstract class DefaultImplementation<I extends Implementation<I>>	
	implements Implementation<I> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 399585651114432619L;
	private ValueExtractorFactory valueExtractorFactory; 
	private ValueAssignerFactory valueAssignerFactory;	
//	private Driver driver;
	
//	private AttributeWriterFactory attributeWriterFactory;
	
	private static Logger logger = Logger.getLogger(DefaultImplementation.class);
	
	@Override
	public abstract CatalogFactory catalogFactory();

	@Override
	public ValueExtractorFactory getValueExtractorFactory() {
		if (valueExtractorFactory == null) {			
			valueExtractorFactory = createValueExtractorFactory();			
		}

		return valueExtractorFactory;
	}
	
//	@Override
//	public AttributeWriterFactory getAttributeWriterFactory() {
//		if (attributeWriterFactory == null) {
//			attributeWriterFactory = createAttributeWriterFactory();
//			
//		}
//
//		return attributeWriterFactory;
//	}
//	
//	protected AttributeWriterFactory createAttributeWriterFactory() {
//		return new DefaultAttributeWriterFactory();
//	}

	protected ValueExtractorFactory createValueExtractorFactory() {
		return new DefaultValueExtractorFactory();
	}
	
	@Override
	public ValueAssignerFactory getValueAssignerFactory() {
		if (valueAssignerFactory == null) {
			this.valueAssignerFactory = createValueAssignerFactory();			
		}

		return valueAssignerFactory;
	}

	protected ValueAssignerFactory createValueAssignerFactory() {
		return new DefaultValueAssignerFactory();
	}
	
//	@Override
//	public Driver getDriver() {
//		if (driver == null) {
//			try {
//				this.driver = createDriver();
//			}
//			catch (Exception e) {
//				logger().error(e.getMessage(), e);
//			}
//		}
//		
//		return this.driver;
//	}
	
	private static Logger logger() {
		return DefaultImplementation.logger;
	}
		
//	protected Driver createDriver() throws ClassNotFoundException, InstantiationException, IllegalAccessException {
//		Class<?> c = Class.forName(driverClassName());
//		Driver d = (Driver) c.newInstance();
//		return d;
//	}
	
}

@@ -78,41 +78,8 @@
 v;%0A%0A
-import org.apache.log4j.Logger;%0A%0A
 impo
@@ -121,32 +121,32 @@
 ssignerFactory;%0A
+
 import com.appsp
@@ -287,183 +287,8 @@
 y;%0A%0A
-%0A/**%0A * TODO: This needs to be fixed. DefaultImplementation should not extend a DefaultEnvironment.%0A * We should not to require implementation object to be serializable.%0A */%0A%0A
 publ
@@ -394,90 +394,8 @@
  %7B%0A%0A
-%09/**%0A%09 * %0A%09 */%0A%09private static final long serialVersionUID = 399585651114432619L;%0A
 %09pri
@@ -586,16 +586,18 @@
 tory;%0A%09%0A
+//
 %09private
@@ -1986,16 +1986,18 @@
 %0A//%09%7D%0A%09%0A
+//
 %09private
@@ -2018,24 +2018,26 @@
  logger() %7B%0A
+//
 %09%09return Def
@@ -2063,16 +2063,18 @@
 logger;%0A
+//
 %09%7D%0A%09%09%0A//

clean up