00001 /** 00002 * C-JDBC: Clustered JDBC. 00003 * Copyright (C) 2002-2004 French National Institute For Research In Computer 00004 * Science And Control (INRIA). 00005 * Contact: c-jdbc@objectweb.org 00006 * 00007 * This library is free software; you can redistribute it and/or modify it 00008 * under the terms of the GNU Lesser General Public License as published by the 00009 * Free Software Foundation; either version 2.1 of the License, or any later 00010 * version. 00011 * 00012 * This library is distributed in the hope that it will be useful, but WITHOUT 00013 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00014 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 00015 * for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public License 00018 * along with this library; if not, write to the Free Software Foundation, 00019 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. 00020 * 00021 * Initial developer(s): Nicolas Modrzyk 00022 * Contributor(s): ______________________. 00023 */ 00024 00025 package org.objectweb.cjdbc.common.sql.filters; 00026 00027 import java.io.Serializable; 00028 00029 import org.objectweb.cjdbc.common.xml.DatabasesXmlTags; 00030 00031 /** 00032 * This class defines a BlobFilterInterface. All implementing interface should 00033 * satisfy the following: - Implementation is not dependant of the database - 00034 * decode(encode(data)) = data 00035 * 00036 * @author <a href="mailto:Nicolas.Modrzyk@inria.fr">Nicolas Modrzyk </a> 00037 * @version 1.0 00038 */ 00039 public abstract class AbstractBlobFilter implements Serializable 00040 { 00041 00042 /** 00043 * Get an instance of an <code>AbstractBlobFilter</code> given the 00044 * blobEndodingMethod description. Currently supported are: <br> 00045 * <code>hexa</code><br> 00046 * <code>none</code><br> 00047 * <code>escaped</code><br> 00048 * If the parameter specified is not appropriate then a 00049 * <code>NoneBlobFilter</code> instance is returned. 00050 * 00051 * @param blobEncodingMethod the string description 00052 * @return <code>AbstractBlobFilter</code> instance 00053 */ 00054 public static AbstractBlobFilter getBlobFilterInstance( 00055 String blobEncodingMethod) 00056 { 00057 if (blobEncodingMethod.equals(DatabasesXmlTags.VAL_hexa)) 00058 return new HexaBlobFilter(); 00059 else if (blobEncodingMethod.equals(DatabasesXmlTags.VAL_escaped)) 00060 return new BlobEscapedFilter(); 00061 else if (blobEncodingMethod.equals(DatabasesXmlTags.VAL_base64)) 00062 return new Base64Filter(); 00063 else 00064 return new NoneBlobFilter(); 00065 } 00066 00067 /** 00068 * Encode the blob data in a form that is independant of the database. 00069 * 00070 * @param data the byte array to convert 00071 * @return <code>String</code> object is returned for convenience as this is 00072 * the way it is going to be handled afterwards. 00073 */ 00074 public abstract String encode(byte[] data); 00075 00076 /** 00077 * Encode the blob data in a form that is independant of the database. 00078 * 00079 * @param data the byte array to convert 00080 * @return <code>String</code> object is returned for convenience as this is 00081 * the way it is going to be handled afterwards. 00082 */ 00083 public abstract String encode(String data); 00084 00085 /** 00086 * Decode the blob data from the database. This must done in a database 00087 * independant manner. 00088 * 00089 * @param data the data to decode 00090 * @return <code>byte[]</code> decoded byte array of data 00091 */ 00092 public abstract byte[] decode(byte[] data); 00093 00094 /** 00095 * Decode the blob data from the database. This must done in a database 00096 * independant manner. 00097 * 00098 * @param data the data to decode 00099 * @return <code>byte[]</code> decoded byte array of data 00100 */ 00101 public abstract byte[] decode(String data); 00102 00103 /** 00104 * Get the XML attribute value of the filter as defined in the DTD. 00105 * 00106 * @return XML attribute value 00107 */ 00108 public abstract String getXml(); 00109 }