That would help some people who do not know much about JavaBeans but want to turn their classes into beans.
All you need to do is to analyze a class and find out public fields, public accessor methods for them, and event information, all of which can be found using classes in java.lang.reflect package.
It would be nice if your application allow a user to create an icon and JavaHelp file for the bean as well.
IMHO
masa
Thanks for the reply...
You mentioned that I needed to analyse the class to find out information regarding the methods, events etc...
Any hints regarding how I would go about analysing the class?
And once analysed how I could automate the addition to the class of bean "required" code, thus turning the class into a bean?
Thanks very much for any help
Kapil
Hi,
Some of information I posted in my previous reply were incorrect. In order to find properties, their accessors and events, you don't need java.lang.reflect package. (All you need is a BeanInfor class for an object.) Also, it seems that I didn't understand what you are trying to do.
Are you trying to create a BeanInfo class from a java source code?
If so, you probably have to parse the .java file and find all public field and methods (including accessors and event related methods), and construct XXXBeanInfo.java file.
If you are trying to create a BeanInfo class from a .class file, you can find properties, methods from its BeanInfo class, then create a source code for the BeanInfo class. (Sounds odd? - get a BeanInfo class in order to create a BeanInfo class.)
If creating a BeanInfo class is your objective, above two will do, but you might want to think why you want to do that because Java will create a default BeanInfo class if a class does not have one.
If you are trying to amend a .java file so that it satisfy the requirement of JavaBeans specification, that's a different story...
Masa
Firstly thanks for the replies, much appreciated:
My aim is to have 3 Very Basic UML template class diagrams (represented in text files as Java). My Swing text editor then opens one of these and upon clicking a button the text files are ammended with the extra "JavaBean" code being added to the file.
So the main function is to convert existing Java code into JBean code by adding the extra "Bean" requirements to the existing Java code (i.e get and set methods).
I am attempting to this at a Very basic level at first. So just adding 1 line to the existing Java file would be sufficient.
Thanks again for any direction/help
Kapil
> Hi,
>
> Some of information I posted in my previous reply were
> incorrect. In order to find properties, their
> accessors and events, you don't need java.lang.reflect
> package. (All you need is a BeanInfor class for an
> object.) Also, it seems that I didn't understand what
> you are trying to do.
>
> Are you trying to create a BeanInfo class from a java
> source code?
>
> If so, you probably have to parse the .java file and
> find all public field and methods (including accessors
> and event related methods), and construct
> XXXBeanInfo.java file.
>
> If you are trying to create a BeanInfo class from a
> .class file, you can find properties, methods from its
> BeanInfo class, then create a source code for the
> BeanInfo class. (Sounds odd? - get a BeanInfo class
> in order to create a BeanInfo class.)
>
> If creating a BeanInfo class is your objective, above
> two will do, but you might want to think why you want
> to do that because Java will create a default BeanInfo
> class if a class does not have one.
>
> If you are trying to amend a .java file so that it
> satisfy the requirement of JavaBeans specification,
> that's a different story...
>
> Masa
>
>
> Firstly thanks for the replies, much appreciated:
>
> My aim is to have 3 Very Basic UML template class
> diagrams (represented in text files as Java). My Swing
> text editor then opens one of these and upon clicking
> a button the text files are ammended with the extra
> "JavaBean" code being added to the file.
>
> So the main function is to convert existing Java code
> into JBean code by adding the extra "Bean"
> requirements to the existing Java code (i.e get and
> set methods).
>
> I am attempting to this at a Very basic level at
> first. So just adding 1 line to the existing Java
> file would be sufficient.
>
Well, then, you probably have to parse a .java file and analyze the code. Then, add necessary code to it (such as "null-constructor", get/set methods).
Masa