CollectionManager.java

00001 /*
00002  * OpenMobileIS - a free Java(TM) Framework for mobile applications Java(TM)
00003  * Copyright (C) 2004-2006 Philippe Delrieu
00004  * All rights reserved.
00005  * Contact: pdelrieu@openmobileis.org
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00020  * USA
00021  *
00022  *  Author : Philippe Delrieu
00023  *  
00024  *  Modifications :
00025  *  2004 Creation P.Delrieu
00026  * 
00027  */
00028 package org.openmobileis.database.fastobjectdb.db;
00029 
00030 import java.util.Hashtable;
00031 
00032 import org.openmobileis.common.util.collection.Array;
00033 
00041 public final class CollectionManager {
00042         protected Array collections;
00043 
00047   public CollectionManager() {
00048     super();
00049                 collections = new Array();
00050   }
00051   
00052   public void addCollection(FODBCollection collection)  {
00053                 collections.add(collection);
00054   } 
00055   
00056   public void removeCollection(String collectionName)   {
00057         int size = collections.size();
00058         FODBCollection collection = null;
00059         for (int i=0; i<size; i++)      {
00060                 collection = (FODBCollection)collections.get(i);
00061                 if (collection.getName().equals(collectionName))        {
00062                         collections.remove(i);
00063                         break;
00064                 }
00065         }
00066   } 
00067   
00068   public FODBCollection getCollectionByName(String name)        {
00069                 FODBCollection col = null;
00070         for (int i=0; i<collections.size(); i++)        {
00071                 col = (FODBCollection) collections.get(i);
00072                 if (col.getName().equals(name)) {
00073                         return col;
00074                 }               
00075         }
00076         return null;
00077   }
00078   
00079         public FODBCollection getCollectionByType(Class type)   {
00080                 FODBCollection col = null;
00081                 for (int i=0; i<collections.size(); i++)        {
00082                         col = (FODBCollection) collections.get(i);
00083                         if (col.getCollectionObjectClass().equals(type))        {
00084                                 return col;
00085                         }               
00086                 }
00087                 return null;
00088         }
00089         
00090         public Hashtable getCollectionList()    {
00091                 FODBCollection col = null;
00092                 Hashtable list = new Hashtable(collections.size());
00093                 for (int i=0; i<collections.size(); i++)        {
00094                         col = (FODBCollection) collections.get(i);
00095                         list.put(col.getName(), col);
00096                 }
00097                 return list;
00098         }
00099         
00100         public Array getCollectionArray()       {
00101                 return (Array) collections.clone();
00102         }
00103 
00104 }

Generated on Mon Jan 11 21:19:13 2010 for OpenMobileIS by  doxygen 1.5.4