| /******************************************************************************* |
| * Copyright (c) 2018 Robert Bosch GmbH. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Robert Bosch GmbH - initial API and implementation |
| *******************************************************************************/ |
| |
| package org.eclipse.app4mc.transformation.extensions.base.templates |
| |
| import com.google.inject.Inject |
| 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 { |
| |
| @Inject public CustomObjectsStore customObjsStore |
| |
| public Logger logger |
| |
| public Properties properties |
| |
| 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")» |
| * ''' |
| */ |
| } |