1 22 package org.jboss.repository.plugins; 23 24 import java.util.Iterator ; 25 import java.util.Map ; 26 import java.util.HashMap ; 27 28 import org.jboss.repository.spi.KernelRepository; 29 import org.jboss.repository.spi.MetaDataCombiner; 30 import org.jboss.repository.spi.Key; 31 import org.jboss.repository.spi.MetaData; 32 import org.jboss.repository.spi.MetaDataLoader; 33 import org.jboss.repository.spi.CommonNames; 34 35 41 public class AbstractKernelRepository 42 implements KernelRepository 43 { 44 private Map repository = new HashMap (103); 45 private Map domainMap = new HashMap (103); 46 private Map clusterMap = new HashMap (103); 47 private Map serverMap = new HashMap (103); 48 private Map appMap = new HashMap (103); 49 private Map deployMap = new HashMap (103); 50 private Map sessionMap = new HashMap (103); 51 private Map maps[] = { 52 domainMap, 53 clusterMap, 54 serverMap, 55 appMap, 56 deployMap, 57 sessionMap 58 }; 59 60 private MetaDataCombiner combiner; 61 62 public AbstractKernelRepository(MetaDataCombiner combiner) 63 throws Exception 64 { 65 super(); 66 this.combiner = combiner; 67 } 68 69 public Object getMetaData(Key key) 70 { 71 return getMetaData(key, combiner); 72 } 73 74 82 public Object getMetaData(Key key, MetaDataCombiner combiner) 83 { 84 Map attributes = key.getAttributes(); 86 HashMap tmp = new HashMap (); 87 MetaData[] levelData = new MetaData[CommonNames.N_LEVELS]; 88 int level = key.getLevel(); 89 for(int n = 0; n <= level; n ++) 90 { 91 String levelKey = CommonNames.LEVELS[n]; 92 String value = (String ) attributes.get(levelKey); 93 tmp.put(levelKey, value); 94 Key tmpKey = new Key(key.getName(), tmp); 95 levelData[n] = (MetaData) maps[n].get(tmpKey); 96 } 97 98 return combiner.combine(key, levelData); 99 } 100 101 106 public Map getAllMetaData(Key key) 107 { 108 HashMap levelData = new HashMap (); 109 Map attributes = key.getAttributes(); 110 HashMap tmp = new HashMap (); 111 int level = key.getLevel(); 112 for(int n = 0; n <= level; n ++) 113 { 114 String levelKey = CommonNames.LEVELS[n]; 115 String value = (String ) attributes.get(levelKey); 116 tmp.put(levelKey, value); 117 Key tmpKey = new Key(key.getName(), tmp); 118 MetaData data = (MetaData) maps[n].get(tmpKey); 119 if( data != null ) 120 levelData.put(tmpKey, data); 121 } 122 123 return levelData; 124 } 125 126 public synchronized MetaData addMetaData(Key key, MetaData data) 127 { 128 MetaData prev = (MetaData) repository.put(key, data); 129 int level = key.getLevel(); 131 maps[level].put(key, data); 132 return prev; 133 } 134 public MetaData removeMetaData(Key key) 135 { 136 int level = key.getLevel(); 137 MetaData prev = (MetaData) maps[level].remove(key); 138 repository.remove(key); 139 return prev; 140 } 141 142 public void loadMetaData(MetaDataLoader loader) 143 { 144 Iterator keys = loader.getKeys(); 145 while( keys.hasNext() ) 146 { 147 Key key = (Key) keys.next(); 148 MetaData data = loader.load(key); 149 int level = key.getLevel(); 150 maps[level].put(key, data); 151 } 152 } 153 154 public Iterator getKeyNames() 155 { 156 return repository.keySet().iterator(); 157 } 158 159 165 public Iterator findKeys(String nameRE, Map attributes) 166 { 167 return null; 168 } 169 170 } 171 | Popular Tags |