All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jk.application.api.AbstractModule Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2002-2016 Jalal Kiswani.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.jk.application.api;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.jk.application.exceptions.ModuleException;
import com.jk.application.reports.Report;
import com.jk.application.reports.ReportManager;
import com.jk.locale.JKLocale;
import com.jk.locale.JKMessage;
import com.jk.logging.JKLogger;
import com.jk.logging.JKLoggerFactory;
import com.jk.metadata.db.meta.EntityMeta;
import com.jk.security.JKPrivilige;
import com.jk.security.JKSecurityManager;
import com.jk.util.JK;

/**
 * The Class AbstractModule.
 *
 * @author Jalal Kiswani
 */
public abstract class AbstractModule implements Module {
	JKLogger logger = JKLoggerFactory.getLogger(getClass());
	String moduleName;
	String configFilePath;
	String iconName;
	private List menu;
	private boolean defaultModule;
	private Application application;
	private int moduleId;
	private Map tablesMeta;

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.jk.metadata.application.Module#getApplication()
	 */
	@Override
	public Application getApplication() {
		return this.application;
	}

	/**
	 * Gets the config file path.
	 *
	 * @return the configFilePath
	 */
	public String getConfigFilePath() {
		return this.configFilePath;
	}

	/**
	 * Gets the file full path.
	 *
	 * @param shortFileName
	 *            the short file name
	 * @return the file full path
	 */
	@Override
	public String getFileFullPath(final String shortFileName) {
		if (this.configFilePath != null) {
			return this.configFilePath + "/" + shortFileName;
		}
		String packageName = "/" + this.getClass().getPackage().getName();
		packageName = packageName.replaceAll("\\.", "/");
		return packageName + "/meta/" + shortFileName;
	}

	// //////////////////////////////////////////////////////////////////////////////////////////
	/*
	 * (non-Javadoc)
	 * 
	 * @see com.jk.metadata.application.Module#getMenu()
	 */
	@Override
	public List getMenu() {
		return this.menu;
	}

	/**
	 * Sets the menu.
	 *
	 * @param menu
	 *            the new menu
	 */
	public void setMenu(List menu) {
		this.menu = menu;
	}

	// public int getModuleId() {
	// return priviligeId;
	/*
	 * (non-Javadoc)
	 * 
	 * @see com.jk.metadata.application.Module#getModuleId()
	 */
	// }
	@Override
	public int getModuleId() {
		return this.moduleId;
	}

	/**
	 * Gets the module name.
	 *
	 * @return the moduleName
	 */
	@Override
	public String getModuleName() {
		return this.moduleName;
	}

	/**
	 * Gets the privilige.
	 *
	 * @return the priviligeId
	 */
	@Override
	public JKPrivilige getPrivilige() {
		return JKSecurityManager.createPrivilige(JKMessage.get(getModuleName(), true), null);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.jk.metadata.application.Module#getReports(java.lang.String,
	 * java.lang.String)
	 */
	@Override
	public List getReports() throws ModuleException {
		final InputStream in = this.getClass().getResourceAsStream(getFileFullPath("reports.xml"));
		if (in != null) {
			final ReportManager report = ApplicationSuperFactory.getInstance().createReportManager(in);
			return report.getInstanceReports();
		}
		return new ArrayList();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.jk.metadata.application.Module#getTablesMeta()
	 */
	@Override
	public Map getEntitiesMeta() {
		return tablesMeta;
	}

	/**
	 * Sets the tables meta.
	 *
	 * @param tablesMeta
	 *            the tables meta
	 */
	public void setTablesMeta(Map tablesMeta) {
		this.tablesMeta = tablesMeta;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.jk.metadata.application.Module#init()
	 */
	@Override
	public void init() throws ModuleException {
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.jk.metadata.application.Module#isDefault()
	 */
	@Override
	public boolean isDefault() {
		return this.defaultModule;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.jk.metadata.application.Module#setApplication(com.jk.metadata.
	 * application.Application)
	 */
	@Override
	public void setApplication(final Application application) {
		this.application = application;
	}

	/**
	 * Sets the config file path.
	 *
	 * @param configFilePath
	 *            the configFilePath to set
	 */
	public void setConfigFilePath(final String configFilePath) {
		this.configFilePath = configFilePath;
	}

	/**
	 * Sets the config path.
	 *
	 * @param configFilePath
	 *            the new config path
	 */
	public void setConfigPath(String configFilePath) {
		if (configFilePath != null) {
			configFilePath = configFilePath.replaceAll("\\.", "/");
			if (!configFilePath.startsWith("/")) {
				configFilePath = "/" + configFilePath;
			}
		}
		this.configFilePath = configFilePath;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.jk.metadata.application.Module#setDefault(boolean)
	 */
	@Override
	public void setDefault(final boolean defaultModule) {
		this.defaultModule = defaultModule;
	}

	/**
	 * Sets the icon name.
	 *
	 * @param iconName
	 *            the iconName to set
	 */
	public void setIconName(final String iconName) {
		this.iconName = iconName;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.jk.metadata.application.Module#setModuleId(int)
	 */
	@Override
	public void setModuleId(final int moduleId) {
		this.moduleId = moduleId;
	}

	/**
	 * Sets the module name.
	 *
	 * @param moduleName
	 *            the moduleName to set
	 */
	@Override
	public void setModuleName(final String moduleName) {
		this.moduleName = moduleName;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		final StringBuffer buf = new StringBuffer();
		return buf.toString();
	}
	
	@Override
	public List getReports(JKLocale locale) {
		JK.implementMe();
		return null;
	}

	@Override
	public void setIndex(int index) {
		JK.implementMe();
	}

	@Override
	public void setDataSource(Object dataSource) {
		JK.implementMe();
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy