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

Generated on Mon Dec 4 11:03:28 2006 for OpenMobileIS by  doxygen 1.5.1-p1