001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.commons.betwixt.strategy;
018
019 import java.beans.Introspector;
020
021 /**
022 * <p>A name mapper which converts types to a decapitalized String.</p>
023 *
024 * <p>This conversion decapitalizes in the standard java beans way
025 * (as per <code>java.beans.Introspector</code>).
026 * This means that the first letter only will be decapitalized except
027 * for the case where the first and second characters are both upper case.
028 * When both are upper case, then the name will be left alown.</p>
029 *
030 * <p>So a bean type of <code>Foo</code> will be converted to the element name <code>"foo"</code.
031 * <code>FooBar</code> will be converted to <code>"fooBar"</code>.
032 * But <code>URL</code> will remain as <code>"URL"</code>.</p>
033 *
034 * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
035 * @version $Revision: 471234 $
036 */
037 public class DecapitalizeNameMapper implements NameMapper {
038
039 /**
040 * Decapitalize first letter unless both are upper case.
041 * (As per standard java beans behaviour.)
042 *
043 * @param typeName the string to convert
044 * @return decapitalized name as per <code>java.beans.Introspector</code>
045 */
046 public String mapTypeToElementName(String typeName) {
047 return Introspector.decapitalize( typeName );
048 }
049
050 /**
051 * Outputs a brief description.
052 * @since 0.8
053 */
054 public String toString() {
055 return "Decapitalize Type Name Mapper";
056 }
057 }