1. /*
  2. * Copyright 2001-2004 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.apache.commons.betwixt.strategy;
  17. import java.beans.Introspector;
  18. /**
  19. * <p>A name mapper which converts types to a decapitalized String.</p>
  20. *
  21. * <p>This conversion decapitalizes in the standard java beans way
  22. * (as per <code>java.beans.Introspector</code>).
  23. * This means that the first letter only will be decapitalized except
  24. * for the case where the first and second characters are both upper case.
  25. * When both are upper case, then the name will be left alown.</p>
  26. *
  27. * <p>So a bean type of <code>Foo</code> will be converted to the element name <code>"foo"</code.
  28. * <code>FooBar</code> will be converted to <code>"fooBar"</code>.
  29. * But <code>URL</code> will remain as <code>"URL"</code>.</p>
  30. *
  31. * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  32. * @version $Revision: 1.6 $
  33. */
  34. public class DecapitalizeNameMapper implements NameMapper {
  35. /**
  36. * Decapitalize first letter unless both are upper case.
  37. * (As per standard java beans behaviour.)
  38. *
  39. * @param typeName the string to convert
  40. * @return decapitalized name as per <code>java.beans.Introspector</code>
  41. */
  42. public String mapTypeToElementName(String typeName) {
  43. return Introspector.decapitalize( typeName );
  44. }
  45. }