
org.coos.messaging.COOSBootstrap Maven / Gradle / Ivy
/**
* COOS - Connected Objects Operating System (www.connectedobjects.org).
*
* Copyright (C) 2009 Telenor ASA and Tellu AS. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* You may also contact one of the following for additional information:
* Telenor ASA, Snaroyveien 30, N-1331 Fornebu, Norway (www.telenor.no)
* Tellu AS, Hagalokkveien 13, N-1383 Asker, Norway (www.tellu.no)
*/
package org.coos.messaging;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import org.coos.util.macro.MacroSubstituteReader;
/**
* A Bootstrap class to be used in standalone environments
*
* @author Knut Eilif Husa, Tellu AS
*/
public class COOSBootstrap implements COContainer {
private final static String COOS_CONFIG_DIR = "configDir";
private final static String DEFAULT_COOS_CONFIG_DIR = "./coosConfig";
private static final String COOS_CONFIG_PATH = "/org/coos/config";
private static String configDir;
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
configDir = DEFAULT_COOS_CONFIG_DIR;
for (int i = 0; i < args.length; i++) {
if (args[0].startsWith(COOS_CONFIG_DIR)) {
configDir = args[0].substring(args[0].indexOf('=')).trim();
}
if (args[0].equals("?")) {
System.out
.println("Usage: java org.coos.messaging.COOSBootstrap [configDir=]");
System.out.println("Configuration directory contains either coos.xml or plugin.xml or both.");
System.out
.println("If configuration directory contains coos.xml it will override the default coos configuration.]");
System.out
.println("If configuration directory contains plugin.xml it will be added to the default plugin configuration for the coos instance.");
System.out.println("Notice: You have to provide the classes used by the plugin on the classpath.");
return;
}
}
COOSBootstrap bs = new COOSBootstrap();
COOSBootstrapHelper.startCOOS(configDir, bs);
COOSBootstrapHelper.startPlugins(configDir, bs);
}
public Object getObject(String name) {
return null;
}
public InputStream getResource(String resourceName) throws IOException {
InputStream is = null;
try {
File file = new File(configDir + resourceName);
is = file.toURI().toURL().openStream();
is = substitute(is);
} catch (Exception e) {
}
// if it is not overridden, use the provided file
if (is == null) {
is = this.getClass().getResourceAsStream(COOS_CONFIG_PATH + resourceName);
is = substitute(is);
}
return is;
}
public Class loadClass(String className) throws ClassNotFoundException {
return Class.forName(className);
}
private InputStream substitute(InputStream is) throws IOException {
InputStreamReader isr = new InputStreamReader(is);
MacroSubstituteReader msr = new MacroSubstituteReader(isr);
String substituted = msr.substituteMacros();
is = new ByteArrayInputStream(substituted.getBytes());
return is;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy