Java - 返回一个抽象类

时间:2013-10-25 14:06:04

标签: java jsf-2

我正在jsf

中开发一个Web应用程序

我有这些课程

摘要:

  • RepositoryBase
  • ManagedBeanCRUD
  • EntityBase

类:

  • 客户端扩展了EntityBase
  • ClientRepository扩展了RepositoryBase
  • ClientManagedBean扩展了ManagedBeanCRUD

但是我在ManagedBeanCRUD上实现保存方法时遇到问题

在这个方法中我需要一个Repository,所以我有一个RepositoryBase rep = repositoryfactory.getFactory((entity.getClass()));

我试图以多种方式实现repositoryFactory,但仍然没有成功。

任何人都知道我怎么能这样做???

提前谢谢

public class  ManagedBeanCRUD < T extends EntityBase> () {
   protected T newEntity;

   public void save() {      
    Repositoryfactory factory =  new Repositoryfactory();
    RepositoryBase<T> rep = factory.getFactory((entity.getClass()));
    rep.persiste(newEntity);
  }
}


public class FactoryRepository < T extends EntityBase> () {

public RepositoryBase<T> getFactory(Class newEntity) {
    if(newEntity == Client.class) {
         return new ClientRepository();
    } else {
        System.out.println("error");
    }
}
}

public class ClientManagedBean extends CRUDBean<Client> {

private static final long serialVersionUID = 1L;
private Clietn client = new Client();

public void setSalve(){
    this.setNewEntity(this.client);
    this.salvar();
    this.client = new Client();
}

}

公共类ClientRepository扩展了RepositoryBase {

@Override
protected Class<Client> getRuntimeClass() {
    return Client.class;
}

}

0 个答案:

没有答案
相关问题