All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jlot.client.config.JlotClient Maven / Gradle / Ivy

There is a newer version: 1.2
Show newest version
package org.jlot.client.config;

import java.beans.Introspector;
import java.util.Properties;

import org.jlot.client.executor.spi.CommandExecutor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.core.env.PropertySource;

public class JlotClient
{
	private AnnotationConfigApplicationContext	applicationContext;
	private boolean								started	= false;

	public void start ( Properties properties )
	{
		applicationContext = new AnnotationConfigApplicationContext();
		addPropertySource(properties);
		applicationContext.register(ClientConfig.class);
		applicationContext.refresh();
		started = true;
	}

	public void stop ( )
	{
		applicationContext.close();
		started = false;
	}

	public boolean isStarted ( )
	{
		return started;
	}

	private void addPropertySource ( Properties properties )
	{
		PropertySource ps = new PropertiesPropertySource("jlot.properties", properties);
		applicationContext.getEnvironment().getPropertySources().addFirst(ps);
	}

	public ApplicationContext getApplicationContext ( )
	{
		return applicationContext;
	}

	public  T getRestCommand ( Class restCommandClass )
	{
		String shortClassName = restCommandClass.getSimpleName();
		String beanName = Introspector.decapitalize(shortClassName);
		return applicationContext.getBean(beanName, restCommandClass);
	}

	public CommandExecutor getCommandExecuter ( Class commandExecutorClass )
	{
		String shortClassName = commandExecutorClass.getSimpleName();
		String beanName = Introspector.decapitalize(shortClassName);
		return applicationContext.getBean(beanName, commandExecutorClass);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy