package it.unina.seclab.jafimon.test;
import it.unina.seclab.jafimon.DataCollection;
import it.unina.seclab.jafimon.MonitoredData;
import it.unina.seclab.jafimon.MonitoredDataManager;
import it.unina.seclab.jafimon.util.SystemEnvironmentVariables;
import java.io.IOException;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
/**
* Classe ad uso interno per il testing
*
* @author Mauro Iorio
*
*/
public class TestMainClass {
private static final Logger logger = Logger.getRootLogger();
//private static Loader loader;
public static void main(String[] args) throws Throwable {
try {
PropertyConfigurator.configure(SystemEnvironmentVariables.getEnvironmentVariable("JAFIMON_HOME") + "/log4j.properties");
} catch (IOException e) {
PropertyConfigurator.configure("log4j.properties");
}
logger.info("starting execution");
MonitoredDataManager dMgr = new MonitoredDataManager();
dMgr.appendDateTimeToName = true;
MonitoredData mData = new MonitoredData();
int id = dMgr.newDataCollection("Pippo");
for (int i = 0; i < 10; i++)
dMgr.appendData(id, mData.setData("Ullalla" + i));
String[] lista = dMgr.getCollectionList();
for (int i = 0; i < lista.length; i++) {
logger.trace(lista[i]);
}
DataCollection coll = dMgr.getCollection("Pippo-20070117191741");
String data = coll.getFirstData();
while (data.length() > 0) {
System.out.print(data);
data = coll.getNextData();
}
data = coll.getFirstData();
System.out.print(data);
/*
ClassPool pool = ClassPool.getDefault();
loader = new Loader(pool);
// Evitiamo i conflitti per le classi Logging
loader.delegateLoadingOf("org.apache.commons.logging.");
logger.trace("inst loader");
logger.trace("TestMainClass args:");
for(int i = 0; i < args.length; i++) {
logger.trace("\t" + args[i]);
}
// CtClass CustomBootstrap = pool.get("org.apache.catalina.startup.BootStrapJAFIMON");
// CtMethod[] methods = CustomBootstrap.getDeclaredMethods();
// for (int i = 0; i < methods.length; i++) {
// logger.trace(methods[i].getName() + " " + methods[i].getSignature());
// }
// CtMethod met = CustomBootstrap.getMethod("initClassLoaders$JAFIMON", "()V");
// met.setBody(
// "try {" +
// " log.error(\"Sono nel CustomMethod\");" +
// " commonLoader = createClassLoader(\"common\", null);" +
// " if( commonLoader == null ) {" +
// " // no config file, default to this loader - we might be in a 'single' env." +
// " commonLoader=this.getClass().getClassLoader();" +
// " }" +
// " catalinaLoader = createClassLoader(\"server\", commonLoader);" +
// " sharedLoader = createClassLoader(\"shared\", commonLoader);" +
// "} catch (Throwable t) {" +
// " log.error(\"Class loader creation threw exception\", t);" +
// " System.exit(1);" +
// "}"
// );
loader.addTranslator(pool, new CustomTranslator());
logger.trace("inst translator");
String[] pargs = new String[args.length - 1];
System.arraycopy(args, 1, pargs, 0, pargs.length);
logger.trace("ready to run!");
loader.run(args[0], pargs);
// new Activator().startSystem("Tomcat5", null, null);
logger.info("stopping execution");
//
// logger.trace("trace msg");
// logger.debug("debug msg");
// logger.info("info msg");
// logger.warn("warn msg");
// logger.error("error msg");
// logger.fatal("fatal msg");
//
*/
}
}