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 * @return The prefix for this squeezer.
035 */
036
037 String getPrefix();
038
039 /**
040 * Returns the class (or interface) which can be encoded by this adaptor.
041 *
042 * @return The class type that this adaptor can manage.
043 */
044
045 Class getDataClass();
046
047 /**
048 * Converts the data object into a String.
049 *
050 * @param squeezer
051 * The squeezer that should be used to ultimately squeeze the data.
052 * @param data
053 * The data to squeeze.
054 *
055 * @return String representation of data.
056 */
057
058 String squeeze(DataSqueezer squeezer, Object data);
059
060 /**
061 * Converts a String back into an appropriate object.
062 *
063 * @param squeezer
064 * The squeezer to use to unsqueeze the data.
065 * @param string
066 * The string data - as was returned from {@link #squeeze(org.apache.tapestry.services.DataSqueezer, Object)}.
067 *
068 * @return The re-constituded object representation of the string.
069 */
070
071 Object unsqueeze(DataSqueezer squeezer, String string);
072 }