aspose file tools*
The moose likes Beginning Java and the fly likes help with reflection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "help with reflection" Watch "help with reflection" New topic
Author

help with reflection

Marco Vanoli
Ranch Hand

Joined: Jan 12, 2005
Posts: 99
Hi,
I have a javabean;
in my program i have to analyze the bean , then put in a list all properties name (String) that have a set method and also a get method. (some properties could have only get or set method).

What can i use to do this work..??

I thinked to use the java.lang.reflect showMethods(bean) but i have to parse all stings and make checks for get and set.. it is cumbersome.

Isn' t there a quickest pratice to do this?
tnk


bye, <br />Marco
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24184
    
  34

The java.beans.Introspector class does exactly what you need. It provides all the information in a nicely structured way.


[Jess in Action][AskingGoodQuestions]
Marco Vanoli
Ranch Hand

Joined: Jan 12, 2005
Posts: 99
Yes think this is the right way but no example ho to use it

can somebody gimme an example of how to use Introspector on a bean to show its properies?

tnk
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

Use Introspector's getBeanInfo() method and provide the class that has your bean properties as an argument. This method returns a BeanInfo object which will then return a list of properties from the class.

The challenge to you is to try it; post your code here for review if you like. More than happy to help you with code that isn't quite doing what you want.


Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
Marco Vanoli
Ranch Hand

Joined: Jan 12, 2005
Posts: 99
Nice , i do it


Is it ok? It seems to work ..

Thank you very much!
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292



Nicely done; nothing to it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: help with reflection