These sources will guide you into using Java Reflection. Please also look at following links:
http://java.sun.com/docs/books/tutorial/reflect/
This is the project layout i used in the examples

Simple object for testing purposes
DataObject.java
/*
*
- To change the template for this generated file go to
- Window>Preferences>Java>Code Generation>Code and Comments
*/
package pl.com.bcc.demoref;
/**
*
- To change the template for this generated type comment go to
- Window>Preferences>Java>Code Generation>Code and Comments
*/
public class DataObject {
public String name = "";
public int age = 0;
public String SecondName = "";
protected String protect = "";
private String privat = "";
}
Servlet for testing the EJB functionality (methods)
RefDemoEjbServlet.java
" + "" + "" + ""); }}
Servlet for testing simple funcionality (fields)
RefDemoServlet.java
" + "");
Class c = o.getClass();
Field fld[] = c.getFields();
for (int i=0; i<fld.length; i++) {
String fname = fld[i].getName();
if (request.getParameter(fname) != null) {
try {
if (fld[i].getType() == int.class) {
fld[i].setInt(o,(new Integer(request.getParameter(fname)).intValue()));
} else {
// assume string
fld[i].set(o, request.getParameter(fname));
}
} catch (Exception e ){
// take care here of missed type
// (eg. '321sd' as a number)
e.printStackTrace(wr);
}
}
try {
wr.print(fld[i].getName() + " : <input type='text' name='"
+ fld[i].getName() + "' value='"fld[i].get(o).toString()"'>"); } catch (Exception e) { ; } } wr.print("" + ""); } }
Following are sources for test EJB.
ReflObjectBean.java
package pl.com.bcc.reflectdemo;
import javax.ejb.EntityBean;
import javax.ejb.EntityContext;
import javax.ejb.RemoveException;
import javax.ejb.CreateException;
/**
- @abstractSchemaName ReflObjectBean
- @ejbLocal <{pl.com.bcc.reflectdemo.ReflObjectLocal}>
- @ejbLocalHome <{pl.com.bcc.reflectdemo.ReflObjectLocalHome}>
- @ejbPrimaryKey <{java.lang.Object}>
*/
public abstract class ReflObjectBean implements EntityBean {
public void ejbLoad() {
}
public void ejbStore() {
}
public void ejbRemove() throws RemoveException {
}
public void ejbActivate() {
}
public void ejbPassivate() {
}
public void setEntityContext(EntityContext context) {
myContext = context;
}
public void unsetEntityContext() {
myContext = null;
}
private EntityContext myContext;
/**
*/
public Object ejbCreate() throws CreateException {
// TODO : Implement
return null;
}
/**
*/
public void ejbPostCreate() {
// TODO : Implement
setAge(0);
setName("newName");
}
public abstract int getAge();
public abstract void setAge(int age);
public abstract String getName();
public abstract void setName(String name);
}
ReflObjectLocal.java
package pl.com.bcc.reflectdemo;
import javax.ejb.EJBLocalObject;
public interface ReflObjectLocal extends EJBLocalObject {
/**
*/
public int getAge();
/**
*/
public void setAge(int age);
/**
*/
public String getName();
/**
*/
public void setName(String name);
}
ReflObjectLocalHome.java
package pl.com.bcc.reflectdemo;
import javax.ejb.EJBLocalHome;
import javax.ejb.FinderException;
import javax.ejb.CreateException;
public interface ReflObjectLocalHome extends EJBLocalHome {
/**
*/
public ReflObjectLocal findByPrimaryKey(Object primKey)
throws FinderException;
/**
*/
public ReflObjectLocal create() throws CreateException;
/**
*/
public ReflObjectLocal findMethod(int arg1) throws FinderException;
}
</textarea>