1 package org.apache.turbine.om; 2 3 18 19 import java.util.HashMap ; 20 import java.util.Map ; 21 22 import org.apache.turbine.Turbine; 23 import org.apache.turbine.services.pull.ApplicationTool; 24 import org.apache.turbine.util.pool.Recyclable; 25 26 33 public class OMTool implements ApplicationTool, Recyclable 34 { 35 private HashMap omMap; 37 38 43 44 private static Map pullMap = new HashMap (); 45 46 50 private RetrieverFactory omFactory; 51 52 public OMTool()throws Exception 53 { 54 omMap = new HashMap (); 55 String className = Turbine.getConfiguration() 56 .getString("tool.om.factory"); 57 } 60 61 64 public void init(Object runData) 65 { 66 } 68 69 73 public void refresh() 74 { 75 } 77 78 81 private class PullHelper 82 { 83 String omName; 84 85 private PullHelper(String omName) 86 { 87 this.omName = omName; 88 } 89 90 public Object setKey(String key) 91 throws Exception 92 { 93 Object om = null; 94 95 String inputKey = omName + key; 96 if (omMap.containsKey(inputKey)) 97 { 98 om = omMap.get(inputKey); 99 } 100 else 101 { 102 om = omFactory.getInstance(omName).retrieve(key); 103 omMap.put(inputKey, om); 104 } 105 106 return om; 107 } 108 } 109 110 public Object get(String omName) throws Exception 111 { 112 if (!pullMap.containsKey(omName)) 113 { 114 synchronized (this.getClass()) 118 { 119 pullMap.put(omName, new OMTool.PullHelper(omName)); 120 } 121 } 122 123 return pullMap.get(omName); 124 } 125 126 public Object get(String omName, String key) throws Exception 127 { 128 return ((OMTool.PullHelper) get(omName)).setKey(key); 129 } 130 131 132 public String getName() 133 { 134 return "om"; 135 } 136 137 138 140 private boolean disposed; 141 142 152 public void recycle() 153 { 154 disposed = false; 155 } 156 157 162 public void dispose() 163 { 164 omMap.clear(); 165 disposed = true; 167 } 168 169 173 public boolean isDisposed() 174 { 175 return disposed; 176 } 177 } 178 179 180 181 182 183 184 185 186 | Popular Tags |