1 /* 2 * Copyright 2002-2006 the original author or authors. 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.springframework.binding.format; 17 18 /** 19 * A lightweight interface for formatting a value and parsing a value from its 20 * formatted form. 21 * @author Keith Donald 22 */ 23 public interface Formatter { 24 25 /** 26 * Format the value. 27 * @param value the value to format 28 * @return The formatted string, fit for display in a UI 29 * @throws IllegalArgumentException The value could not be formatted. 30 */ 31 public String formatValue(Object value) throws IllegalArgumentException; 32 33 /** 34 * Parse the formatted string representation of a value, restoring the 35 * value. 36 * @param formattedString The formatted string representation 37 * @param targetClass the target class to convert the formatted value to 38 * @return The parsed value 39 * @throws InvalidFormatException The string was in an invalid form 40 */ 41 public Object parseValue(String formattedString, Class targetClass) throws InvalidFormatException; 42 43 }