[forge-dev] ejb plugin: work with generics and abstract classes

JFlower fiorenzino at gmail.com
Sat Sep 15 09:34:24 EDT 2012


Hi,

in forge is possibile to specify a superType class with generics? How to do
this?

My use case is as follows: i have an entity bean, a repository session bean
and an abstract class to extend.

1) An abstract repository with all persistence management functionality:
*public abstract class AbstractRepository<T> implements Serializable {*
public T find(Object key) {
try {
return getEm().find(getEntityType(), key);
} catch (Exception e) {return null; }
}
}

2) an entity class like:
*@Entity*
*public class SImpleEntity implements Serializable {*
private String name;
public String getName() {return name;}
public void setName(String name) {this.name = name;}
}


3) i want to create a specific *SImpleEntityRepository* like:
@Stateless
@LocalBean
*public class SImpleEntityRepository extends BaseRepository<SImpleEntity> {}
*


In ejb plugin i need to do this, to create a "add-extends" command (also
for "add-implements").
My initial reasoning is this:
- read with reflection the super class, to understand if this class use
generics.
             - If the super class is like *public abstract
class AbstractRepository<T>{}:*
                  i need to modify my current class (an ejb) specifying:
                           - or the generic class
                           - or asking to the user what's the real class to
use.
*
*
But in forge, I can't do this:

                JavaClass javaClass = JavaParser.create(JavaClass.class);
javaClass.setName("FlowerTest");
javaClass.setPackage("it.coopservice.test");
javaClass.addImport("org.jboss.forge.spec.ejb.testClasses.BaseEntity");
javaClass.addImport("org.jboss.forge.spec.ejb.testClasses.BaseRepositoryMultiVar");
*javaClass.setSuperType("BaseRepositoryMultiVar<BaseEntity>"); *


Some trick for this?

Fiorenzo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/forge-dev/attachments/20120915/00e2a2a9/attachment-0001.html 


More information about the forge-dev mailing list