Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

ReadWrite.java

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.util;
00026 
00027 import java.util.ArrayList;
00028 import java.util.Enumeration;
00029 import java.util.Hashtable;
00030 
00031 /**
00032  * This class defines reading and writing convenient methods
00033  * 
00034  * @author <a href="mailto:Nicolas.Modrzyk@inria.fr">Nicolas Modrzyk </a>
00035  * @version 1.0
00036  */
00037 public class ReadWrite
00038 {
00039 
00040   /**
00041    * Write the content of the <code>Hashtable</code> in a readable format
00042    * 
00043    * @param table the hashtable to get keys and values from
00044    * @param prefix prefix some values with tabs
00045    * @return <code>String</code> conversion for the table content
00046    */
00047   public static String write(Hashtable table, boolean prefix)
00048   {
00049     if (table == null)
00050       return "";
00051     StringBuffer buffer = new StringBuffer();
00052     Enumeration e = table.keys();
00053     Object o;
00054     while (e.hasMoreElements())
00055     {
00056       o = e.nextElement();
00057       if (o.toString().indexOf(".path") != -1)
00058       {
00059         // This is a class path, make it look nice
00060         buffer.append(o + " = " + System.getProperty("line.separator"));
00061         String substring = (String) table.get(o);
00062         int index;
00063         while (true)
00064         {
00065           index = substring.indexOf(':');
00066           if (index == -1)
00067             break;
00068           if (prefix)
00069             buffer.append("\t\t");
00070           buffer.append(substring.substring(0, index)
00071               + System.getProperty("line.separator"));
00072           substring = substring.substring(index + 1);
00073         }
00074         if (prefix)
00075           buffer.append("\t\t");
00076         buffer.append(substring + System.getProperty("line.separator"));
00077       }
00078       else
00079       {
00080         buffer.append(o + " = " + table.get(o)
00081             + System.getProperty("line.separator"));
00082       }
00083     }
00084     return buffer.toString();
00085   }
00086 
00087   /**
00088    * Write the content of the <code>ArrayList<code> in a readable format
00089    * 
00090    * @param list the list to get the values from
00091    * @param listName give the prefix names for values
00092    * @param writeCountKey should we write the count keys
00093    * @return <code>String</code> conversion for the list content
00094    */
00095   public static String write(ArrayList list, String listName,
00096       boolean writeCountKey)
00097   {
00098     if (list == null)
00099       return "";
00100     StringBuffer buffer = new StringBuffer();
00101     int size = list.size();
00102     if (writeCountKey)
00103       buffer.append(listName + ".items.count=" + size
00104           + System.getProperty("line.separator"));
00105     for (int i = 0; i < size; i++)
00106       buffer.append(listName + "." + i + "=" + list.get(i)
00107           + System.getProperty("line.separator"));
00108     return buffer.toString();
00109   }
00110 }

Generated on Mon Apr 11 22:01:34 2005 for C-JDBC by  doxygen 1.3.9.1