• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java bean  RSS feed

 
Manigandan Velraj
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

Is there any API to validate the structure of a java bean. Given a java file, i should be able to say if it is a valid java bean file (ie. it should have only have getters and setters methods and not other methods.. )

Thanks in advance.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Manigandan Velraj wrote:.. (ie. it should have only have getters and setters methods and not other methods.. )

Somehow this sounds wrong to me, but I could be mistaken.
Consider the following code.
 
Manigandan Velraj
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply,

But i need to check if a file contains only variables , getters , setters.

If a file contains methods (as in your example, getDisplayName) the file should be rejected.

Thanks.
 
Rob Spoor
Sheriff
Posts: 21133
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why should that be rejected? getDisplayName() is a getter too, for a read-only property based on two other properties.

Anyway, if you change the requirement from "Java file" to "Java class" you can use reflection, starting with Class.getMethods().
 
Campbell Ritchie
Marshal
Posts: 56533
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds as if you could use reflection and getMethods() or similar.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!