KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > continuent > sequoia > common > sql > filters > AbstractBlobFilter


1 /**
2  * Sequoia: Database clustering technology.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Copyright (C) 2005 AmicoSoft, Inc. dba Emic Networks
6  * Contact: sequoia@continuent.org
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  * Initial developer(s): Nicolas Modrzyk
21  * Contributor(s): Emmanuel Cecchet.
22  */

23
24 package org.continuent.sequoia.common.sql.filters;
25
26 import org.continuent.sequoia.common.xml.DatabasesXmlTags;
27
28 /**
29  * This class defines a BlobFilterInterface. All implementing interface should
30  * satisfy the following: - Implementation is not dependant of the database -
31  * decode(encode(data)) = data
32  *
33  * @author <a HREF="mailto:Nicolas.Modrzyk@inria.fr">Nicolas Modrzyk </a>
34  * @author <a HREF="mailto:emmanuel.cecchet@emicnetworks.fr">Emmanuel Cecchet
35  * </a>
36  * @version 1.0
37  */

38 public abstract class AbstractBlobFilter
39 {
40   private static final Base64Filter BASE64FILTER = new Base64Filter();
41   private static final Base64ZipFilter BASE64_ZIP_FILTER = new Base64ZipFilter();
42   private static final HexaBlobFilter HEXA_BLOB_FILTER = new HexaBlobFilter();
43
44   /**
45    * Get an instance of an <code>AbstractBlobFilter</code> given the
46    * blobEndodingMethod description. Currently supported are: <br>
47    * <code>hexa</code><br>
48    * <code>base64</code><br>
49    * <code>base64zip</code><br>
50    * <code>escaped</code><br>
51    * If the parameter specified is not appropriate then a
52    * <code>NoneBlobFilter</code> instance is returned.
53    *
54    * @param blobEncodingMethod the string description
55    * @return <code>AbstractBlobFilter</code> instance
56    */

57   public static AbstractBlobFilter getBlobFilterInstance(
58       String JavaDoc blobEncodingMethod)
59   {
60     if (blobEncodingMethod.equals(DatabasesXmlTags.VAL_base64))
61       return BASE64FILTER;
62     if (blobEncodingMethod.equals(DatabasesXmlTags.VAL_base64zip))
63       return BASE64_ZIP_FILTER;
64     else if (blobEncodingMethod.equals(DatabasesXmlTags.VAL_hexa))
65       return HEXA_BLOB_FILTER;
66     else
67       throw new RuntimeException JavaDoc("Unknown Blob encoder " + blobEncodingMethod);
68   }
69
70   /**
71    * Returns the default blob filter. This is used for serializing
72    * PreparedStatement parameters in driverProcessed=false mode.
73    *
74    * @return the default blob filter.
75    */

76   public static AbstractBlobFilter getDefaultBlobFilter()
77   {
78     return BASE64FILTER;
79   }
80   
81   /**
82    * Encode the blob data in a form that is independant of the database.
83    *
84    * @param data the byte array to convert
85    * @return <code>String</code> object is returned for convenience as this is
86    * the way it is going to be handled afterwards.
87    */

88   public abstract String JavaDoc encode(byte[] data);
89
90   /**
91    * Decode the blob data from the database. This must done in a database
92    * independant manner.
93    *
94    * @param data the data to decode
95    * @return <code>byte[]</code> decoded byte array of data
96    */

97   public abstract byte[] decode(String JavaDoc data);
98
99   /**
100    * Get the XML attribute value of the filter as defined in the DTD.
101    *
102    * @return XML attribute value
103    */

104   public abstract String JavaDoc getXml();
105 }
Popular Tags