
package jm14.ant.model;

import jm14.ant.model.db.ArtigosHomeImpl;

public class ServiceLocator {
	
	private static final String PROPRIEDADE_DRIVER = "jm14.ant.nomeDriver";
	private static final String DRIVER_DEFAULT = "hsqldb";
	private static ServiceLocator instancia = new ServiceLocator();
	
	private static ArtigosHome artigosHome = null;
	
	private ServiceLocator() {
	}
	
	public ArtigosHome getArtigosHome() {
		if ( artigosHome == null ) {
			String driver = System.getProperty( PROPRIEDADE_DRIVER );
			if ( driver == null ) {
				System.err.println( "Propriedade " + PROPRIEDADE_DRIVER + " indefinida! " );
				System.err.println( "Usando driver default: " + DRIVER_DEFAULT );
				driver = DRIVER_DEFAULT;
			}
			artigosHome = new ArtigosHomeImpl(  driver + "/driver.properties" );
		}
		return artigosHome;
	}
	
	public static ServiceLocator getInstance() {
		return instancia;
	}

}
