1 17 package org.apache.geronimo.security.deploy; 18 19 import java.beans.PropertyEditorManager ; 20 import java.io.ByteArrayInputStream ; 21 import java.io.IOException ; 22 import java.util.Arrays ; 23 import java.util.HashMap ; 24 import java.util.HashSet ; 25 import java.util.Iterator ; 26 import java.util.Map ; 27 import java.util.Properties ; 28 import java.util.Set ; 29 30 import org.apache.geronimo.common.propertyeditor.PropertyEditorException; 31 import org.apache.geronimo.common.propertyeditor.TextPropertyEditorSupport; 32 33 36 public class MapOfSets extends HashMap { 37 38 public MapOfSets() { 39 super(); 40 } 41 42 public MapOfSets(int size) { 43 super(size); 44 } 45 46 public MapOfSets(Map map) { 47 super(map); 48 } 49 50 static { 51 PropertyEditorManager.registerEditor(MapOfSets.class, MapOfSetsEditor.class); 52 } 53 54 public static class MapOfSetsEditor extends TextPropertyEditorSupport { 55 56 public void setAsText(String text) { 57 if (text != null) { 58 try { 59 ByteArrayInputStream is = new ByteArrayInputStream (text.getBytes()); 60 Properties p = new Properties (); 61 p.load(is); 62 63 Map result = new MapOfSets(p.size()); 64 for (Iterator iterator = p.entrySet().iterator(); iterator.hasNext();) { 65 Map.Entry entry = (Map.Entry ) iterator.next(); 66 Set values = new HashSet (Arrays.asList(((String ) entry.getValue()).split(","))); 67 result.put(entry.getKey(), values); 68 } 69 setValue(result); 70 } catch (IOException e) { 71 throw new PropertyEditorException(e); 72 } 73 } else { 74 setValue(null); 75 } 76 } 77 78 public String getAsText() { 79 Map map = (Map ) getValue(); 80 if (map == null) { 81 return null; 82 } 83 StringBuffer text = new StringBuffer (); 84 for (Iterator iterator = map.entrySet().iterator(); iterator.hasNext();) { 85 Map.Entry entry = (Map.Entry ) iterator.next(); 86 text.append(entry.getKey()).append("="); 87 Set values = (Set ) entry.getValue(); 88 for (Iterator iterator1 = values.iterator(); iterator1.hasNext();) { 89 String value = (String ) iterator1.next(); 90 text.append(value); 91 if (iterator1.hasNext()) { 92 text.append(","); 93 } 94 } 95 } 96 return text.toString(); 97 } 98 99 } 100 } 101 | Popular Tags |