TestSynchroOSGIOpenMISInit.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 
00026 package org.openmobileis.module.test.server;
00027 
00028 import java.io.File;
00029 import java.util.Properties;
00030 
00031 import org.openmobileis.common.user.UserManager;
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.exception.ServiceException;
00036 import org.openmobileis.common.util.file.FileUtilities;
00037 import org.openmobileis.common.util.log.FileLogManager;
00038 import org.openmobileis.common.util.log.LogManager;
00039 import org.openmobileis.services.servlet.OpenMISInit;
00040 import org.openmobileis.synchro.algo.syncnumber.SyncNumberManager;
00041 import org.openmobileis.synchro.algo.syncnumber.impl.EmptySyncNumberManagerDelegate;
00042 
00043 public class TestSynchroOSGIOpenMISInit implements OpenMISInit {
00044 
00045   public TestSynchroOSGIOpenMISInit() {
00046     super();
00047   }
00048 
00049   public void preLoadingInit() throws ServiceException {
00050     //init database.
00051     try {
00052         System.out.println("test acccent ééékdd");
00053         
00054       Properties  props = new Properties();
00055       props.put("org.openmobileis.common.log.file", System.getProperty("user.dir")+"/WEB-INF/log/serverlog.txt");
00056       File file = new File(System.getProperty("user.dir")+"/WEB-INF/log");
00057       if (file.exists())   FileLogManager.registerLogManager(props); //log to a file
00058       else LogManager.registerLogManager(null); //log to a console
00059 
00060       PropertiesManager.getManager().addProperty("org.openmobileis.common.user.profil.xmlprofilfile.path",System.getProperty("user.dir") + "/WEB-INF/conf/defaultprofils.xml");
00061       // init user manager with the default impl with one user. Login:test Pwd:test
00062       //to authenticate to another source, use your UserManagerFactory
00063       UserManager.getManager().registerUserManagerFactoryForGroup("default", new TestBundleUserManagerFactory());
00064       //register the sync nyumber manager. Sync number identify a db modification in the time.
00065       //every modification on db data is tracked with a sync number.
00066       SyncNumberManager.getManager().registerDelegate(new EmptySyncNumberManagerDelegate());
00067 
00068       // init profil management with default profil. All synchronized collection must be in the profil.
00069       //edit the defaultprofils.xml file to add your collection.
00070       ProfileDataManager.getManager().registerProfilDataFactoryForGroup("default", new XmlFileProfilDataFactory());
00071     } catch (Throwable ex)  {
00072       throw new ServiceException(ex);
00073     }
00074  }
00075 
00076   public void postLoadingInit() throws ServiceException {
00077 
00078             //Start OSGI Container      
00079           System.setProperty("org.osgi.framework.dir", System.getProperty("user.dir")+"/osgifwk/repository");
00080           System.setProperty("org.knopflerfish.verbosity", "9");
00081           //remove old context 
00082           String dir =  System.getProperty("user.dir")+"/osgifwk/repository";
00083           FileUtilities.deleteDir(new File(dir));
00084           
00085                 org.knopflerfish.framework.Main.main(new String[0]);
00086   }
00087 
00088 }

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