⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 compiere.java

📁 Java写的ERP系统
💻 JAVA
字号:
/******************************************************************************
 * The contents of this file are subject to the   Compiere License  Version 1.1
 * ("License"); You may not use this file except in compliance with the License
 * You may obtain a copy of the License at http://www.compiere.org/license.html
 * Software distributed under the License is distributed on an  "AS IS"  basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 * the specific language governing rights and limitations under the License.
 * The Original Code is             Compiere  ERP & CRM Smart Business Solution
 * The Initial Developer of the Original Code is Jorg Janke  and ComPiere, Inc.
 * Portions created by Jorg Janke are Copyright (C) 1999-2003 Jorg Janke, parts
 * created by ComPiere are Copyright (C) ComPiere, Inc.;   All Rights Reserved.
 * Contributor(s): ______________________________________.
 *****************************************************************************/
package org.compiere;

import java.awt.*;
import java.net.*;
import java.io.*;
import java.util.*;
import java.util.jar.*;
import javax.swing.*;
import javax.naming.*;
import org.apache.log4j.*;

import org.compiere.util.*;
import org.compiere.plaf.*;
import org.compiere.db.*;

/**
 *  Compiere Control Class
 *
 *  @author Jorg Janke
 *  @version $Id: Compiere.java,v 1.10 2003/05/04 06:46:24 jjanke Exp $
 */
public final class Compiere
{
	/** Timestamp                   */
	static public final String	TIMESTAMP		= "$Date: 2003/05/04 06:46:24 $";
	/** Main Version String         */
	static public final String	MAIN_VERSION	= "Version 2.4.4c";
	/** Detail Version as date      */
	static public final String	DATE_VERSION	= "2003-05-02";
	/** Database Version as date    */
	static public final String	DB_VERSION		= "2003-05-02";

	/** Product Name            */
	static public final String	NAME 		= "Compiere\u2122";
	/** URL of Product          */
	static public final String	URL			= "www.compiere.org";
	/** 16*16 Product Image     */
	static private final String	s_File16x16	= "images/C16.gif";
	/** 32*32 Product Image     */
	static private final String	s_file32x32	= "images/C32.gif";
	/** 100*3- Product Image    */
	static private final String	s_file100x30	= "images/C10030.gif";
	/** 48*15 Product Image    	*/
	static private final String	s_file48x15	= "images/Compiere.gif";
	/** Support Email           */
	static private String		s_supportEmail	= "info@compiere.org";

	/** Subtitle                */
	static public final String	SUB_TITLE	= " Smart ERP & CRM ";
	/** Powered By          - Don't modify this - Program will fail unexpectedly  */
	static public final String	POWERED_BY	= " Powered by Compiere\u2122 ";
	/**  Copyright Notice   - Don't modify this - Program will fail unexpectedly  */
	static public final String	COPYRIGHT	= "Copyright \u00A9 1999-2003 Jorg Janke";

	static private String		s_ImplementationVersion = null;
	static private String		s_ImplementationVendor = null;

	static private Image 		s_image16;
	static private Image 		s_image48x15;
	static private Image 		s_imageLogo;
	static private ImageIcon 	s_imageIcon32;
	static private ImageIcon 	s_imageIconLogo;

	/**	Logging								*/
	private static Logger		s_log = null;

	/**
	 *  Get Product Name w/o TM
	 *  @return Application Name
	 */
	public static String getName()
	{
		return NAME;
	}   //  getName


	/**
	 *	Short Summary (Windows)
	 *  @return summary
	 */
	public static String getSum()
	{
		StringBuffer sb = new StringBuffer();
		sb.append(NAME).append(" ").append(MAIN_VERSION).append(SUB_TITLE);
		return sb.toString();
	}	//	getSum

	/**
	 *	Summary (Windows)
	 *  @return Summary in Windows character set
	 */
	public static String getSummary()
	{
		StringBuffer sb = new StringBuffer();
		sb.append(NAME).append(" ")
			.append(MAIN_VERSION).append("/").append(DATE_VERSION)
			.append(" -").append(SUB_TITLE)
			.append("- ").append(COPYRIGHT)
			.append(" - ").append(getImplementationVersion())
			.append(" - ").append(getImplementationVendor());
		return sb.toString();
	}	//	getSummary

	/**
	 * 	Set Jar Info
	 */
	private static void setJarInfo()
	{
		if (s_ImplementationVendor != null)
			return;
		s_ImplementationVendor = "?";
		s_ImplementationVersion = "?";

		try
		{
			//	Get Jar File
			JarFile jar = ZipUtil.getJar("CClient.jar");
			if (jar == null)
				jar = ZipUtil.getJar("CTools.jar");
			if (jar == null)
				return;

		//	JarEntry je = jar.getJarEntry(JarFile.MANIFEST_NAME);
		//	if (je != null)
		//		System.out.println("Time " + new Date(je.getTime()));
			Manifest mf = jar.getManifest();
			if (mf != null)
			{
				Attributes atts = mf.getMainAttributes();
				s_ImplementationVendor = atts.getValue("Implementation-Vendor");
				s_ImplementationVersion = atts.getValue("Implementation-Version");
			}
		}
		catch (IOException ex)
		{
			System.err.println(ex);
		}
	}	//	setJarInfo

	/**
	 * 	Get Jar Implementation Version
	 * 	@return Implementation-Version
	 */
	public static String getImplementationVersion()
	{
		if (s_ImplementationVersion == null)
			setJarInfo();
		return s_ImplementationVersion;
	}	//	getImplementationVersion

	/**
	 * 	Get Jar Implementation Vendor
	 * 	@return Implementation-Vendor
	 */
	public static String getImplementationVendor()
	{
		return s_ImplementationVendor;
	}	//	getImplementationVendor

	/**
	 *  Get Checksum
	 *  @return checksum
	 */
	public static int getCheckSum()
	{
		return getSum().hashCode();
	}   //  getCheckSum

	/**
	 *	Summary in ASCII
	 *  @return Summary in ASCII
	 */
	public static String getSummaryAscii()
	{
		String retValue = getSummary();
		//  Trademark
		retValue = Util.replace(retValue, "\u00AE", "(r)");
		//  Trademark
		retValue = Util.replace(retValue, "\u2122", "(tm)");
		//  Copyright
		retValue = Util.replace(retValue, "\u00A9", "(c)");
		//  Cr
		retValue = Util.replace(retValue, Env.NL, " ");
		retValue = Util.replace(retValue, "\n", " ");
		return retValue;
	}	//	getSummaryAscii

	/**
	 *  Get full URL
	 *  @return URL
	 */
	public static String getURL()
	{
		return "http://" + URL;
	}   //  getURL

	/**
	 *  Get Powered
	 *  @return Powered By Compiere
	 */
	public static String getPowered()
	{
		return POWERED_BY;
	}   //  getPowered

	/**
	 *  Get Sub Title
	 *  @return Subtitle
	 */
	public static String getSubtitle()
	{
		return SUB_TITLE;
	}   //  getSubitle

	/**
	 *  Get 16x16 Image
	 *  @return Image Icon
	 */
	public static Image getImage16()
	{
		if (s_image16 == null)
		{
			Toolkit tk = Toolkit.getDefaultToolkit();
			URL url = org.compiere.Compiere.class.getResource(s_File16x16);
		//	System.out.println(url);
			if (url == null)
				return null;
			s_image16 = tk.getImage(url);
		}
		return s_image16;
	}   //  getImage16

	/**
	 *  Get 28*15 Logo Image
	 *  @return Image Icon
	 */
	public static Image getImageLogoSmall()
	{
		if (s_image48x15 == null)
		{
			Toolkit tk = Toolkit.getDefaultToolkit();
			URL url = org.compiere.Compiere.class.getResource(s_file48x15);
		//	System.out.println(url);
			if (url == null)
				return null;
			s_image48x15 = tk.getImage(url);
		}
		return s_image48x15;
	}   //  getImageLogoSmall

	/**
	 *  Get Logo Image
	 *  @return Image Logo
	 */
	public static Image getImageLogo()
	{
		if (s_imageLogo == null)
		{
			Toolkit tk = Toolkit.getDefaultToolkit();
			URL url = org.compiere.Compiere.class.getResource(s_file100x30);
		//	System.out.println(url);
			if (url == null)
				return null;
			s_imageLogo = tk.getImage(url);
		}
		return s_imageLogo;
	}   //  getImageLogo

	/**
	 *  Get 32x32 ImageIcon
	 *  @return Image Icon
	 */
	public static ImageIcon getImageIcon32()
	{
		if (s_imageIcon32 == null)
		{
			URL url = org.compiere.Compiere.class.getResource(s_file32x32);
		//	System.out.println(url);
			if (url == null)
				return null;
			s_imageIcon32 = new ImageIcon(url);
		}
		return s_imageIcon32;
	}   //  getImageIcon32

	/**
	 *  Get 100x30 ImageIcon
	 *  @return Image Icon
	 */
	public static ImageIcon getImageIconLogo()
	{
		if (s_imageIconLogo == null)
		{
			URL url = org.compiere.Compiere.class.getResource(s_file100x30);
		//	System.out.println(url);
			if (url == null)
				return null;
			s_imageIconLogo = new ImageIcon(url);
		}
		return s_imageIconLogo;
	}   //  getImageIconLogo

	/**
	 *  Get default (Home) directory
	 *  @return Home directory
	 */
	public static String getCompiereHome()
	{
		//  Try Environment
		String retValue = Ini.getCompiereHome();
		if (retValue == null)
		{
			if (System.getProperty("os.name", "").startsWith("Win"))
				retValue = "D:\\Compiere2\\";
			else
				retValue = "/etc/Compiere2/";
		}
		return retValue;
	}   //  getHome

	/**
	 *  Get Support Email
	 *  @return Support mail address
	 */
	public static String getSupportEMail()
	{
		return s_supportEmail;
	}   //  getSupportEMail

	/**
	 *  Set Support Email
	 *  @param email Support mail address
	 */
	public static void setSupportEMail(String email)
	{
		s_supportEmail = email;
	}   //  setSupportEMail

	/*************************************************************************/

	/**
	 *  Startup Client.
	 *  - Print greeting,
	 *  - Check Java version and
	 *  - load ini parameters
	 *  If it is a client, load/set PLAF and exit if error
	 *
	 *  @return successful startup
	 */
	public static boolean startupClient ()
	{
		//	Already started
		if (s_log != null)
			return true;

		//	Init Log
		s_log = Logger.getLogger(Compiere.class);
		LogManager.resetConfiguration();
		Logger root = Logger.getRootLogger();
	//	root.addAppender(new ConsoleAppender(new PatternLayout("%d{ABSOLUTE} %-5p [%c{1}] %m%n")));
		root.addAppender(new ConsoleAppender(new LogLayout()));
		root.setLevel(Level.ALL);
		//	Greeting
		s_log.info(getSummaryAscii());

		//	Get Defaults
		Ini.setClient (true);
		//	Check Version
		if (!Env.isJavaOK())
			System.exit(1);

		//  Load System environment
	//	EnvLoader.load(Ini.ENV_PREFIX);

		//	Set XML environment explicitly to standard 1.4.0 distribution
		System.setProperty("javax.xml.parsers.DocumentBuilderFactory",
			"org.apache.crimson.jaxp.DocumentBuilderFactoryImpl");	//	System Default
		//	"org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");
		System.setProperty("javax.xml.parsers.SAXParserFactory",
			"org.apache.crimson.jaxp.SAXParserFactoryImpl");	//	System Default
		//	"org.apache.xerces.jaxp.SAXParserFactoryImpl");

		//  System properties
		Ini.loadProperties (false);
		//	Set Log (use defaults)
		Log.initLog();

		//	Set UI
		CompiereTheme.load();
		CompierePLAF.setPLAF (null);

		//  Set Default Database Connection
		DB.setDBTarget(CConnection.get());
		return true;
	}   //  startupClient

	/**
	 *  Startup Server.
	 *  - Print greeting,
	 *  - Check Java version and
	 *  - load ini parameters
	 *
	 *  @param context context
	 *  @return successful startup
	 */
	public static boolean startupServer (Context context)
	{
		//	Already started
		if (s_log != null && Ini.isLoaded())
			return true;

		//	Init Log
		s_log = Logger.getLogger(Compiere.class);
		//	Greeting
		s_log.info(getSummaryAscii());

		//	Get Defaults
		Ini.setClient (false);
		//	Check Version
		Env.isJavaOK();
		//  Load System environment
	//	EnvLoader.load(Ini.ENV_PREFIX);

		//	Set XML environment explicitly to standard 1.4.0 distribution
		System.setProperty("javax.xml.parsers.DocumentBuilderFactory",
			"org.apache.crimson.jaxp.DocumentBuilderFactoryImpl");	//	System Default
		//	"org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");
		System.setProperty("javax.xml.parsers.SAXParserFactory",
			"org.apache.crimson.jaxp.SAXParserFactoryImpl");	//	System Default
		//	"org.apache.xerces.jaxp.SAXParserFactoryImpl");

		//  System properties
		Ini.loadProperties (false);
		//	Set Log (use defaults)
		Log.initLog();

		//  Set Default Database Connection from Ini
		CConnection cc = CConnection.get();
		DB.setDBTarget(cc);
		//
		if (context != null)
			cc.setDataSource (context, Ini.getProperty(Ini.P_CONTEXT));
		if (!cc.isDataSource())
		{
			s_log.warn("startupServer - no DataSource");
			return false;
		}
		//
		return true;
	}   //  startupServer

	/**
	 *  Main Method
	 *
	 *  @param args optional start class
	 */
	public static void main (String[] args)
	{
		Splash.getSplash();
		startupClient ();     //  error exit and initUI

		//  Start with class as argument - or if nothing provided with Client
		String className = "org.compiere.apps.AMenu";
		for (int i = 0; i < args.length; i++)
		{
			if (!args[i].equals("-debug"))  //  ignore -debug
			{
				className = args[i];
				break;
			}
		}
		//
		try
		{
			Class startClass = Class.forName(className);
			startClass.newInstance();
		}
		catch (Exception e)
		{
			System.err.println("Cannot start: " + className + " - " + e.toString());
			e.printStackTrace();
		}
	}   //  main
}	//	Compiere

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -