/*
 * $Id: ConverterService4JBoss.java,v 1.2 2007/08/16 11:10:58 marbobo Exp $
 *
 * Copyright (c) Siemens AG 2008 
 *           (c) Universität Paderborn 2008 
 * Licensed under EUPL 1.1. 
 *
 * $Log: ConverterService4JBoss.java,v $
 * Revision 1.2  2007/08/16 11:10:58  marbobo
 * + Bugfixes
 * + Refactorings
 *
 */
package vkc.converter.server;

import java.io.File;
import java.util.Properties;
import vkc.converter.server.ConverterServer;

public class ConverterService4JBoss {
    Properties properties = null;

    ConverterServer converterServer = null;

    // Lifecycle methods
    public void create() throws Exception {
        properties = new Properties();
        // Falls die Properties im Arbeitsverzeichnis sind,
        // werden sie geladen, sonst diejenigen aus dem vkc/converter/server
        // Verzeichnis
        File f = new File(ConverterServer.PROPERTIES_FILE);

        String propFilename = ConverterServer.PROPERTIES_FILE;

        if (f.exists()) {
            propFilename = "/" + propFilename;
        }

        properties.load(ConverterServer.class.getResourceAsStream(propFilename));

        System.out.println("ConverterServer - Created");
    }

    public void start() throws Exception {
        converterServer = new ConverterServer(properties);

        System.out.println("ConverterServer - Started");
    }

    public void stop() {
        converterServer.shutdown();

        System.out.println("ConverterServer - Stopped");
    }

    public void destroy() {
        properties = null;
        converterServer = null;

        System.out.println("ConverterServer - Destroyed");
    }

    public static void main(String[] args) throws Exception {
        ConverterService4JBoss converterService = new ConverterService4JBoss();

        converterService.create();
        Thread.sleep(5000);

        converterService.start();
        Thread.sleep(10000);

        converterService.stop();
        Thread.sleep(5000);

        converterService.destroy();
        Thread.sleep(5000);
    }
}