blob: e414204489310f02b118bc9ac34ca531454875ca [file] [log] [blame]
/**
********************************************************************************
* Copyright (c) 2018-2019 Robert Bosch GmbH.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Robert Bosch GmbH - initial API and implementation
********************************************************************************
*/
package org.eclipse.app4mc.transformation.extensions.base.templates
import java.util.Properties
import org.apache.log4j.LogManager
import org.apache.log4j.Logger
import org.eclipse.app4mc.transformation.extensions.CustomObjectsStore
import org.apache.log4j.ConsoleAppender
import org.apache.log4j.PatternLayout
import com.google.inject.Injector
public abstract class AbstractTransformer{
static public CustomObjectsStore customObjsStore = new CustomObjectsStore
static public Logger logger
static public Properties properties
static public Injector injector
/**
* Provides Log4J logger which can be used by the corresponding Transformer classes.
* Note: Root Logger is initialized during the startup and the corresponding Appenders are hooked to it accordingly.
* In case, if user specific appenders are to be attached to the logger, this method should be overridden and new Appenders should be attached to the logger
*
*/
protected def Logger getLogger() {
if (logger === null) {
logger = createLogger
logger.addAppender(new ConsoleAppender(new PatternLayout))
}
return logger
}
protected def Logger createLogger(){
logger = LogManager.getLogger("com.bosch.m2m.app4mc.simulation");
}
protected def String getProperty(String propKey) {
if (properties === null) {
if (customObjsStore !== null) {
properties = customObjsStore.getInstance(Properties)
if (properties === null) {
throw new NullPointerException(
"Properties object not set in CustomObjectsStore : Verify the custom Google Guice Module configuration ")
}
} else {
throw new NullPointerException(
"CustomObjectsStore object not binded: Verify the custom Google Guice Module configuration ")
}
}
val value = properties.get(propKey)
if (value === null) {
throw new NullPointerException("Request input key : \"" + propKey +
"\" not supplied in the input properties file")
}
return value.toString
}
/* public def doGenerate() '''
*
* « val instance = customObjsStore.getInstance(Properties)»
* «instance.get("log_file")»
* «getLogger.warn("logging info about transformation of :"+this.class.name) »
* ----------> «this.class.name»
* ===============> «properties.get("log_file")»
* '''
*/
}