001/* 002 * Copyright (c) 2004-2012, Willem Cazander 003 * All rights reserved. 004 * 005 * Redistribution and use in source and binary forms, with or without modification, are permitted provided 006 * that the following conditions are met: 007 * 008 * * Redistributions of source code must retain the above copyright notice, this list of conditions and the 009 * following disclaimer. 010 * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 011 * the following disclaimer in the documentation and/or other materials provided with the distribution. 012 * 013 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 014 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 015 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 016 * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 017 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 018 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 019 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 020 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 021 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 022 */ 023 024package org.x4o.xml.conv; 025 026import java.io.Serializable; 027import java.util.List; 028import java.util.Locale; 029 030/** 031 * The interface to convert objects. 032 * 033 * @author Willem Cazander 034 * @version 1.0 Aug 28, 2008 035 */ 036public interface ObjectConverter extends Cloneable,Serializable { 037 038 /** 039 * @return Returns the class which we can convert to. 040 */ 041 Class<?> getObjectClassTo(); 042 043 /** 044 * @return Returns the class which we can convert from. 045 */ 046 Class<?> getObjectClassBack(); 047 048 /** 049 * Convert to the object. 050 * @param obj The object to convert. 051 * @param locale The Object convert locale if needed. 052 * @return Returns the converted object. 053 * @throws ObjectConverterException 054 */ 055 Object convertTo(Object obj,Locale locale) throws ObjectConverterException; 056 057 /** 058 * Convert the object back. 059 * @param obj The object to convert. 060 * @param locale The Object convert locale if needed. 061 * @return Returns the converted object. 062 * @throws ObjectConverterException 063 */ 064 Object convertBack(Object obj,Locale locale) throws ObjectConverterException; 065 066 /** 067 * @return Returns list of child converters. 068 */ 069 List<ObjectConverter> getObjectConverters(); 070 071 /** 072 * @param converter Adds an child converter. 073 */ 074 void addObjectConverter(ObjectConverter converter); 075 076 /** 077 * @param converter Removes this child converter. 078 */ 079 void removeObjectConverter(ObjectConverter converter); 080 081 /** 082 * Force impl to have public clone method. 083 * 084 * @return An cloned ObjectConverter. 085 * @throws CloneNotSupportedException If thrown when cloning is not supported. 086 */ 087 ObjectConverter clone() throws CloneNotSupportedException; 088}