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

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