Converter.java
上传用户:zhengdagz
上传日期:2014-03-06
资源大小:1956k
文件大小:3k
源码类别:

xml/soap/webservice

开发平台:

Java

  1. /*
  2.  * $Id: Converter.java,v 1.2 2005/10/10 17:01:08 rbair Exp $
  3.  *
  4.  * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
  5.  * Santa Clara, California 95054, U.S.A. All rights reserved.
  6.  *
  7.  * This library is free software; you can redistribute it and/or
  8.  * modify it under the terms of the GNU Lesser General Public
  9.  * License as published by the Free Software Foundation; either
  10.  * version 2.1 of the License, or (at your option) any later version.
  11.  * 
  12.  * This library is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.  * Lesser General Public License for more details.
  16.  * 
  17.  * You should have received a copy of the GNU Lesser General Public
  18.  * License along with this library; if not, write to the Free Software
  19.  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  20.  */
  21. package org.jdesktop.binding.metadata;
  22. /**
  23.  * Interface for defining objects which perform bi-directional conversion
  24.  * between string values and Java objects.  A unified conversion interface
  25.  * is required for serializing and de-serializing data values to and from
  26.  * a textual representation, which is a common requirement when interacting
  27.  * with a network or web-based data source.
  28.  * <p>
  29.  * For many Java classes (Date, Color, etc), an instance may be
  30.  * represented in a variety of string formats, hence both conversion methods
  31.  * take an optional <code>format</code> parameter for specifying an
  32.  * unambiguous string format to use during conversion.  A Converter class
  33.  * must document the format classes it supports and must also accept a
  34.  * <code>null</code> value for the <code>format</code> parameter,
  35.  * in which case a suitable and well-documented default should be used.
  36.  * Converters should support standard formats whenever possible.</p>
  37.  *
  38.  * @see Converters#get
  39.  *
  40.  * @author Amy Fowler
  41.  * @version 1.0
  42.  */
  43. public interface Converter {
  44.     /**@todo aim: should converters honor null/"" values? */
  45.     /**
  46.      * Converts the specified Object value to a string representation.
  47.      * The value must be an instance of the class associated with
  48.      * this converter, else an exception will be thrown.
  49.      * @param value the object to be converted
  50.      * @param format object containing string format information, or null
  51.      *        if format information is either not relevant or unspecified
  52.      * @return String containing the converted string representation of the
  53.      *         value
  54.      * @throws ConversionException if the conversion could not be performed
  55.      */
  56.     String encode(Object value, Object format) throws ConversionException;
  57.     /**
  58.      * Converts the specified String value to an object that is an
  59.      * instance of the class associated with this converter instance.
  60.      * @param value String object to be converted
  61.      * @param format object containing string format information, or null
  62.      *        if format information is either not relevant or unspecified
  63.      * @return Object which contains the converted value as an instance of
  64.      *         the class associated with this converter
  65.      * @throws ConversionException if the conversion could not be performed
  66.      */
  67.     Object decode(String value, Object format) throws ConversionException;
  68. }