views:

544

answers:

3

The Spring Framework API doc says:

The convention used is to return the uncapitalized short name of the Class, according to JavaBeans property naming rules: So, com.myapp.Product becomes product; com.myapp.MyProduct becomes myProduct; com.myapp.UKProduct becomes UKProduct.

I looked at Suns website to find a definition, but didn't find one. I wonder about a rule for names with more than one upper case character at the beginning. Is the rule that the first character is upper case if the second character is upper case too?

The background is, that I want to generate variable names automatically for use in HTML templates depending on the type of the object. Example: class: SomeName --> object: someName.

+4  A: 

http://java.sun.com/javase/technologies/desktop/javabeans/docs/spec.html

Also, a direct link to the (PDF) specification .

Section 8.8 in the linked document is entitled "Capitalization of inferred names" and briefly outlines how names of properties are derived.

Carl Smotricz
Thanks! As I've guessed it is relevant wheter the second letter is upper case or not. Sun: "However to support the occasional use of all upper-case names, we check if the first two characters of the name are both upper case and if so leave it alone."There is a method to convert a String to a name that follows this convention: java.beans.Introspector#decapitalize(String name)
deamon
Wow, that's a lot of detail I didn't know before. Thanks!
Carl Smotricz
+1  A: 

You can look into JavaBean specs., I guess.

Adeel Ansari
+1  A: 

the implementation of this functionality is in this class: http://java.sun.com/javase/6/docs/api/java/beans/Introspector.html

eqbridges