org.openbp.server.ProcessServerFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of openbp-server Show documentation
Show all versions of openbp-server Show documentation
The OpenBP process engine (main module)
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openbp.server;
import org.openbp.common.logger.LogUtil;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* Factory class that creates a process server.
*
* @author Heiko Erhardt
*/
public class ProcessServerFactory
{
/**
* Default constructor.
*/
public ProcessServerFactory()
{
}
/**
* Creates a process server using the standard configuration.
* Uses the standard Spring configuration file "OpenBP.spring.xml".
*
* @return The new process server instance
*/
public ProcessServer createProcessServer()
{
return createProcessServer("OpenBP.spring.xml");
}
/**
* Creates a process server using the provided configuration.
*
* @param springConfigFileName Name of the OpenBP spring configuration file
* @return The new process server instance
*/
public ProcessServer createProcessServer(String springConfigFileName)
{
LogUtil.info(getClass(), "Loading Spring framework resource: " + springConfigFileName);
AbstractApplicationContext springContext = new ClassPathXmlApplicationContext(springConfigFileName);
return createProcessServer(springContext);
}
/**
* Creates a process server from a class annotated with Spring's Configuration annotation.
*
* @param configClass Class of the spring configuration class that provides beans using the @Bean annotation
* @return The new process server instance
*/
public ProcessServer createProcessServerFromConfigurationClass(Class configClass)
{
return createProcessServerFromConfigurationClasses(new Class[] { configClass });
}
/**
* Creates a process server from a set of classes annotated with Spring's Configuration annotation.
*
* @param configClasses Set of classes of the spring configuration class that provides beans using the @Bean annotation
* @return The new process server instance
*/
public ProcessServer createProcessServerFromConfigurationClasses(Class[] configClasses)
{
if (LogUtil.isInfoEnabled(getClass()))
{
String logMsg = "Loading Spring framework configurations: ";
for (int i = 0; i < configClasses.length; ++i)
{
if (i > 0)
logMsg += ", ";
logMsg += configClasses[i].getSimpleName();
}
LogUtil.info(getClass(), logMsg);
}
AnnotationConfigApplicationContext springContext = new AnnotationConfigApplicationContext();
springContext.scan("org.openbp.server");
for (int i = 0; i < configClasses.length; ++i)
{
springContext.register(configClasses[i]);
}
springContext.refresh();
return createProcessServer(springContext);
}
/**
* Creates a process server using the provided configuration.
*
* @param springContext Spring bean factory (e. g. a Spring ApplicationContext)
* @return The new process server
*/
public ProcessServer createProcessServer(final BeanFactory springContext)
{
return (ProcessServer) springContext.getBean(ProcessServer.class);
}
}