Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Java bean

 
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.
 
Bartender
Posts: 11445
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • 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.
 
Sheriff
Posts: 21972
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu 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().
 
Marshal
Posts: 69805
277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds as if you could use reflection and getMethods() or similar.
 
There's a city wid manhunt for this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic