This is the mail archive of the kawa@sourceware.cygnus.com mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Dynamic classes



I suspect someone here knows the answer to this question...

I've written some Java database classes. A bit like an object database
they can directly populate the attributes of a class via reflection. I
have also written a class generator, that uses a database schema to
generate a Java class with attributes corresponding to the attributes of
the table. People can then extend that class with methods etc.

What I'd like to be able to do is generate that class at run-time if it
doesn't exist already. This probably involves generating byte codes or
something, that I'm sure Kawa hackers are familiar with.

An interface that looks something like this would be ideal...

Class[] attrs = new Class[3];
String[] names = new String[3];
attrs[0] = Class.forName("java.lang.Integer");
names[0] = "attr1";
attrs[1] = Class.forName("java.lang.String");
names[0] = "attr2";
attrs[2] = Class.forName("java.lang.Boolean");
names[2] = "attr3";
Class foo = ClassGenerator.make(names, attrs);


Which would be the equivilent of writing an anonymous class...

public class {
   public Integer attr1;
   public String attr2;
   public Boolean attr3;
}

Also, is it just me, or can only public attributes be modified via
reflection?

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]