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