KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > betwixt > strategy > DecapitalizeNameMapper


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
18 import java.beans.Introspector JavaDoc;
19
20 /**
21  * <p>A name mapper which converts types to a decapitalized String.</p>
22  *
23  * <p>This conversion decapitalizes in the standard java beans way
24  * (as per <code>java.beans.Introspector</code>).
25  * This means that the first letter only will be decapitalized except
26  * for the case where the first and second characters are both upper case.
27  * When both are upper case, then the name will be left alown.</p>
28  *
29  * <p>So a bean type of <code>Foo</code> will be converted to the element name <code>"foo"</code.
30  * <code>FooBar</code> will be converted to <code>"fooBar"</code>.
31  * But <code>URL</code> will remain as <code>"URL"</code>.</p>
32  *
33  * @author <a HREF="mailto:jstrachan@apache.org">James Strachan</a>
34  * @version $Revision: 1.6 $
35  */

36 public class DecapitalizeNameMapper implements NameMapper {
37
38     /**
39      * Decapitalize first letter unless both are upper case.
40      * (As per standard java beans behaviour.)
41      *
42      * @param typeName the string to convert
43      * @return decapitalized name as per <code>java.beans.Introspector</code>
44      */

45     public String JavaDoc mapTypeToElementName(String JavaDoc typeName) {
46         return Introspector.decapitalize( typeName );
47     }
48 }
49
Popular Tags