com.talk2object.plum.interaction.application.Plum Maven / Gradle / Ivy
package com.talk2object.plum.interaction.application;
import org.apache.log4j.Logger;
import com.talk2object.common.ApplicationContextUtils;
import com.talk2object.plum.interaction.session.SessionContext;
import com.talk2object.plum.interaction.session.SessionManager;
import com.talk2object.plum.interaction.session.SessionManagerImpl;
import com.talk2object.plum.interaction.viewgeneneration.ViewFactory;
import com.talk2object.plum.interaction.viewgeneneration.ViewFactoryImpl;
import com.talk2object.plum.repository.biz.TransactionExecutor;
import com.talk2object.plum.repository.biz.interafce.Repository;
import com.talk2object.plum.repository.context.RepositoryContextUtils;
/**
* top object of PLUM framework
*
* @author jack
*
*/
public class Plum {
private final Logger logger = Logger.getLogger(Plum.class);
private String basePackage;
private String defaultModelClassName;
private TransactionExecutor transactionExecutor;
private ViewFactory viewFactory;
private Repository repository;
private SessionManager sessionManager;
@Deprecated
private void initFromApplicationContext() {
transactionExecutor = ApplicationContextUtils.getTransactionExecutor();
viewFactory = PlumApplicationContextUtils.getViewFactory();
repository = RepositoryContextUtils.getRepository();
sessionManager = PlumApplicationContextUtils.getSessionManager();
}
public void init() {
ViewFactoryImpl vf = new ViewFactoryImpl();
vf.setBasePackage(basePackage);
viewFactory = vf;
SessionManagerImpl sm = new SessionManagerImpl();
sm.setDefaultModelClassName(defaultModelClassName);
sessionManager = sm;
refreshContexts();
}
/**
* refresh all kinds of Contexts.
*/
private void refreshContexts() {
ApplicationContextUtils.setTransactionExecutor(transactionExecutor);
PlumApplicationContextUtils.setViewFactory(viewFactory);
RepositoryContextUtils.setRepository(repository);
PlumApplicationContextUtils.setSessionManager(sessionManager);
PlumApplicationContextUtils.setPlum(this);
}
public void start() {
viewFactory.scanDomainObjects();
}
public void stop() {
logger.info(String.format("try to stop %d UI threads", sessionManager
.getSessionContextList().size()));
for (SessionContext sessionCtx : sessionManager.getSessionContextList()) {
sessionCtx.getView().getEventThread().stopThread();
}
logger.info("PLUM stopped");
}
public TransactionExecutor getTransactionExecutor() {
return transactionExecutor;
}
public void setTransactionExecutor(TransactionExecutor transactionExecutor) {
this.transactionExecutor = transactionExecutor;
}
public Repository getRepository() {
return repository;
}
public void setRepository(Repository repository) {
this.repository = repository;
}
public String getBasePackage() {
return basePackage;
}
public void setBasePackage(String basePackage) {
this.basePackage = basePackage;
}
public String getDefaultModelClassName() {
return defaultModelClassName;
}
public void setDefaultModelClassName(String defaultModelClassName) {
this.defaultModelClassName = defaultModelClassName;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy