001 // Copyright 2004, 2005 The Apache Software Foundation 002 // 003 // Licensed under the Apache License, Version 2.0 (the "License"); 004 // you may not use this file except in compliance with the License. 005 // You may obtain a copy of the License at 006 // 007 // http://www.apache.org/licenses/LICENSE-2.0 008 // 009 // Unless required by applicable law or agreed to in writing, software 010 // distributed under the License is distributed on an "AS IS" BASIS, 011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012 // See the License for the specific language governing permissions and 013 // limitations under the License. 014 015 package org.apache.tapestry.util.io; 016 017 import org.apache.tapestry.services.DataSqueezer; 018 019 /** 020 * Interface which defines a class used to convert data for a specific Java type into a String 021 * format (squeeze it), or convert from a String back into a Java type (unsqueeze). 022 * <p> 023 * This interface is somewhat misnamed; this is more of the GoF Strategy pattern than GoF Adaptor 024 * pattern. 025 * 026 * @author Howard Lewis Ship 027 */ 028 029 public interface SqueezeAdaptor 030 { 031 /** 032 * Returns one or more characters, each of which will be a prefix for this adaptor. 033 */ 034 035 public String getPrefix(); 036 037 /** 038 * Returns the class (or interface) which can be encoded by this adaptor. 039 */ 040 041 public Class getDataClass(); 042 043 /** 044 * Converts the data object into a String. 045 * 046 * @throws IOException 047 * if the object can't be converted. 048 */ 049 050 public String squeeze(DataSqueezer squeezer, Object data); 051 052 /** 053 * Converts a String back into an appropriate object. 054 * 055 * @throws IOException 056 * if the String can't be converted. 057 */ 058 059 public Object unsqueeze(DataSqueezer squeezer, String string); 060 }