File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes help with reflection Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply 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: 24057
    
  13

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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: help with reflection
 
Similar Threads
bean method question
how to reset form bean properties
How to access method of another Bean
java bean in JSP ?
Show a progress page using Struts