View Javadoc
1 /* 2 * Scope: a generic MVC framework. 3 * Copyright (c) 2000-2002, The Scope team 4 * All rights reserved. 5 * 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 11 * Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 14 * Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 18 * Neither the name "Scope" nor the names of its contributors 19 * may be used to endorse or promote products derived from this software 20 * without specific prior written permission. 21 * 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR 27 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 * 35 * 36 * $Id: StringStringConvertor.java,v 1.3 2002/09/05 15:41:47 ludovicc Exp $ 37 */ 38 package org.scopemvc.util.convertor; 39 40 41 /*** 42 * String convertor for type {@link java.lang.String java.lang.String}. The main 43 * sense of the class is to correctly handle <code>null</code> value. Useful 44 * results can be obtained if <code>null</code> representation is set for 45 * example to <code>"(null)"</code> or <code>"N/A"</code> - this strings are 46 * then parsed into <code>null</code> value. 47 * 48 * @author <A HREF="mailto:danmi@users.sourceforge.net">Daniel Michalik</A> 49 * @created 05 September 2002 50 * @version $Revision: 1.3 $ $Date: 2002/09/05 15:41:47 $ 51 */ 52 public final class StringStringConvertor extends NullStringConvertor { 53 54 /*** 55 * Converts String to String. <p<i> 56 * 57 * Handling of <code>null</code> value:</i> it is converted into {@link 58 * #getNullAsString() getNullAsString()} which is default empty String. <p> 59 * 60 * 61 * 62 * @param inValue TODO: Describe the Parameter 63 * @return TODO: Describe the Return Value 64 * @throws IllegalArgumentException if passed value is not instance of 65 * String 66 */ 67 public String valueAsString(Object inValue) throws IllegalArgumentException { 68 if (inValue == null) { 69 return getNullAsString(); 70 } 71 if (!(inValue instanceof String)) { 72 throw new IllegalArgumentException("StringStringConvertor only " 73 + "operates on String, not on: " + inValue.getClass()); 74 } 75 return (String) inValue; 76 } 77 78 79 /*** 80 * Parses String to String. If passed String is non-null and non-empty, the 81 * same instance is returned. <p<i> 82 * 83 * Handling of <code>null</code> value</i> is based on the following 84 * sequence of conditions: 85 * <ol> 86 * <li> for empty input string also empty String is returned.</li> 87 * <li> for input equal to value of {@link #getNullAsString() 88 * getNullAsString()} <code>null</code> is returned.</li> 89 * </ol> 90 * <p> 91 * 92 * 93 * 94 * @param inString TODO: Describe the Parameter 95 * @return passed input string or <code>null</code>. 96 * @throws IllegalArgumentException if passed value is not instance of 97 * String 98 */ 99 public Object stringAsValue(String inString) throws IllegalArgumentException { 100 if (isNull(inString)) { 101 return null; 102 } 103 return inString; 104 } 105 }

This page was automatically generated by Maven