001 /* 002 Copyright (C) 2001-2002 Laurent Martelli. 003 004 This program is free software; you can redistribute it and/or modify 005 it under the terms of the GNU Lesser General Public License as 006 published by the Free Software Foundation; either version 2 of the 007 License, or (at your option) any later version. 008 009 This program is distributed in the hope that it will be useful, 010 but WITHOUT ANY WARRANTY; without even the implied warranty of 011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 012 GNU Lesser General Public License for more details. 013 014 You should have received a copy of the GNU Lesser General Public License 015 along with this program; if not, write to the Free Software 016 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 017 018 package org.objectweb.jac.aspects.gui; 019 020 import java.util.Map; 021 import gnu.regexp.*; 022 023 /** 024 * This class is a mere wrapper which delegates all methods to a real 025 * Map. It allows you to have wrappable maps. 026 */ 027 028 public class WrappableMap 029 { 030 private Map delegate; 031 032 protected Map getDelegate() { 033 return delegate; 034 } 035 036 public WrappableMap(Map delegate) { 037 this.delegate = delegate; 038 } 039 040 /** 041 * Calls put on delegate for every key already in delegate which 042 * matches key. For instance, call with <code>put("gui.*",0)</code> 043 * will turn off all gui traces. 044 * @param key regexp key 045 * @param value trace level 046 */ 047 048 public void put ( String key, Integer value ) 049 throws REException 050 { 051 Object keys[] = delegate.keySet().toArray(); 052 RE re = new RE(key); 053 for (int i=0; i<keys.length;i++) { 054 String cur_key = (String)keys[i]; 055 if (re.isMatch(cur_key)) 056 delegate.put(cur_key, value); 057 } 058 } 059 060 public void clear ( ) { 061 delegate.clear(); 062 } 063 064 public Object remove ( String key ) { 065 return delegate.remove(key); 066 } 067 068 static public String[] getCategories(WrappableMap wmap ) { 069 java.util.Set keys = wmap.getDelegate().keySet(); 070 String[] result = new String[keys.size()]; 071 java.util.Iterator i = keys.iterator(); 072 int j=0; 073 while (i.hasNext()) { 074 result[j++] = (String)i.next(); 075 } 076 return result; 077 } 078 079 static public Integer[] getLevels(WrappableMap wmap) { 080 return new Integer[] {new Integer(0),new Integer(1), 081 new Integer(2),new Integer(3)}; 082 } 083 }