I did call defineClass, but don't know if I am using an appropriate
Classloader.
I am working from an article that was in the February 2002 issue Java
Developer's Journal by Norman Richards.


here is a portion of my UIGenerator class:

public class MYNEWComboBoxUIGenerator extends ClassLoader implements
Constants {
  private InstructionFactory _factory;
  private ConstantPoolGen   _cp;
  private ClassGen          _cg;

  public ComponentUI generate(UIManager.LookAndFeelInfo lf, JComponent comp)
{
      new GuardianComboBoxUI$GuardianComboPopupGenerator().generate(lf,
comp);
      new GuardianComboBoxUI$PropertyChangeHandler2Generator().generate(lf,
comp);
      String lfName =
lf.getClassName().substring(lf.getClassName().lastIndexOf(".") + 1,
lf.getClassName().length() - 11);
      String lfPackage = lf.getClassName().substring(0,
lf.getClassName().lastIndexOf("."));
      String className = "combo_research.Guardian" + lfName + "ComboBoxUI";
      String superClassName = lfPackage + "." + lfName + "ComboBoxUI";
//need to get rid of last node in classname
    _cg = new ClassGen(className, superClassName, "", ACC_PUBLIC |
ACC_SUPER, new String[] {  });
    _cg.addEmptyConstructor(ACC_PUBLIC);
    _cp = _cg.getConstantPool();
       _factory = new InstructionFactory(_cg, _cp);
//    createMethod_0();
    createMethod_1(className);
    createMethod_2(className);
    createMethod_3(className);
    createMethod_4(className);
    createMethod_5(className);
    createMethod_6(className);
    byte[] data = _cg.getJavaClass().getBytes();
    Class c = defineClass(data, 0, data.length);



----- Original Message -----
From: <[EMAIL PROTECTED]>
To: "BCEL Users List" <[EMAIL PROTECTED]>
Sent: Monday, November 25, 2002 1:58 PM
Subject: Re: making classes available


> Hi Chris,
>
> Once you have the bytecode for the class, you can use
ClassLoader.defineClass to
> make it available to the JVM. Make sure you're using an appropriate
ClassLoader.
>
> God bless,
> -Toby Reyelts
>
> > What I need is an example of generating a class at runtime and just
making it
> > available to be accessed at any future point instead of returning an
instance of
> > it immediately.
>
> --
> To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>
>


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to