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

📄 environment.java

📁 Java Communicating Agents是一个用于开发网络反应式信息agent的框架
💻 JAVA
字号:
/* * $Source: /home/data/cvsroot/src/jacomma/util/Environment.java,v $ * $Revision: 1.11 $ * $Date: 2000/10/28 20:09:08 $ * * This file is part of the jacomma framework * Copyright (c) 2000 	Dimitrios Vyzovitis *			mailto:dviz@egnatia.ee.auth.gr *			 * *			 *			 *			 * *	This library is free software; you can redistribute it and/or modify *	it under the terms of the GNU Library General Public License as published by *	the Free Software Foundation; either version 2 of the License, or *	(at your option) any later version. * *	This library 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 Library General Public License for more details. * *	You should have received a copy of the GNU Library General Public License *	along with this library; if not, write to the Free Software *	Foundation, Inc., 59 Temple Place, Suite 330,  *	Boston, MA  02111-1307  USA */package jacomma.util;import java.net.URL;/** * TBA **/public final class Environment {	public static final boolean DEBUG;		static final Cache lpcache_;	static final java.util.Hashtable prop_;	static {		DEBUG = true;		lpcache_ = new Cache();		prop_ = loadProperties( Environment.class );	}	public static Object setProperty( String key, Object val ) {		return prop_.put( key, val );	}		public static Object getProperty( String key ) {		return prop_.get( key );	}	public synchronized static final void outp( Object obj ) {		if ( DEBUG ) {			System.out.println( new java.util.Date() + ":" + Thread.currentThread() 								+ ":" + obj );			System.out.flush();		}	}		public static void assert( boolean b, String msg ) {		if ( DEBUG && !b ) {			outp( msg + ": Assertion failed!" );			throw new RuntimeException( "Assertion failed!" );		}	}		public static final Object newInstance( String c ) {		try {			return Class.forName( c ).newInstance();		} catch ( ClassNotFoundException exc ) {			throw new CheckedException( exc );		} catch ( InstantiationException exc ) {			throw new CheckedException( exc );		} catch ( IllegalAccessException exc ) {			throw new CheckedException( exc );		}	}	public static final Object newInstance( Class c ) {		try {			return c.newInstance();		} catch ( InstantiationException exc ) {			throw new CheckedException( exc );		} catch ( IllegalAccessException exc ) {			throw new CheckedException( exc );		}	}		public static final Object newRegistry( Class c ) {		try {			java.util.Properties p = loadProperties( c );			Object r = Class.forName( p.getProperty( "registry" ) ).newInstance();			r.getClass().getMethod( "load", new Class[]{java.util.Properties.class} ).invoke( r, new Object[]{p} );						return r;		} catch ( RuntimeException exc ) {			throw exc;		} catch ( Exception exc ) {			throw new CheckedException( exc );		}	}	public static final Object newSingleton( Class c ) {		try {			java.util.Properties p = loadProperties( c );			Object r = Class.forName( p.getProperty( "instance" ) ).newInstance();			r.getClass().getMethod( "load", new Class[]{java.util.Properties.class} ).invoke( r, new Object[]{p} );						return r;		} catch ( RuntimeException exc ) {			throw exc;		} catch ( Exception exc ) {			throw new CheckedException( exc );		}	}	public static java.util.Properties loadProperties( Class c ) {		try {			java.util.Properties p = (java.util.Properties)lpcache_.get( c );			if ( p == null ) {				p = new java.util.Properties();				String f = "/resources/" 					+ c.getName().replace( '.', '/' ) 					+ ".properties";								java.io.InputStream sin = c.getResourceAsStream( f );												p.load( sin );				sin.close();				lpcache_.put( c, p );			}			return p;		} catch ( java.io.IOException exc ) {			exc.printStackTrace();			throw new CheckedException( "Unable to load properties for "										+ c.getName()										+ " [" + exc.getMessage() + "]",										exc );		}	}	public static java.util.Properties reloadProperties( Class c ) {		try {			java.util.Properties p = new java.util.Properties();			String f = "/resources/" 				+ c.getName().replace( '.', '/' ) 				+ ".properties";						java.io.InputStream sin = c.getResourceAsStream( f );						p.load( sin );			sin.close();			lpcache_.put( c, p );						return p;		} catch ( java.io.IOException exc ) {			exc.printStackTrace();			throw new CheckedException( "Unable to load properties for "										+ c.getName()										+ " [" + exc.getMessage() + "]",										exc );		}	}	}

⌨️ 快捷键说明

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