1 18 package org.objectweb.util.monolog.wrapper.remote.lib; 19 20 import org.objectweb.util.monolog.Monolog; 21 import org.objectweb.util.monolog.api.Handler; 22 import org.objectweb.util.monolog.api.Level; 23 import org.objectweb.util.monolog.api.Logger; 24 import org.objectweb.util.monolog.api.MonologFactory; 25 import org.objectweb.util.monolog.api.TopicalLogger; 26 import org.objectweb.util.monolog.file.monolog.PropertiesConfAccess; 27 import org.objectweb.util.monolog.wrapper.remote.api.LoggerInfo; 28 import org.objectweb.util.monolog.wrapper.remote.api.MonologFactoryProxy; 29 30 import java.net.MalformedURLException ; 31 import java.net.UnknownHostException ; 32 import java.rmi.Naming ; 33 import java.rmi.RemoteException ; 34 import java.rmi.server.UnicastRemoteObject ; 35 import java.util.HashMap ; 36 import java.util.Map ; 37 import java.util.Properties ; 38 39 45 public class MonologFactoryProxyImpl 46 extends UnicastRemoteObject 47 implements MonologFactoryProxy { 48 49 private MonologFactory mf; 50 51 55 public MonologFactoryProxyImpl() throws RemoteException { 56 this(Monolog.initialize()); 57 } 58 59 64 public MonologFactoryProxyImpl(MonologFactory mf) throws RemoteException { 65 super(); 66 this.mf = mf; 67 } 68 69 77 public MonologFactoryProxyImpl(MonologFactory mf, String rmiName) throws RemoteException { 78 super(); 79 this.mf = mf; 80 register(rmiName); 81 } 82 83 89 public void register(String name) throws RemoteException { 90 try { 91 register(java.net.InetAddress.getLocalHost(), name); 92 } catch (UnknownHostException e) { 93 throw new RemoteException (e.getMessage()); 94 } 95 } 96 97 105 public void register(java.net.InetAddress host, String name) throws RemoteException { 106 try { 107 Naming.rebind("rmi://" + host + "/" + name,this); 108 } catch (MalformedURLException e) { 109 throw new RemoteException (e.getMessage()); 110 } 111 } 112 113 public boolean defineLevel(String name, int value) throws RemoteException { 114 return mf.defineLevel(name, value) != null; 115 } 116 117 public boolean defineLevel(String name, String value) 118 throws RemoteException { 119 return mf.defineLevel(name, value) != null; 120 } 121 122 public void removeLevel(String name) throws RemoteException { 123 mf.removeLevel(name); 124 } 125 126 public Level getLevel(String name) throws RemoteException { 127 return mf.getLevel(name); 128 } 129 130 public Level getLevel(int value) throws RemoteException { 131 return mf.getLevel(value); 132 } 133 134 public Level[] getLevels() throws RemoteException { 135 return mf.getLevels(); 136 } 137 138 public int compareTo(String levelname1, String levelname2) 139 throws RemoteException { 140 Level l1 = mf.getLevel(levelname1); 141 if (l1 == null) { 142 return Integer.MAX_VALUE; 143 } 144 Level l2 = mf.getLevel(levelname2); 145 if (l1 == null) { 146 return Integer.MIN_VALUE; 147 } 148 return l1.compareTo(l2); 149 } 150 151 public boolean createHandler(String hn, String handlertype) 152 throws RemoteException { 153 return mf.createHandler(hn, handlertype) != null; 154 } 155 156 public boolean removeHandler(String handlername) throws RemoteException { 157 return mf.removeHandler(handlername) == null; 158 } 159 160 public String [] getHandlerNames() throws RemoteException { 161 Handler[] hs = mf.getHandlers(); 162 String [] hns = new String [hs.length]; 163 for(int i=0; i<hs.length; i++) { 164 hns[i] = hs[i].getName(); 165 } 166 return hns; 167 } 168 169 public Map getHandlerAttributes(String handlername) throws RemoteException { 170 Handler h = mf.getHandler(handlername); 171 String [] ans = h.getAttributeNames(); 172 Map m = new HashMap (ans.length); 173 for(int i=0; i<ans.length; i++) { 174 m.put(ans[i], h.getAttribute(ans[i])); 175 } 176 return m; 177 } 178 179 public Map getAllHandlerAttributes() 180 throws RemoteException { 181 Handler[] hs = mf.getHandlers(); 182 Map m = new HashMap (hs.length); 183 for(int i=0; i<hs.length; i++) { 184 m.put(hs[i], getHandlerAttributes(hs[i].getName())); 185 } 186 return m; 187 } 188 189 public void setHandlerAttribute(String handlername, String attributeName, 190 String value) throws RemoteException { 191 Handler h = mf.getHandler(handlername); 192 if (h == null) { 193 throw new RemoteException ("No handler '" + handlername + "' found."); 194 } 195 h.setAttribute(attributeName, value); 196 } 197 198 public LoggerInfo getLogger(String loggername) throws RemoteException { 199 return new LoggerInfo((TopicalLogger) mf.getLogger(loggername)); 200 } 201 202 public LoggerInfo getLogger(String loggername, String resourceBundleName) 203 throws RemoteException { 204 return new LoggerInfo((TopicalLogger) 205 mf.getLogger(loggername, resourceBundleName)); 206 } 207 208 public String getResourceBundleName() throws RemoteException { 209 return mf.getResourceBundleName(); 210 } 211 212 public void setResourceBundleName(String resourceBundleName) 213 throws RemoteException { 214 mf.setResourceBundleName(resourceBundleName); 215 } 216 217 public LoggerInfo[] getLoggers() throws RemoteException { 218 Logger[] ls = mf.getLoggers(); 219 LoggerInfo[] lis = new LoggerInfo[ls.length]; 220 for(int i=0; i<ls.length; i++) { 221 lis[i] = new LoggerInfo((TopicalLogger) ls[i]); 222 } 223 return lis; 224 } 225 226 public void addHandlerToLogger(String handlername, String loggerName) 227 throws RemoteException { 228 Handler h = mf.getHandler(handlername); 229 if (h == null) { 230 throw new RemoteException ("No handler '" + handlername + "' found."); 231 } 232 TopicalLogger l = (TopicalLogger) mf.getLogger(loggerName); 233 try { 234 l.addHandler(h); 235 } catch (Exception e) { 236 throw new RemoteException (e.getMessage()); 237 } 238 } 239 240 public void removeHandlerFromLogger(String handlerName, String loggerName) 241 throws RemoteException { 242 Handler h = mf.getHandler(handlerName); 243 if (h == null) { 244 return; 245 } 246 TopicalLogger l = (TopicalLogger) mf.getLogger(loggerName); 247 try { 248 l.removeHandler(h); 249 } catch (Exception e) { 250 throw new RemoteException (e.getMessage()); 251 } 252 } 253 254 public void removeAllHandlersFromLogger(String loggerName) throws RemoteException { 255 TopicalLogger l = (TopicalLogger) mf.getLogger(loggerName); 256 try { 257 l.removeAllHandlers(); 258 } catch (Exception e) { 259 throw new RemoteException (e.getMessage()); 260 } 261 } 262 263 public void setAdditivity(boolean a, String loggerName) throws RemoteException { 264 TopicalLogger l = (TopicalLogger) mf.getLogger(loggerName); 265 l.setAdditivity(a); 266 } 267 268 public void setLoggerLevel(int level, String loggerName) throws RemoteException { 269 TopicalLogger l = (TopicalLogger) mf.getLogger(loggerName); 270 l.setIntLevel(level); 271 } 272 273 public void setLoggerLevel(String levelName, String loggerName) throws RemoteException { 274 TopicalLogger l = (TopicalLogger) mf.getLogger(loggerName); 275 Level level = mf.getLevel(levelName); 276 if (level != null) { 277 l.setLevel(level); 278 } 279 } 280 281 public void addTopicToLogger(String topic, String loggerName) 282 throws RemoteException { 283 TopicalLogger l = (TopicalLogger) mf.getLogger(loggerName); 284 try { 285 l.addTopic(topic); 286 } catch (Exception e) { 287 throw new RemoteException (e.getMessage()); 288 } 289 } 290 291 public void removeTopicFromLogger(String topic, String loggerName) 292 throws RemoteException { 293 TopicalLogger l = (TopicalLogger) mf.getLogger(loggerName); 294 try { 295 l.removeTopic(topic); 296 } catch (Exception e) { 297 throw new RemoteException (e.getMessage()); 298 } 299 } 300 301 public Properties getMonologProperties() throws RemoteException { 302 Properties p = new Properties (); 303 try { 304 PropertiesConfAccess.store(p, mf); 305 } catch (Exception e) { 306 throw new RemoteException (e.getMessage()); 307 } 308 return p; 309 } 310 311 public void setMonologProperties(Properties p) throws RemoteException { 312 try { 313 PropertiesConfAccess.load(p, mf); 314 } catch (Exception e) { 315 throw new RemoteException (e.getMessage()); 316 } 317 } 318 319 } 320 | Popular Tags |