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

MyCrmServerOpenMISInit.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  */
00025 package org.openmobileis.examples.mycrm.server;
00026 
00027 import java.io.File;
00028 import java.util.Properties;
00029 
00030 import org.openmobileis.common.user.UserManager;
00031 import org.openmobileis.common.user.impl.MonoUserUserManagerFactory;
00032 import org.openmobileis.common.user.profil.ProfilDataManager;
00033 import org.openmobileis.common.user.profil.impl.XmlFileProfilDataFactory;
00034 import org.openmobileis.common.util.PropertiesManager;
00035 import org.openmobileis.common.util.database.JdbcPoolManagerDB;
00036 import org.openmobileis.common.util.database.ManagerDB;
00037 import org.openmobileis.common.util.exception.ServiceException;
00038 import org.openmobileis.common.util.log.FileLogManager;
00039 import org.openmobileis.common.util.log.LogManager;
00040 import org.openmobileis.database.fastobjectdb.synchro.server.FODBSynchroManager;
00041 import org.openmobileis.examples.mycrm.data.jdbc.MyCrmAccountSynchroTarget;
00042 import org.openmobileis.examples.mycrm.data.jdbc.MyCrmJDBCUserFactory;
00043 import org.openmobileis.examples.mycrm.data.jdbc.MyCrmLabelSynchroTarget;
00044 import org.openmobileis.examples.mycrm.data.jdbc.MyCrmLeadsSynchroTarget;
00045 import org.openmobileis.examples.mycrm.data.jdbc.MyCrmTerminalUserlQuery;
00046 import org.openmobileis.examples.server.synchro.BaseDataFODBSyncTarget;
00047 import org.openmobileis.modules.crm.database.common.jdbc.JDBCTerminalUserFODBSyncTarget;
00048 import org.openmobileis.services.servlet.OpenMISInit;
00049 import org.openmobileis.synchro.algo.replication.utils.DefaultSynchroAtomicObjectDelegate;
00050 import org.openmobileis.synchro.algo.replication.utils.SynchroAtomicObjectManager;
00051 import org.openmobileis.synchro.algo.replication.utils.impl.HSQLAtomicObjectQueryManager;
00052 import org.openmobileis.synchro.algo.syncnumber.SyncNumberManager;
00053 import org.openmobileis.synchro.algo.syncnumber.impl.DefaultSyncNumberManagerDelegate;
00054 import org.openmobileis.synchro.algo.syncnumber.impl.HSQLSyncNumberQueryManager;
00055 import org.openmobileis.synchro.openmsp.server.synctarget.SynchroTargerManager;
00056 import org.openmobileis.synchro.openmsp.server.synctarget.proxy.GenericProxySynchroTarget;
00057 
00065 public final class MyCrmServerOpenMISInit implements OpenMISInit {
00066 
00070   public MyCrmServerOpenMISInit() {
00071     super();
00072   }
00073 
00074   /* (non-Javadoc)
00075    * @see org.openmobileis.services.servlet.OpenMISInit#preLoadingInit()
00076    */
00077   public void preLoadingInit() throws ServiceException {
00078     
00079     //init database.
00080     try {
00081       Properties  props = new Properties();
00082       props.put("org.openmobileis.common.log.file", System.getProperty("user.dir")+"/WEB-INF/log/serverlog.txt");
00083       File file = new File(System.getProperty("user.dir")+"/WEB-INF/log");
00084       if (file.exists())   FileLogManager.registerLogManager(props); //log to a file
00085       else LogManager.registerLogManager(null); //log to a console
00086      
00087       //init synchro database access.
00088       //use OpenMis db facilities. Any other JDBC DB API can be use.
00089       //load db properties
00090       PropertiesManager.getManager().addProperty("server.database.dbDriver", "org.hsqldb.jdbcDriver");
00091       PropertiesManager.getManager().addProperty("server.database.dbServer","jdbc:hsqldb:file:"+System.getProperty("user.dir")+"/hsql/basedb");
00092       PropertiesManager.getManager().addProperty("server.database.dbLogin","sa");
00093       PropertiesManager.getManager().addProperty("server.database.dbPassword","");
00094       PropertiesManager.getManager().addProperty("server.database.pool.monitorInterval", "300");
00095       PropertiesManager.getManager().addProperty("server.database.pool.maxConns", "10");
00096       PropertiesManager.getManager().addProperty("server.database.pool.idleTimeout", "300");
00097       PropertiesManager.getManager().addProperty("server.database.pool.checkoutTimeout", "120");
00098       PropertiesManager.getManager().addProperty("server.database.pool.maxCheckout", "3000");      
00099       JdbcPoolManagerDB dbmanager = new JdbcPoolManagerDB(); //init pool with loaded properties
00100       ManagerDB.registerManager(dbmanager);
00101       
00102       PropertiesManager.getManager().addProperty("org.openmobileis.common.user.profil.xmlprofilfile.path",System.getProperty("user.dir") + "/WEB-INF/conf/defaultprofils.xml");
00103       // init user manager with the default impl with one user. Login:test Pwd:test
00104       //to authenticate to another source, use your UserManagerFactory
00105       UserManager.getManager().registerUserManagerFactoryForGroup("default", new MyCrmJDBCUserFactory());
00106       //register the sync nyumber manager. Sync number identify a db modification in the time.
00107       //every modification on db data is tracked with a sync number.
00108       SyncNumberManager.getManager().registerDelegate(new DefaultSyncNumberManagerDelegate(new HSQLSyncNumberQueryManager()));
00109       
00110       // register the Synchro Atomic object manager.
00111       //manage data modification on the db server side.
00112       //It is use to get all modification since last synchro
00113       //It's use is not mandatotry. We provide it to facilitate the server db  modification management
00114       // But you can use any other db modification tracking process.
00115       // Use inside the FODBSynchroTarget to implements the getAllModifiedAtomicObjectSince method.
00116       SynchroAtomicObjectManager.getManager().registerDelegateManager(
00117             new DefaultSynchroAtomicObjectDelegate(
00118               new HSQLAtomicObjectQueryManager()  // default implementation for HSQL
00119             )
00120           );
00121       
00122       // init profil management with default profil. All synchronized collection must be in the profil.
00123       //edit the defaultprofils.xml file to add your collection.
00124       ProfilDataManager.getManager().registerProfilDataFactoryForGroup("default", new XmlFileProfilDataFactory());
00125       
00126       //init TerminalUser synchro
00127       FODBSynchroManager.getManager().registerCollection(new JDBCTerminalUserFODBSyncTarget(new MyCrmTerminalUserlQuery()));
00128       // register terminal synchro target for all terminal synchronized collection
00129       FODBSynchroManager.getManager().registerCollection(new MyCrmLabelSynchroTarget());
00130       FODBSynchroManager.getManager().registerCollection(new MyCrmAccountSynchroTarget());
00131       FODBSynchroManager.getManager().registerCollection(new MyCrmLeadsSynchroTarget());
00132       
00133       // to be added to work with a servlet server.
00134       SynchroTargerManager.getManager().registerProxyTargetForTerminal(new GenericProxySynchroTarget(), null);      
00135     } catch (Throwable ex)  {
00136       throw new ServiceException(ex);
00137     }
00138     
00139     
00140   }
00141 
00142   /* (non-Javadoc)
00143    * @see org.openmobileis.services.servlet.OpenMISInit#postLoadingInit()
00144    */
00145   public void postLoadingInit() throws ServiceException {
00146   }
00147 
00148 }

Generated on Mon Jul 10 10:29:31 2006 for OpenMobileIS by  doxygen 1.4.4