




已阅读5页,还剩55页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
package org.jfree.base.config;import java.util.Enumeration;import java.util.Iterator;import org.jfree.util.Configuration;public abstract interface ModifiableConfiguration extends Configuration public abstract void setConfigProperty(String paramString1, String paramString2); public abstract Enumeration getConfigProperties(); public abstract Iterator findPropertyKeys(String paramString);package org.jfree.base.config;import java.util.Enumeration;import java.util.Properties;import java.util.Vector;public class SystemPropertyConfiguration extends HierarchicalConfiguration public void setConfigProperty(String key, String value) throw new UnsupportedOperationException(The SystemPropertyConfiguration is readOnly); public String getConfigProperty(String key, String defaultValue) try String value = System.getProperty(key); if (value != null) return value; catch (SecurityException se) return super.getConfigProperty(key, defaultValue); public boolean isLocallyDefined(String key) try return System.getProperties().containsKey(key); catch (SecurityException se) return false; public Enumeration getConfigProperties() try return System.getProperties().keys(); catch (SecurityException se) return new Vector().elements(); package org.jfree.base.config;import java.io.BufferedInputStream;import java.io.IOException;import java.io.InputStream;import java.util.Properties;import org.jfree.util.Log;import org.jfree.util.ObjectUtilities;public class PropertyFileConfiguration extends HierarchicalConfiguration public void load(String resourceName) load(resourceName, PropertyFileConfiguration.class); public void load(String resourceName, Class resourceSource) InputStream in = ObjectUtilities.getResourceRelativeAsStream(resourceName, resourceSource); if (in != null) try load(in); finally try in.close(); catch (IOException e) else Log.debug(Configuration file not found in the classpath: + resourceName); public void load(InputStream in) if (in = null) throw new NullPointerException(); try BufferedInputStream bin = new BufferedInputStream(in); Properties p = new Properties(); p.load(bin); getConfiguration().putAll(p); bin.close(); catch (IOException ioe) Log.warn(Unable to read configuration, ioe); package org.jfree.base.log;import org.jfree.util.Log;import org.jfree.util.LogTarget;import org.jfree.util.PrintStreamLogTarget;public class DefaultLog extends Log private static final PrintStreamLogTarget DEFAULT_LOG_TARGET = new PrintStreamLogTarget(); private static final DefaultLog defaultLogInstance = new DefaultLog(); public void init() removeTarget(DEFAULT_LOG_TARGET); String logLevel = LogConfiguration.getLogLevel(); if (logLevel.equalsIgnoreCase(error) setDebuglevel(0); else if (logLevel.equalsIgnoreCase(warn) setDebuglevel(1); else if (logLevel.equalsIgnoreCase(info) setDebuglevel(2); else if (logLevel.equalsIgnoreCase(debug) setDebuglevel(3); public synchronized void addTarget(LogTarget target) super.addTarget(target); if (target != DEFAULT_LOG_TARGET) removeTarget(DEFAULT_LOG_TARGET); public static DefaultLog getDefaultLog() return defaultLogInstance; public static void installDefaultLog() Log.defineLog(defaultLogInstance); static defaultLogInstance.addTarget(DEFAULT_LOG_TARGET); try String property = System.getProperty(org.jfree.DebugDefault, false); if (Boolean.valueOf(property).booleanValue() defaultLogInstance.setDebuglevel(3); else defaultLogInstance.setDebuglevel(1); catch (SecurityException se) defaultLogInstance.setDebuglevel(1); package org.jfree.base.log;import org.jfree.base.modules.AbstractModule;import org.jfree.base.modules.ModuleInitializeException;import org.jfree.base.modules.SubSystem;import org.jfree.util.Configuration;import org.jfree.util.Log;import org.jfree.util.PrintStreamLogTarget;public class DefaultLogModule extends AbstractModule public DefaultLogModule() throws ModuleInitializeException loadModuleInfo(); public void initialize(SubSystem subSystem) throws ModuleInitializeException if (LogConfiguration.isDisableLogging() return; if (LogConfiguration.getLogTarget().equals(PrintStreamLogTarget.class.getName() DefaultLog.installDefaultLog(); Log.getInstance().addTarget(new PrintStreamLogTarget(); if (true.equals(subSystem.getGlobalConfig().getConfigProperty(org.jfree.base.LogAutoInit) Log.getInstance().init(); L(Default log target started previous log messages could have been ignored.); package org.jfree.base.log;import org.jfree.base.AbstractBoot;import org.jfree.base.BaseBoot;import org.jfree.base.config.ModifiableConfiguration;import org.jfree.util.Configuration;import org.jfree.util.PrintStreamLogTarget;public class LogConfiguration public static final String DISABLE_LOGGING_DEFAULT = false; public static final String LOGLEVEL = org.jfree.base.LogLevel; public static final String LOGLEVEL_DEFAULT = Info; public static final String LOGTARGET = org.jfree.base.LogTarget; public static final String LOGTARGET_DEFAULT = PrintStreamLogTarget.class.getName(); public static final String DISABLE_LOGGING = org.jfree.base.NoDefaultDebug; public static String getLogTarget() return BaseBoot.getInstance().getGlobalConfig().getConfigProperty(org.jfree.base.LogTarget, LOGTARGET_DEFAULT); public static void setLogTarget(String logTarget) BaseBoot.getConfiguration().setConfigProperty(org.jfree.base.LogTarget, logTarget); public static String getLogLevel() return BaseBoot.getInstance().getGlobalConfig().getConfigProperty(org.jfree.base.LogLevel, Info); public static void setLogLevel(String level) BaseBoot.getConfiguration().setConfigProperty(org.jfree.base.LogLevel, level); public static boolean isDisableLogging() return BaseBoot.getInstance().getGlobalConfig().getConfigProperty(org.jfree.base.NoDefaultDebug, false).equalsIgnoreCase(true); public static void setDisableLogging(boolean disableLogging) BaseBoot.getConfiguration().setConfigProperty(org.jfree.base.NoDefaultDebug, String.valueOf(disableLogging); package org.jfree.base.log;import java.util.Arrays;public class PadMessage private final Object text; private final int length; public PadMessage(Object message, int length) this.text = message; this.length = length; public String toString() StringBuffer b = new StringBuffer(); b.osend(this.text); if (b.length() this.length) char pad = new charthis.length - b.length(); Arrays.fill(pad, ); b.osend(pad); return b.toString(); package org.jfree.base.modules;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.util.ArrayList;import org.jfree.util.ObjectUtilities;public abstract class AbstractModule extends DefaultModuleInfo implements Module private ModuleInfo requiredModules; private ModuleInfo optionalModules; private String name; private String description; private String producer; private String subsystem; public AbstractModule() setModuleClass(getClass().getName(); protected void loadModuleInfo() throws ModuleInitializeException InputStream in = ObjectUtilities.getResourceRelativeAsStream(perties, getClass(); if (in = null) throw new ModuleInitializeException(File perties not found in module package.); loadModuleInfo(in); protected void loadModuleInfo(InputStream in) throws ModuleInitializeException if (in = null) throw new NullPointerException(Given InputStream is null.); try ArrayList optionalModules = new ArrayList(); ArrayList dependendModules = new ArrayList(); ReaderHelper rh = new ReaderHelper(new BufferedReader(new InputStreamReader(in, ISO-8859-1); try while (rh.hasNext() String lastLineRead = rh.next(); if (lastLineRead.startsWith(module-info:) readModuleInfo(rh); else if (lastLineRead.startsWith(depends:) dependendModules.add(readExternalModule(rh); else if (lastLineRead.startsWith(optional:) optionalModules.add(readExternalModule(rh); finally rh.close(); this.optionalModules = (ModuleInfo)optionalModules.toArray(new ModuleInfooptionalModules.size(); this.requiredModules = (ModuleInfo)dependendModules.toArray(new ModuleInfodependendModules.size(); catch (IOException ioe) throw new ModuleInitializeException(Failed to load properties, ioe); private String readValue(ReaderHelper reader, String firstLine) throws IOException StringBuffer b = new StringBuffer(firstLine.trim(); boolean newLine = true; while (isNextLineValueLine(reader) firstLine = reader.next(); String trimedLine = firstLine.trim(); if (trimedLine.length() = 0) & (!newLine) b.osend(n); newLine = true; else if (!newLine) b.osend( ); b.osend(parseValue(trimedLine); newLine = false; return b.toString(); private boolean isNextLineValueLine(ReaderHelper reader) throws IOException if (!reader.hasNext() return false; String firstLine = reader.next(); if (firstLine = null) return false; if (parseKey(firstLine) != null) reader.pushBack(firstLine); return false; reader.pushBack(firstLine); return true; private void readModuleInfo(ReaderHelper reader) throws IOException while (reader.hasNext() String lastLineRead = reader.next(); if (!Character.isWhitespace(lastLineRead.charAt(0) reader.pushBack(lastLineRead); return; String line = lastLineRead.trim(); String key = parseKey(line); if (key != null) String b = readValue(reader, parseValue(line.trim(); if (name.equals(key) setName(b); else if (producer.equals(key) setProducer(b); else if (description.equals(key) setDescription(b); else if (subsystem.equals(key) setSubSystem(b); else if (version.major.equals(key) setMajorVersion(b); else if (version.minor.equals(key) setMinorVersion(b); else if (version.patchlevel.equals(key) setPatchLevel(b); private String parseKey(String line) int idx = line.indexOf(:); if (idx = -1) return null; return line.substring(0, idx); private String parseValue(String line) int idx = line.indexOf(:); if (idx = -1) return line; if (idx + 1 = line.length() return ; return line.substring(idx + 1); private DefaultModuleInfo readExternalModule(ReaderHelper reader) throws IOException DefaultModuleInfo mi = new DefaultModuleInfo(); while (reader.hasNext() String lastLineRead = reader.next(); if (!Character.isWhitespace(lastLineRead.charAt(0) reader.pushBack(lastLineRead); return mi; String line = lastLineRead.trim(); String key = parseKey(line); if (key != null) String b = readValue(reader, parseValue(line); if (module.equals(key) mi.setModuleClass(b); else if (version.major.equals(key) mi.setMajorVersion(b); else if (version.minor.equals(key) mi.setMinorVersion(b); else if (version.patchlevel.equals(key) mi.setPatchLevel(b); return mi; public String getName() return ; protected void setName(String name) = name; public String getDescription() return this.description; protected void setDescription(String description) this.description = description; public String getProducer() return ducer; protected void setProducer(String producer) ducer = producer; public ModuleInfo getRequiredModules() ModuleInfo retval = new ModuleInfothis.requiredModules.length; System.arraycopy(this.requiredModules, 0, retval, 0, this.requiredModules.length); return retval; public ModuleInfo getOptionalModules() ModuleInfo retval = new ModuleInfothis.optionalModules.length; System.arraycopy(this.optionalModules, 0, retval, 0, this.optionalModules.length); return retval; protected void setRequiredModules(ModuleInfo requiredModules) this.requiredModules = new ModuleInforequiredModules.length; System.arraycopy(requiredModules, 0, this.requiredModules, 0, requiredModules.length); public void setOptionalModules(ModuleInfo optionalModules) this.optionalModules = new ModuleInfooptionalModules.length; System.arraycopy(optionalModules, 0, this.optionalModules, 0, optionalModules.length); public String toString() StringBuffer buffer = new StringBuffer(); buffer.osend(Module : ); buffer.osend(getName(); buffer.osend(n); buffer.osend(ModuleClass : ); buffer.osend(getModuleClass(); buffer.osend(n); buffer.osend(Version: ); buffer.osend(getMajorVersion(); buffer.osend(.); buffer.osend(getMinorVersion(); buffer.osend(.); buffer.osend(getPatchLevel(); buffer.osend(n); buffer.osend(Producer: ); buffer.osend(getProducer(); buffer.osend(n); buffer.osend(Description: ); buffer.osend(getDescription(); buffer.osend(n); return buffer.toString(); /* deprecated */ protected static boolean isClassLoadable(String name) try ClassLoader loader = ObjectUtilities.getClassLoader(AbstractModule.class); if (loader = null) return false; loader.loadClass(name); return true; catch (Exception e) return false; protected static boolean isClassLoadable(String name, Class context) try ObjectUtilities.getClassLoader(context).loadClass(name); return true; catch (Exception e) return false; public void configure(SubSystem subSystem) InputStream in = ObjectUtilities.getResourceRelativeAsStream(perties, getClass(); if (in = null) return; try subSystem.getPackageManager().getPackageConfiguration().load(in); finally try in.close(); catch (IOException e) /* deprecated */ protected void performExternalInitialize(String classname) throws ModuleInitializeException try ModuleInitializer mi = (ModuleInitializer)ObjectUtilities.loadAndInstantiate(classname, AbstractModule.class, ModuleInitializer.class); if (mi = null) throw new ModuleInitializeException(Failed to load specified initializer class.); mi.performInit(); catch (ModuleInitializeException mie) throw mie; catch (Exception e) throw new ModuleInitializeException(Failed to load specified initializer class., e); protected void performExternalInitialize(String classname, Class context) throws ModuleInitializeException try ModuleInitializer mi = (ModuleInitializer)ObjectUtilities.loadAndInstantiate(classname, context, ModuleInitializer.class); if (mi = null) throw new ModuleInitializeException(Failed to load specified initializer class.); mi.performInit(); catch (ModuleInitializeException mie) throw mie; catch (Exception e)
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 南大校区围堰工程施工方案
- 民宿管理面试题库及答案
- 2025年教师招聘之《小学教师招聘》题库必刷100题含答案详解【典型题】
- 教师招聘之《小学教师招聘》综合提升试卷及答案详解【考点梳理】
- 2025年教师招聘之《幼儿教师招聘》每日一练试卷附参考答案详解(夺分金卷)
- 2025年教师招聘之《幼儿教师招聘》每日一练试卷附参考答案详解(能力提升)
- 教师招聘之《小学教师招聘》综合提升练习试题含答案详解【黄金题型】
- 2025年艾梅乙培训试题(含答案)
- 共青餐饮联合整改措施
- 教师招聘之《幼儿教师招聘》考前冲刺练习试题含答案详解(巩固)
- 2024年秋季新统编版七年级上册道德与法治全册教案
- GB/T 37977.46-2024静电学第4-6 部分:特定应用中的标准试验方法腕带
- 《矿物岩石学》全套教学课件
- 不动产授权委托书样本
- 全国职业院校宠物营养学知识竞赛备考试题库(含答案)
- 休产假工作交接表
- 心理健康五年级上册北师大版第二课 交往从尊重开始 课件
- 护士自我管理规划
- 航海英语会话(一)
- 医疗器械关于生产和生产后信息评价(模板)
- 2023年度出版专业职业资格考试试题及参考答案初级
评论
0/150
提交评论