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

📄 nameregistrar.java

📁 POS is a Java&#174 platform-based, mission-critical, ISO-8583 based financial transaction library/fr
💻 JAVA
字号:
/* * jPOS Project [http://jpos.org] * Copyright (C) 2000-2008 Alejandro P. Revilla * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program.  If not, see <http://www.gnu.org/licenses/>. */package org.jpos.util;import java.io.PrintStream;import java.util.Hashtable;import java.util.Iterator;import java.util.Map;/** * Allow runtime binding of jPOS's components (ISOChannels, Logger, MUXes, etc) * @author <a href="mailto:apr@cs.com.uy">Alejandro P. Revilla</a> * @version $Revision: 2594 $ $Date: 2008-01-22 14:41:31 -0200 (Tue, 22 Jan 2008) $ */public class NameRegistrar implements Loggeable {    private static NameRegistrar instance = new NameRegistrar();    private Map registrar;    public static class NotFoundException extends Exception {        private static final long serialVersionUID = 8744022794646381475L;        public NotFoundException() {            super();        }        public NotFoundException(String detail) {            super(detail);        }    }    private NameRegistrar() {        super();        registrar = new Hashtable();    }    public static Map getMap() {        return getInstance().registrar;    }    /**     * @return singleton instance     */    public static NameRegistrar getInstance() {        return instance;    }    /**     * register object     * @param key - key with which the specified value is to be associated.     * @param value - value to be associated with the specified key     */    public static void register (String key, Object value) {        Map map = getMap();        synchronized (map) {            map.put (key, value);        }    }    /**     * @param key key whose mapping is to be removed from registrar.     */    public static void unregister (String key) {        Map map = getMap();        synchronized (map) {            map.remove (key);        }    }    /**     * @param key key whose associated value is to be returned.     * @throws NotFoundException if key not present in registrar     */    public static Object get (String key) throws NotFoundException {        Object obj = getMap().get(key);        if (obj == null)            throw new NotFoundException (key);        return obj;    }    /**     * @param key key whose associated value is to be returned.     * @throws NotFoundException if key not present in registrar     */    public static Object getIfExists (String key) {        return getMap().get(key);    }    public void dump (PrintStream p, String indent) {        dump(p,indent,false);    }    public void dump (PrintStream p, String indent, boolean detail) {        String inner = indent + "  ";        p.println (indent + "--- name-registrar ---");        synchronized (registrar) {            Iterator iter = registrar.entrySet().iterator();            while (iter.hasNext()) {                Map.Entry entry = (Map.Entry) iter.next ();                Object obj = entry.getValue();                p.println (inner +                     entry.getKey().toString() + ": " +                    obj.getClass().getName()                );                if ((detail == true) && (obj instanceof Loggeable)) {                    ((Loggeable)obj).dump(p, inner+"  ");                }            }        }    }}

⌨️ 快捷键说明

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