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

SynchroManager.java

00001 /*
00002  * OpenMobileIS - a free Java(TM) Framework for mobile applications Java(TM)
00003  * Copyright (C) 2004-2005 Philippe Delrieu
00004  * All rights reserved.
00005  * Contact: openmobileis@e-care.fr
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  */
00025 package org.openmobileis.synchro.client;
00026 
00027 import java.util.Enumeration;
00028 import java.util.Hashtable;
00029 
00030 import org.openmobileis.common.context.ApplicationContextManager;
00031 import org.openmobileis.common.util.exception.SynchroException;
00032 import org.openmobileis.common.util.log.LogManager;
00033 import org.openmobileis.synchro.security.auth.Credential;
00034 
00042 public final class SynchroManager {
00043 
00044   private static SynchroManager manager;
00045   private Hashtable procTable;
00046 
00050   private SynchroManager() {
00051     super();
00052     procTable = new Hashtable(10);
00053   }
00054 
00055   public static SynchroManager getManager() {
00056     if (manager == null)  {
00057       synchronized (SynchroManager.class) {
00058         if (manager == null)  {
00059           manager = new SynchroManager();
00060           ApplicationContextManager.getManager().addManager(manager);
00061         }
00062       }
00063     }
00064     return manager;
00065   }
00066  
00067   public void registerSynchroProcessor(SynchroProcessor proc)  {
00068     procTable.put(proc.getProcessorName(), proc);
00069   }
00070   
00071   public SynchroProcessor getSynchroProcessor(String processorName)  {
00072     return (SynchroProcessor) procTable.get(processorName);
00073   }
00074   
00075   public void doSynchro(Credential cred, SynchroDescriptor descriptor)  throws SynchroException {
00076     //open ras
00077     descriptor.synchroConduit.openRAS();
00078     try {
00079       boolean error = false;
00080       Enumeration proclist = procTable.elements();
00081       while (proclist.hasMoreElements())  {
00082         try {
00083           SynchroProcessor proc = (SynchroProcessor) proclist.nextElement();
00084           proc.doSynchro(cred, descriptor);
00085         } catch (Throwable ex)  {
00086           LogManager.traceError(0, ex);
00087           error = true;
00088         }
00089       }
00090       if (error)  {
00091         throw new SynchroException("Error during SynchroManager doSynchro processing");
00092       }
00093     } finally {
00094       descriptor.synchroConduit.closeRAS();
00095     }
00096   }
00097 
00098 }

Generated on Wed Dec 14 21:05:35 2005 for OpenMobileIS by  doxygen 1.4.4