Nossa interface mais alta na hierarquia é:
[code]package br.com.ampix.basic.interfaces;
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface ApxServicoRMIInterface<S extends ApxSession, R extends ApxSession>
extends Remote, ApxServicoInterface {
S openSession() throws RemoteException;
R openSessionReport() throws RemoteException;
}
[/code]
Interface abaixo desta:
[code]package br.com.ampix.basic.directorsystemcontabil.service.interfaces;
import java.rmi.RemoteException;
import br.com.ampix.basic.directorsystemcontabilreport.bolseiro.interfaces.ApxDSCBolseiroInterface;
import br.com.ampix.basic.directorsystemcontabilreport.bolseiro.interfaces.ApxDSCReportBolseiroInterface;
import br.com.ampix.basic.interfaces.ApxBolseiroInterface;
import br.com.ampix.basic.interfaces.ApxServicoRMIInterface;
import br.com.ampix.basic.interfaces.ApxSession;
import br.com.ampix.util.exception.ApxException;
public interface ApxDSCServiceInterface<S extends ApxSession, R extends ApxSession, B extends ApxBolseiroInterface> extends
ApxServicoRMIInterface<S, R> {
Object executeListagem(ApxDSCBolseiroInterface bolseiro) throws RemoteException, ApxException;
Object executeProcessamento(ApxDSCBolseiroInterface bolseiro) throws RemoteException, ApxException;
Object executeInclusao(ApxDSCBolseiroInterface bolseiro) throws RemoteException, ApxException;
Object executeConsulta(ApxDSCBolseiroInterface bolseiro) throws RemoteException, ApxException;
Object executeUpdate(ApxDSCBolseiroInterface bolseiro) throws RemoteException, ApxException;
boolean executeRemove(ApxDSCBolseiroInterface bolseiro) throws RemoteException, ApxException;
ApxDSCReportBolseiroInterface buildReport(ApxDSCReportBolseiroInterface bolseiro) throws RemoteException;
Object executeQuery(B bolseiro) throws RemoteException;
}
[/code]
Classe Abstrata que implementa esta interface:
[code]package br.com.ampix.basic.directorsystemcontabil.service;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.HashMap;
import br.com.ampix.basic.directorsystemcontabil.factories.interfaces.ApxDSCFactoryDaoInterface;
import br.com.ampix.basic.directorsystemcontabil.factories.interfaces.ApxDSCFactoryRuleInterface;
import br.com.ampix.basic.directorsystemcontabil.service.interfaces.ApxDSCServiceInterface;
import br.com.ampix.basic.directorsystemcontabilreport.factories.interfaces.ApxDSCReportFactoryDaoInterface;
import br.com.ampix.basic.directorsystemcontabilreport.factories.interfaces.ApxDSCReportFactoryRuleInterface;
import br.com.ampix.basic.interfaces.ApxBolseiroInterface;
import br.com.ampix.basic.interfaces.ApxSession;
import br.com.ampix.basic.interfaces.factories.FactoryInterface;
import br.com.ampix.util.exception.ApxException;
public abstract class AbstractApxDSCService<S extends ApxSession, R extends ApxSession, B extends ApxBolseiroInterface> extends
UnicastRemoteObject implements ApxDSCServiceInterface<S, R, B> {
protected static HashMap<String, FactoryInterface> factories = new HashMap();
static {
try {
factories.put(ApxDSCFactoryRuleInterface.RULE_NAME, (FactoryInterface) Class.forName(
"br.com.ampix.directorsystemcontabil.server.factories.DefaultFactoryRule").newInstance());
factories.put(ApxDSCFactoryDaoInterface.DAO_NAME, (FactoryInterface) Class.forName(
"br.com.ampix.directorsystemcontabil.server.factories.DefaultFactoryDao").newInstance());
factories.put(ApxDSCReportFactoryDaoInterface.DAO_NAME, (FactoryInterface) Class.forName(
"br.com.ampix.directorsystemcontabilreport.server.factories.DefaultFactoryDaoReport").newInstance());
factories.put(ApxDSCReportFactoryRuleInterface.RULE_NAME, (FactoryInterface) Class.forName(
"br.com.ampix.directorsystemcontabilreport.server.factories.DefaultFactoryRuleReport").newInstance());
}
catch (Exception e) {
e.printStackTrace();
}
}
public static FactoryInterface getFactory(String key) {
return factories.get(key);
}
public AbstractApxDSCService() throws RemoteException {
super();
}
}
[/code]
E finalmente, a classe concreta, que realmente chega no cliente como servico de rmi, que foi feito o rebind:
package br.com.ampix.directorsystemcontabil.server.service;
import java.rmi.RemoteException;
import br.com.ampix.basic.directorsystemcontabil.server.DefaultApxReportSession;
import br.com.ampix.basic.directorsystemcontabil.server.DefaultApxSession;
import br.com.ampix.basic.directorsystemcontabil.service.AbstractApxDSCService;
import br.com.ampix.basic.directorsystemcontabilreport.bolseiro.interfaces.ApxDSCBolseiroInterface;
import br.com.ampix.basic.directorsystemcontabilreport.bolseiro.interfaces.ApxDSCReportBolseiroInterface;
import br.com.ampix.basic.interfaces.ApxBolseiroInterface;
import br.com.ampix.interfaces.ctb.RazaoReportInterface;
import br.com.ampix.objetos.ctb.report.RazaoReport;
import br.com.ampix.objetos.ctb.report.cfg.ApxReportCompiler;
import br.com.ampix.pesquisa.interfaces.ApxBolseiroPesquisa;
import br.com.ampix.util.exception.ApxException;
public class DefaultApxDSCService extends AbstractApxDSCService<DefaultApxSession, DefaultApxReportSession, ApxBolseiroPesquisa> {
private static final long serialVersionUID = 1628317873417746216L;
private static ApxDSCHibernateController hibernateController;
public DefaultApxDSCService() throws RemoteException {
super();
}
private Object executeRegra(ApxDSCBolseiroInterface bolseiro) throws RemoteException, ApxException {
return openSession().execute(bolseiro);
}
public Object executeListagem(ApxDSCBolseiroInterface bolseiro) throws RemoteException, ApxException {
return openSession().executeListagem(bolseiro);
}
public Object executeProcessamento(ApxDSCBolseiroInterface bolseiro) throws RemoteException, ApxException {
return executeRegra(bolseiro);
}
public Object executeInclusao(ApxDSCBolseiroInterface bolseiro) throws RemoteException, ApxException {
return openSession().executeInclusao(bolseiro);
}
public Object executeConsulta(ApxDSCBolseiroInterface bolseiro) throws RemoteException, ApxException {
return openSession().executeConsulta(bolseiro);
}
public Object executeUpdate(ApxDSCBolseiroInterface bolseiro) throws RemoteException, ApxException {
return openSession().executeUpdate(bolseiro);
}
public boolean executeRemove(ApxDSCBolseiroInterface bolseiro) throws RemoteException, ApxException {
return openSession().executeRemove(bolseiro);
}
public synchronized static ApxDSCHibernateController getHibernateController() {
return hibernateController;
}
public synchronized static void setHibernateController(ApxDSCHibernateController controller) {
hibernateController = controller;
}
public DefaultApxSession openSession() {
return new DefaultApxSession(hibernateController.openSession());
}
public ApxDSCReportBolseiroInterface buildReport(ApxDSCReportBolseiroInterface bolseiro) throws RemoteException {
ApxDSCReportBolseiroInterface report = openSessionReport().buildReport(bolseiro);
System.gc();
return report;
}
public DefaultApxReportSession openSessionReport() throws RemoteException {
return new DefaultApxReportSession(openSession());
}
public Object executeQuery(ApxBolseiroPesquisa bolseiro) throws ApxException {
return openSession().executeQuery(bolseiro);
}
}
Parece um pouco complexo, mas não é tanto não, fizemos assim para reutilizarmos em mais aplicações cliente/servidor utilizando o RMI.
Agradeço a cooperação.