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

📄 enhproperties.java

📁 Java的面向对象数据库系统的源代码
💻 JAVA
字号:
// You can redistribute this software and/or modify it under the terms of// the Infozone Software License version 2 published by the Infozone Group// (http://www.infozone-group.org).//// Copyright (C) @year@ by The Infozone Group. All rights reserved.//// $Id: EnhProperties.java,v 1.2 2003/03/12 12:30:26 per_nyfelt Exp $package org.infozone.tools;import java.io.*;import java.util.*;/**EnhProperties has methods to store/update the value of a property to handlesuch dynamic properties.<p>In addition the Properties EnhProperties can hold not only String propertiesbut most of other primitive types and raw objects. Non-string properties areinternaly stored as Strings.<p>Setup extends java.util.Properties. So the system properties can be used asdefaults.@author <a href="http://www.softwarebuero.de/">SMB</a>@version $Revision: 1.2 $Date: 2003/03/12 12:30:26 $*/public class EnhProperties extends Properties {    /**    An Observable object that is responsible for this properties. Directly    extending the class is not possible because it already extends Properties.    */    protected EnhObservable	observable;    public EnhProperties() {        observable = new EnhObservable();        }    public EnhProperties (Properties _defaults) {        super (_defaults);        observable = new EnhObservable();        }    public void addObserver (Observer _observer) {        observable.addObserver (_observer);        }    public void removeObserver (Observer _observer) {        observable.deleteObserver (_observer);        }    public void notifyObservers() {        observable.notifyObservers (this);        }    public boolean hasChanged() {        return observable.hasChanged();        }    /**    @param properties    @param keyPrefix    */    public void addProperties (Properties properties, String keyPrefix) {        observable.setChanged();        for (Enumeration e=properties.keys(); e.hasMoreElements();) {            String key = (String)e.nextElement();            if (key.startsWith (keyPrefix)) {               // System.out.println (key);                String val = properties.getProperty (key, "");                setStringProperty (key, val);                }            }        }    /**    @param _val    @param _key    */    public synchronized void setStringProperty (String _key, String _val) {        observable.setChanged();        super.put (_key, _val);        }    /**    @param _key    @param _default The default value to use if no property is found.    */    public String stringProperty (String _key, String _default) {        return super.getProperty (_key, _default);        }    /**    @param _key    @param _default The default value to use if no property is found.    */    public String[] stringsProperty (String _key, String _default) {        String propList = stringProperty( _key, _default );        Vector v = new Vector();        StringTokenizer st = new StringTokenizer( propList, " \t,", false );        while (st.hasMoreTokens()) {            String token = st.nextToken();           // System.out.println ("'" + token + "'");            v.addElement( token );        }        String[] result = new String[v.size()];        v.copyInto( result );        return result;        }    /**    @param _val    @param _key    */    public void setProperty (String _key, Object _val) {        observable.setChanged();        try {            ByteArrayOutputStream buf = new ByteArrayOutputStream (1024);            ObjectOutputStream out = new ObjectOutputStream (buf);            out.writeObject (_val);            out.close();            MimeBase64Encoder encoder = new MimeBase64Encoder();            encoder.translate (buf.toByteArray());            setStringProperty (_key, new String (encoder.getCharArray()));            }        catch (Exception e) {            throw new RuntimeException (e.getMessage());            }        }    /**    @param _key    @param _default The default value to use if no property is found.    */    public Object property (String _key, Object _default) {        try {            String result = stringProperty (_key, (String)_default);            if (result != null) {                MimeBase64Decoder decoder = new MimeBase64Decoder();                decoder.translate (result.toCharArray());                ObjectInputStream in = new ResolvingObjectInputStream (new ByteArrayInputStream (decoder.getByteArray()));                return in.readObject();                }            else                return null;            }        catch (Exception e) {            throw new RuntimeException (e.getMessage());            }        }    /**    @param _val    @param _key    */    public void setIntProperty (String _key, int _val) {        setStringProperty (_key, String.valueOf (_val));        }    /**    @param _key    @param _default The default value to use if no property is found.    */    public int intProperty (String _key, int _default) {        String result = stringProperty (_key, String.valueOf (_default));        return Integer.parseInt (result);        }    /**    @param _key    @param _default The default value to use if no property is found.    */    public long longProperty (String _key, long _default) {        String result = stringProperty (_key, String.valueOf (_default));        return Long.valueOf (result).longValue();        }    /**    @param _key    @param _default The default value to use if no property is found.    */    public boolean booleanProperty (String _key, boolean _default) {        String result = stringProperty (_key, String.valueOf (_default));        return Boolean.valueOf (result).booleanValue();        }    /**    @param _val    @param _key    */    public void setLongProperty (String _key, long _val) {        setStringProperty (_key, String.valueOf (_val));        }    /**    @param _val    @param _key    */    public void setBooleanProperty (String _key, boolean _val) {        setStringProperty (_key, String.valueOf (_val));        }    /**    @param    @param keyPrefix    @param printPrefix    *///    public void print (PrintStream out, String keyPrefix, String printPrefix) {//        DxTreeSet sortedProps = new DxTreeSet (new DxStringComparator());//        for (Enumeration e=propertyNames(); e.hasMoreElements();) {//            String key = (String)e.nextElement();//            String val = stringProperty (key, "(not set)");//            //avoid printing "object" properties//            //currently not supported!!!//            if (key.startsWith (keyPrefix) && !val.startsWith("[object]")) {//                sortedProps.add (printPrefix + key + " = " + val);//                }//            }//        for (DxIterator it=sortedProps.iterator(); it.next()!=null;)//            out.println (it.object().toString());//        }    }/**@author <a href="http://www.softwarebuero.de/">SMB</a>@version $Revision: 1.2 $Date: 2003/03/12 12:30:26 $*/class EnhObservable extends Observable {   public EnhObservable() {       super();       }   public void setChanged() {       super.setChanged();       }   }

⌨️ 快捷键说明

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