001/* 002 * Transform.java May 2007 003 * 004 * Copyright (C) 2007, Niall Gallagher <niallg@users.sf.net> 005 * 006 * Licensed under the Apache License, Version 2.0 (the "License"); 007 * you may not use this file except in compliance with the License. 008 * You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 015 * implied. See the License for the specific language governing 016 * permissions and limitations under the License. 017 */ 018 019package org.simpleframework.xml.transform; 020 021/** 022 * A <code>Transform</code> represents a an object used to transform 023 * an object to and from a string value. This is typically used when 024 * either an <code>Attribute</code> or <code>Element</code> annotation 025 * is used to mark the field of a type that does not contain any of 026 * the XML annotations, and so does not represent an XML structure. 027 * For example take the following annotation. 028 * <pre> 029 * 030 * @Text 031 * private Date date; 032 * 033 * </pre> 034 * The above annotation marks an object from the Java class libraries 035 * which does not contain any XML annotations. During serialization 036 * and deserialization of such types a transform is used to process 037 * the object such that it can be written and read to and from XML. 038 * 039 * @author Niall Gallagher 040 */ 041public interface Transform<T> { 042 043 /** 044 * This method is used to convert the string value given to an 045 * appropriate representation. This is used when an object is 046 * being deserialized from the XML document and the value for 047 * the string representation is required. 048 * 049 * @param value this is the string representation of the value 050 * 051 * @return this returns an appropriate instanced to be used 052 */ 053 T read(String value) throws Exception; 054 055 /** 056 * This method is used to convert the provided value into an XML 057 * usable format. This is used in the serialization process when 058 * there is a need to convert a field value in to a string so 059 * that that value can be written as a valid XML entity. 060 * 061 * @param value this is the value to be converted to a string 062 * 063 * @return this is the string representation of the given value 064 */ 065 String write(T value) throws Exception; 066}