103 |
* The singleton LogManager instance. |
* The singleton LogManager instance. |
104 |
*/ |
*/ |
105 |
private static LogManager logManager; |
private static LogManager logManager; |
|
|
|
106 |
|
|
107 |
/** |
/** |
108 |
* The registered named loggers; maps the name of a Logger to |
* The registered named loggers; maps the name of a Logger to |
109 |
* a WeakReference to it. |
* a WeakReference to it. |
110 |
*/ |
*/ |
111 |
private Map loggers; |
private Map loggers; |
|
|
|
112 |
final Logger rootLogger; |
final Logger rootLogger; |
113 |
|
|
|
|
|
114 |
/** |
/** |
115 |
* The properties for the logging framework which have been |
* The properties for the logging framework which have been |
116 |
* read in last. |
* read in last. |
129 |
* behave differently from the reference implementation in |
* behave differently from the reference implementation in |
130 |
* this case. |
* this case. |
131 |
*/ |
*/ |
132 |
private final PropertyChangeSupport pcs |
private final PropertyChangeSupport pcs = new PropertyChangeSupport( /* source bean */ |
133 |
= new PropertyChangeSupport(/* source bean */ LogManager.class); |
LogManager.class); |
134 |
|
|
135 |
protected LogManager() |
protected LogManager() |
136 |
{ |
{ |
137 |
if (logManager != null) |
if (logManager != null) |
138 |
throw new IllegalStateException( |
throw new IllegalStateException("there can be only one LogManager; use LogManager.getLogManager()"); |
|
"there can be only one LogManager; use LogManager.getLogManager()"); |
|
139 |
|
|
140 |
logManager = this; |
logManager = this; |
141 |
loggers = new java.util.HashMap(); |
loggers = new java.util.HashMap(); |
142 |
rootLogger = new Logger("", null); |
rootLogger = new Logger("", null); |
143 |
addLogger(rootLogger); |
addLogger(rootLogger); |
144 |
|
|
145 |
/* Make sure that Logger.global has the rootLogger as its parent. |
/* Make sure that Logger.global has the rootLogger as its parent. |
146 |
* |
* |
147 |
* Logger.global is set during class initialization of Logger, |
* Logger.global is set during class initialization of Logger, |
162 |
Logger.getLogger("global").setUseParentHandlers(true); |
Logger.getLogger("global").setUseParentHandlers(true); |
163 |
} |
} |
164 |
|
|
|
|
|
165 |
/** |
/** |
166 |
* Returns the globally shared LogManager instance. |
* Returns the globally shared LogManager instance. |
167 |
*/ |
*/ |
171 |
} |
} |
172 |
|
|
173 |
static |
static |
|
{ |
|
|
makeLogManager(); |
|
|
|
|
|
/* The Javadoc description of the class explains |
|
|
* what is going on here. |
|
|
*/ |
|
|
Object configurator = createInstance( |
|
|
System.getProperty("java.util.logging.config.class"), |
|
|
/* must be instance of */ Object.class); |
|
|
|
|
|
try |
|
|
{ |
|
|
if (configurator == null) |
|
|
getLogManager().readConfiguration(); |
|
|
} |
|
|
catch (IOException ex) |
|
174 |
{ |
{ |
175 |
/* FIXME: Is it ok to ignore exceptions here? */ |
makeLogManager(); |
176 |
|
|
177 |
|
/* The Javadoc description of the class explains |
178 |
|
* what is going on here. |
179 |
|
*/ |
180 |
|
Object configurator = createInstance(System.getProperty("java.util.logging.config.class"), |
181 |
|
/* must be instance of */ Object.class); |
182 |
|
|
183 |
|
try |
184 |
|
{ |
185 |
|
if (configurator == null) |
186 |
|
getLogManager().readConfiguration(); |
187 |
|
} |
188 |
|
catch (IOException ex) |
189 |
|
{ |
190 |
|
/* FIXME: Is it ok to ignore exceptions here? */ |
191 |
|
} |
192 |
} |
} |
|
} |
|
|
|
|
193 |
|
|
194 |
private static LogManager makeLogManager() |
private static LogManager makeLogManager() |
195 |
{ |
{ |
196 |
String managerClassName; |
String managerClassName; |
197 |
LogManager manager; |
LogManager manager; |
198 |
|
|
199 |
managerClassName = System.getProperty("java.util.logging.manager"); |
managerClassName = System.getProperty("java.util.logging.manager"); |
200 |
manager = (LogManager) createInstance(managerClassName, LogManager.class); |
manager = (LogManager) createInstance(managerClassName, LogManager.class); |
203 |
|
|
204 |
if (managerClassName != null) |
if (managerClassName != null) |
205 |
System.err.println("WARNING: System property \"java.util.logging.manager\"" |
System.err.println("WARNING: System property \"java.util.logging.manager\"" |
206 |
+ " should be the name of a subclass of java.util.logging.LogManager"); |
+ " should be the name of a subclass of java.util.logging.LogManager"); |
207 |
|
|
208 |
return new LogManager(); |
return new LogManager(); |
209 |
} |
} |
210 |
|
|
|
|
|
211 |
/** |
/** |
212 |
* Registers a listener which will be notified when the |
* Registers a listener which will be notified when the |
213 |
* logging properties are re-read. |
* logging properties are re-read. |
220 |
pcs.addPropertyChangeListener(listener); |
pcs.addPropertyChangeListener(listener); |
221 |
} |
} |
222 |
|
|
|
|
|
223 |
/** |
/** |
224 |
* Unregisters a listener. |
* Unregisters a listener. |
225 |
* |
* |
233 |
pcs.removePropertyChangeListener(listener); |
pcs.removePropertyChangeListener(listener); |
234 |
} |
} |
235 |
|
|
|
|
|
236 |
/** |
/** |
237 |
* Adds a named logger. If a logger with the same name has |
* Adds a named logger. If a logger with the same name has |
238 |
* already been registered, the method returns <code>false</code> |
* already been registered, the method returns <code>false</code> |
261 |
* that LogManager does its synchronization on the globally |
* that LogManager does its synchronization on the globally |
262 |
* shared instance of LogManager. |
* shared instance of LogManager. |
263 |
*/ |
*/ |
|
|
|
264 |
String name; |
String name; |
265 |
WeakReference ref; |
WeakReference ref; |
266 |
|
|
267 |
/* This will throw a NullPointerException if logger is null, |
/* This will throw a NullPointerException if logger is null, |
268 |
* as required by the API specification. |
* as required by the API specification. |
271 |
|
|
272 |
ref = (WeakReference) loggers.get(name); |
ref = (WeakReference) loggers.get(name); |
273 |
if (ref != null) |
if (ref != null) |
274 |
{ |
{ |
275 |
if (ref.get() != null) |
if (ref.get() != null) |
276 |
return false; |
return false; |
277 |
|
|
278 |
/* There has been a logger under this name in the past, |
/* There has been a logger under this name in the past, |
279 |
* but it has been garbage collected. |
* but it has been garbage collected. |
280 |
*/ |
*/ |
281 |
loggers.remove(ref); |
loggers.remove(ref); |
282 |
} |
} |
283 |
|
|
284 |
/* Adding a named logger requires a security permission. */ |
/* Adding a named logger requires a security permission. */ |
285 |
if ((name != null) && !name.equals("")) |
if ((name != null) && ! name.equals("")) |
286 |
checkAccess(); |
checkAccess(); |
287 |
|
|
288 |
Logger parent = findAncestor(logger); |
Logger parent = findAncestor(logger); |
297 |
* its parent to "foo.bar". |
* its parent to "foo.bar". |
298 |
*/ |
*/ |
299 |
if (parent != rootLogger) |
if (parent != rootLogger) |
|
{ |
|
|
for (Iterator iter = loggers.keySet().iterator(); iter.hasNext();) |
|
300 |
{ |
{ |
301 |
Logger possChild = (Logger) ((WeakReference) loggers.get(iter.next())).get(); |
for (Iterator iter = loggers.keySet().iterator(); iter.hasNext();) |
302 |
if ((possChild == null) || (possChild == logger) || (possChild.getParent() != parent)) |
{ |
303 |
continue; |
Logger possChild = (Logger) ((WeakReference) loggers.get(iter.next())) |
304 |
|
.get(); |
305 |
|
if ((possChild == null) || (possChild == logger) |
306 |
|
|| (possChild.getParent() != parent)) |
307 |
|
continue; |
308 |
|
|
309 |
if (!possChild.getName().startsWith(name)) |
if (! possChild.getName().startsWith(name)) |
310 |
continue; |
continue; |
311 |
|
|
312 |
if (possChild.getName().charAt(name.length()) != '.') |
if (possChild.getName().charAt(name.length()) != '.') |
313 |
continue; |
continue; |
314 |
|
|
315 |
possChild.setParent(logger); |
possChild.setParent(logger); |
316 |
|
} |
317 |
} |
} |
|
} |
|
318 |
|
|
319 |
return true; |
return true; |
320 |
} |
} |
321 |
|
|
|
|
|
322 |
/** |
/** |
323 |
* Finds the closest ancestor for a logger among the currently |
* Finds the closest ancestor for a logger among the currently |
324 |
* registered ones. For example, if the currently registered |
* registered ones. For example, if the currently registered |
338 |
private synchronized Logger findAncestor(Logger child) |
private synchronized Logger findAncestor(Logger child) |
339 |
{ |
{ |
340 |
String childName = child.getName(); |
String childName = child.getName(); |
341 |
int childNameLength = childName.length(); |
int childNameLength = childName.length(); |
342 |
Logger best = rootLogger; |
Logger best = rootLogger; |
343 |
int bestNameLength = 0; |
int bestNameLength = 0; |
344 |
|
|
345 |
Logger cand; |
Logger cand; |
346 |
String candName; |
String candName; |
347 |
int candNameLength; |
int candNameLength; |
348 |
|
|
349 |
if (child == rootLogger) |
if (child == rootLogger) |
350 |
return null; |
return null; |
351 |
|
|
352 |
for (Iterator iter = loggers.keySet().iterator(); iter.hasNext();) |
for (Iterator iter = loggers.keySet().iterator(); iter.hasNext();) |
|
{ |
|
|
candName = (String) iter.next(); |
|
|
candNameLength = candName.length(); |
|
|
|
|
|
if (candNameLength > bestNameLength |
|
|
&& childNameLength > candNameLength |
|
|
&& childName.startsWith(candName) |
|
|
&& childName.charAt(candNameLength) == '.') |
|
353 |
{ |
{ |
354 |
cand = (Logger) ((WeakReference) loggers.get(candName)).get(); |
candName = (String) iter.next(); |
355 |
if ((cand == null) || (cand == child)) |
candNameLength = candName.length(); |
356 |
continue; |
|
357 |
|
if (candNameLength > bestNameLength |
358 |
|
&& childNameLength > candNameLength |
359 |
|
&& childName.startsWith(candName) |
360 |
|
&& childName.charAt(candNameLength) == '.') |
361 |
|
{ |
362 |
|
cand = (Logger) ((WeakReference) loggers.get(candName)).get(); |
363 |
|
if ((cand == null) || (cand == child)) |
364 |
|
continue; |
365 |
|
|
366 |
bestNameLength = candName.length(); |
bestNameLength = candName.length(); |
367 |
best = cand; |
best = cand; |
368 |
|
} |
369 |
} |
} |
|
} |
|
370 |
|
|
371 |
return best; |
return best; |
372 |
} |
} |
373 |
|
|
|
|
|
374 |
/** |
/** |
375 |
* Returns a Logger given its name. |
* Returns a Logger given its name. |
376 |
* |
* |
384 |
*/ |
*/ |
385 |
public synchronized Logger getLogger(String name) |
public synchronized Logger getLogger(String name) |
386 |
{ |
{ |
387 |
WeakReference ref; |
WeakReference ref; |
388 |
|
|
389 |
/* Throw a NullPointerException if name is null. */ |
/* Throw a NullPointerException if name is null. */ |
390 |
name.getClass(); |
name.getClass(); |
396 |
return null; |
return null; |
397 |
} |
} |
398 |
|
|
|
|
|
399 |
/** |
/** |
400 |
* Returns an Enumeration of currently registered Logger names. |
* Returns an Enumeration of currently registered Logger names. |
401 |
* Since other threads can register loggers at any time, the |
* Since other threads can register loggers at any time, the |
409 |
return Collections.enumeration(loggers.keySet()); |
return Collections.enumeration(loggers.keySet()); |
410 |
} |
} |
411 |
|
|
|
|
|
412 |
/** |
/** |
413 |
* Resets the logging configuration by removing all handlers for |
* Resets the logging configuration by removing all handlers for |
414 |
* registered named loggers and setting their level to <code>null</code>. |
* registered named loggers and setting their level to <code>null</code>. |
418 |
* the caller is not granted the permission to control |
* the caller is not granted the permission to control |
419 |
* the logging infrastructure. |
* the logging infrastructure. |
420 |
*/ |
*/ |
421 |
public synchronized void reset() |
public synchronized void reset() throws SecurityException |
|
throws SecurityException |
|
422 |
{ |
{ |
423 |
/* Throw a SecurityException if the caller does not have the |
/* Throw a SecurityException if the caller does not have the |
424 |
* permission to control the logging infrastructure. |
* permission to control the logging infrastructure. |
429 |
|
|
430 |
Iterator iter = loggers.values().iterator(); |
Iterator iter = loggers.values().iterator(); |
431 |
while (iter.hasNext()) |
while (iter.hasNext()) |
|
{ |
|
|
WeakReference ref; |
|
|
Logger logger; |
|
|
|
|
|
ref = (WeakReference) iter.next(); |
|
|
if (ref != null) |
|
432 |
{ |
{ |
433 |
logger = (Logger) ref.get(); |
WeakReference ref; |
434 |
|
Logger logger; |
435 |
|
|
436 |
if (logger == null) |
ref = (WeakReference) iter.next(); |
437 |
iter.remove(); |
if (ref != null) |
438 |
else if (logger != rootLogger) |
{ |
439 |
logger.setLevel(null); |
logger = (Logger) ref.get(); |
440 |
|
|
441 |
|
if (logger == null) |
442 |
|
iter.remove(); |
443 |
|
else if (logger != rootLogger) |
444 |
|
logger.setLevel(null); |
445 |
|
} |
446 |
} |
} |
|
} |
|
447 |
|
|
448 |
rootLogger.setLevel(Level.INFO); |
rootLogger.setLevel(Level.INFO); |
449 |
} |
} |
450 |
|
|
|
|
|
451 |
/** |
/** |
452 |
* Configures the logging framework by reading a configuration file. |
* Configures the logging framework by reading a configuration file. |
453 |
* The name and location of this file are specified by the system |
* The name and location of this file are specified by the system |
473 |
public synchronized void readConfiguration() |
public synchronized void readConfiguration() |
474 |
throws IOException, SecurityException |
throws IOException, SecurityException |
475 |
{ |
{ |
476 |
String path; |
String path; |
477 |
InputStream inputStream; |
InputStream inputStream; |
478 |
|
|
479 |
path = System.getProperty("java.util.logging.config.file"); |
path = System.getProperty("java.util.logging.config.file"); |
480 |
if ((path == null) || (path.length() == 0)) |
if ((path == null) || (path.length() == 0)) |
481 |
{ |
{ |
482 |
String url = (System.getProperty("gnu.classpath.home.url") |
String url = (System.getProperty("gnu.classpath.home.url") |
483 |
+ "/logging.properties"); |
+ "/logging.properties"); |
484 |
inputStream = new URL(url).openStream(); |
inputStream = new URL(url).openStream(); |
485 |
} |
} |
486 |
else |
else |
|
{ |
|
487 |
inputStream = new java.io.FileInputStream(path); |
inputStream = new java.io.FileInputStream(path); |
|
} |
|
488 |
|
|
489 |
try |
try |
490 |
{ |
{ |
491 |
readConfiguration(inputStream); |
readConfiguration(inputStream); |
492 |
} |
} |
493 |
finally |
finally |
494 |
{ |
{ |
495 |
/* Close the stream in order to save |
/* Close the stream in order to save |
496 |
* resources such as file descriptors. |
* resources such as file descriptors. |
497 |
*/ |
*/ |
498 |
inputStream.close(); |
inputStream.close(); |
499 |
} |
} |
500 |
} |
} |
501 |
|
|
|
|
|
502 |
public synchronized void readConfiguration(InputStream inputStream) |
public synchronized void readConfiguration(InputStream inputStream) |
503 |
throws IOException, SecurityException |
throws IOException, SecurityException |
504 |
{ |
{ |
505 |
Properties newProperties; |
Properties newProperties; |
506 |
Enumeration keys; |
Enumeration keys; |
507 |
|
|
508 |
checkAccess(); |
checkAccess(); |
509 |
newProperties = new Properties(); |
newProperties = new Properties(); |
510 |
newProperties.load(inputStream); |
newProperties.load(inputStream); |
511 |
this.properties = newProperties; |
this.properties = newProperties; |
512 |
keys = newProperties.propertyNames(); |
keys = newProperties.propertyNames(); |
513 |
|
|
514 |
while (keys.hasMoreElements()) |
while (keys.hasMoreElements()) |
|
{ |
|
|
String key = ((String) keys.nextElement()).trim(); |
|
|
String value = newProperties.getProperty(key); |
|
|
|
|
|
if (value == null) |
|
|
continue; |
|
|
|
|
|
value = value.trim(); |
|
|
|
|
|
if("handlers".equals(key)) |
|
|
{ |
|
|
StringTokenizer tokenizer = new StringTokenizer(value); |
|
|
while(tokenizer.hasMoreTokens()) |
|
|
{ |
|
|
String handlerName = tokenizer.nextToken(); |
|
|
try |
|
|
{ |
|
|
Class handlerClass = Class.forName(handlerName); |
|
|
getLogger("").addHandler((Handler)handlerClass.newInstance()); |
|
|
} |
|
|
catch (ClassCastException ex) |
|
|
{ |
|
|
System.err.println("[LogManager] class " + handlerName + " is not subclass of java.util.logging.Handler"); |
|
|
} |
|
|
catch (Exception ex) |
|
|
{ |
|
|
//System.out.println("[LogManager.readConfiguration]"+ex); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
if (key.endsWith(".level")) |
|
515 |
{ |
{ |
516 |
String loggerName = key.substring(0, key.length() - 6); |
String key = ((String) keys.nextElement()).trim(); |
517 |
Logger logger = getLogger(loggerName); |
String value = newProperties.getProperty(key); |
518 |
if (logger != null) |
|
519 |
{ |
if (value == null) |
520 |
try |
continue; |
521 |
|
|
522 |
|
value = value.trim(); |
523 |
|
|
524 |
|
if ("handlers".equals(key)) |
525 |
{ |
{ |
526 |
logger.setLevel(Level.parse(value)); |
StringTokenizer tokenizer = new StringTokenizer(value); |
527 |
|
while (tokenizer.hasMoreTokens()) |
528 |
|
{ |
529 |
|
String handlerName = tokenizer.nextToken(); |
530 |
|
try |
531 |
|
{ |
532 |
|
Class handlerClass = Class.forName(handlerName); |
533 |
|
getLogger("").addHandler((Handler) handlerClass |
534 |
|
.newInstance()); |
535 |
|
} |
536 |
|
catch (ClassCastException ex) |
537 |
|
{ |
538 |
|
System.err.println("[LogManager] class " + handlerName |
539 |
|
+ " is not subclass of java.util.logging.Handler"); |
540 |
|
} |
541 |
|
catch (Exception ex) |
542 |
|
{ |
543 |
|
//System.out.println("[LogManager.readConfiguration]"+ex); |
544 |
|
} |
545 |
|
} |
546 |
} |
} |
547 |
catch (Exception _) |
|
548 |
|
if (key.endsWith(".level")) |
549 |
{ |
{ |
550 |
//System.out.println("[LogManager.readConfiguration] "+_); |
String loggerName = key.substring(0, key.length() - 6); |
551 |
|
Logger logger = getLogger(loggerName); |
552 |
|
|
553 |
|
if (logger == null) |
554 |
|
{ |
555 |
|
logger = Logger.getLogger(loggerName); |
556 |
|
addLogger(logger); |
557 |
|
} |
558 |
|
try |
559 |
|
{ |
560 |
|
logger.setLevel(Level.parse(value)); |
561 |
|
} |
562 |
|
catch (Exception _) |
563 |
|
{ |
564 |
|
//System.out.println("[LogManager.readConfiguration] "+_); |
565 |
|
} |
566 |
|
continue; |
567 |
} |
} |
|
continue; |
|
|
} |
|
568 |
} |
} |
|
} |
|
569 |
|
|
570 |
/* The API specification does not talk about the |
/* The API specification does not talk about the |
571 |
* property name that is distributed with the |
* property name that is distributed with the |
576 |
pcs.firePropertyChange(null, null, null); |
pcs.firePropertyChange(null, null, null); |
577 |
} |
} |
578 |
|
|
|
|
|
579 |
/** |
/** |
580 |
* Returns the value of a configuration property as a String. |
* Returns the value of a configuration property as a String. |
581 |
*/ |
*/ |
587 |
return null; |
return null; |
588 |
} |
} |
589 |
|
|
|
|
|
590 |
/** |
/** |
591 |
* Returns the value of a configuration property as an integer. |
* Returns the value of a configuration property as an integer. |
592 |
* This function is a helper used by the Classpath implementation |
* This function is a helper used by the Classpath implementation |
602 |
static int getIntProperty(String name, int defaultValue) |
static int getIntProperty(String name, int defaultValue) |
603 |
{ |
{ |
604 |
try |
try |
605 |
{ |
{ |
606 |
return Integer.parseInt(getLogManager().getProperty(name)); |
return Integer.parseInt(getLogManager().getProperty(name)); |
607 |
} |
} |
608 |
catch (Exception ex) |
catch (Exception ex) |
609 |
{ |
{ |
610 |
return defaultValue; |
return defaultValue; |
611 |
} |
} |
612 |
} |
} |
613 |
|
|
|
|
|
614 |
/** |
/** |
615 |
* Returns the value of a configuration property as an integer, |
* Returns the value of a configuration property as an integer, |
616 |
* provided it is inside the acceptable range. |
* provided it is inside the acceptable range. |
630 |
* or if it is greater than the maximum value. |
* or if it is greater than the maximum value. |
631 |
*/ |
*/ |
632 |
static int getIntPropertyClamped(String name, int defaultValue, |
static int getIntPropertyClamped(String name, int defaultValue, |
633 |
int minValue, int maxValue) |
int minValue, int maxValue) |
634 |
{ |
{ |
635 |
int val = getIntProperty(name, defaultValue); |
int val = getIntProperty(name, defaultValue); |
636 |
if ((val < minValue) || (val > maxValue)) |
if ((val < minValue) || (val > maxValue)) |
638 |
return val; |
return val; |
639 |
} |
} |
640 |
|
|
|
|
|
641 |
/** |
/** |
642 |
* Returns the value of a configuration property as a boolean. |
* Returns the value of a configuration property as a boolean. |
643 |
* This function is a helper used by the Classpath implementation |
* This function is a helper used by the Classpath implementation |
653 |
static boolean getBooleanProperty(String name, boolean defaultValue) |
static boolean getBooleanProperty(String name, boolean defaultValue) |
654 |
{ |
{ |
655 |
try |
try |
656 |
{ |
{ |
657 |
return (new Boolean(getLogManager().getProperty(name))) |
return (new Boolean(getLogManager().getProperty(name))).booleanValue(); |
658 |
.booleanValue(); |
} |
|
} |
|
659 |
catch (Exception ex) |
catch (Exception ex) |
660 |
{ |
{ |
661 |
return defaultValue; |
return defaultValue; |
662 |
} |
} |
663 |
} |
} |
664 |
|
|
|
|
|
665 |
/** |
/** |
666 |
* Returns the value of a configuration property as a Level. |
* Returns the value of a configuration property as a Level. |
667 |
* This function is a helper used by the Classpath implementation |
* This function is a helper used by the Classpath implementation |
678 |
static Level getLevelProperty(String propertyName, Level defaultValue) |
static Level getLevelProperty(String propertyName, Level defaultValue) |
679 |
{ |
{ |
680 |
try |
try |
681 |
{ |
{ |
682 |
return Level.parse(getLogManager().getProperty(propertyName)); |
return Level.parse(getLogManager().getProperty(propertyName)); |
683 |
} |
} |
684 |
catch (Exception ex) |
catch (Exception ex) |
685 |
{ |
{ |
686 |
return defaultValue; |
return defaultValue; |
687 |
} |
} |
688 |
} |
} |
689 |
|
|
|
|
|
690 |
/** |
/** |
691 |
* Returns the value of a configuration property as a Class. |
* Returns the value of a configuration property as a Class. |
692 |
* This function is a helper used by the Classpath implementation |
* This function is a helper used by the Classpath implementation |
704 |
Class usingClass = null; |
Class usingClass = null; |
705 |
|
|
706 |
try |
try |
707 |
{ |
{ |
708 |
String propertyValue = logManager.getProperty(propertyName); |
String propertyValue = logManager.getProperty(propertyName); |
709 |
if (propertyValue != null) |
if (propertyValue != null) |
710 |
usingClass = Class.forName(propertyValue); |
usingClass = Class.forName(propertyValue); |
711 |
if (usingClass != null) |
if (usingClass != null) |
712 |
return usingClass; |
return usingClass; |
713 |
} |
} |
714 |
catch (Exception _) |
catch (Exception _) |
715 |
{ |
{ |
716 |
} |
} |
717 |
|
|
718 |
return defaultValue; |
return defaultValue; |
719 |
} |
} |
720 |
|
|
721 |
|
static final Object getInstanceProperty(String propertyName, Class ofClass, |
722 |
static final Object getInstanceProperty(String propertyName, |
Class defaultClass) |
|
Class ofClass, |
|
|
Class defaultClass) |
|
723 |
{ |
{ |
724 |
Class klass = getClassProperty(propertyName, defaultClass); |
Class klass = getClassProperty(propertyName, defaultClass); |
725 |
if (klass == null) |
if (klass == null) |
726 |
return null; |
return null; |
727 |
|
|
728 |
try |
try |
729 |
{ |
{ |
730 |
Object obj = klass.newInstance(); |
Object obj = klass.newInstance(); |
731 |
if (ofClass.isInstance(obj)) |
if (ofClass.isInstance(obj)) |
732 |
return obj; |
return obj; |
733 |
} |
} |
734 |
catch (Exception _) |
catch (Exception _) |
735 |
{ |
{ |
736 |
} |
} |
737 |
|
|
738 |
if (defaultClass == null) |
if (defaultClass == null) |
739 |
return null; |
return null; |
740 |
|
|
741 |
try |
try |
742 |
{ |
{ |
743 |
return defaultClass.newInstance(); |
return defaultClass.newInstance(); |
744 |
} |
} |
745 |
catch (java.lang.InstantiationException ex) |
catch (java.lang.InstantiationException ex) |
746 |
{ |
{ |
747 |
throw new RuntimeException(ex.getMessage()); |
throw new RuntimeException(ex.getMessage()); |
748 |
} |
} |
749 |
catch (java.lang.IllegalAccessException ex) |
catch (java.lang.IllegalAccessException ex) |
750 |
{ |
{ |
751 |
throw new RuntimeException(ex.getMessage()); |
throw new RuntimeException(ex.getMessage()); |
752 |
} |
} |
753 |
} |
} |
754 |
|
|
|
|
|
755 |
/** |
/** |
756 |
* An instance of <code>LoggingPermission("control")</code> |
* An instance of <code>LoggingPermission("control")</code> |
757 |
* that is shared between calls to <code>checkAccess()</code>. |
* that is shared between calls to <code>checkAccess()</code>. |
758 |
*/ |
*/ |
759 |
private static final LoggingPermission controlPermission |
private static final LoggingPermission controlPermission = new LoggingPermission("control", |
760 |
= new LoggingPermission("control", null); |
null); |
|
|
|
761 |
|
|
762 |
/** |
/** |
763 |
* Checks whether the current security context allows changing |
* Checks whether the current security context allows changing |
769 |
* the caller is not granted the permission to control |
* the caller is not granted the permission to control |
770 |
* the logging infrastructure. |
* the logging infrastructure. |
771 |
*/ |
*/ |
772 |
public void checkAccess() |
public void checkAccess() throws SecurityException |
|
throws SecurityException |
|
773 |
{ |
{ |
774 |
SecurityManager sm = System.getSecurityManager(); |
SecurityManager sm = System.getSecurityManager(); |
775 |
if (sm != null) |
if (sm != null) |
776 |
sm.checkPermission(controlPermission); |
sm.checkPermission(controlPermission); |
777 |
} |
} |
778 |
|
|
779 |
|
/** |
|
/** |
|
780 |
* Creates a new instance of a class specified by name. |
* Creates a new instance of a class specified by name. |
781 |
* |
* |
782 |
* @param className the name of the class of which a new instance |
* @param className the name of the class of which a new instance |
783 |
* should be created. |
* should be created. |
784 |
* |
* |
785 |
* @param ofClass the class to which the new instance should |
* @param ofClass the class to which the new instance should |
786 |
* be either an instance or an instance of a subclass. |
* be either an instance or an instance of a subclass. |
787 |
* FIXME: This description is just terrible. |
* FIXME: This description is just terrible. |
794 |
*/ |
*/ |
795 |
static final Object createInstance(String className, Class ofClass) |
static final Object createInstance(String className, Class ofClass) |
796 |
{ |
{ |
797 |
Class klass; |
Class klass; |
798 |
|
|
799 |
if ((className == null) || (className.length() == 0)) |
if ((className == null) || (className.length() == 0)) |
800 |
return null; |
return null; |
801 |
|
|
802 |
try |
try |
803 |
{ |
{ |
804 |
klass = Class.forName(className); |
klass = Class.forName(className); |
805 |
if (!ofClass.isAssignableFrom(klass)) |
if (! ofClass.isAssignableFrom(klass)) |
806 |
return null; |
return null; |
807 |
|
|
808 |
return klass.newInstance(); |
return klass.newInstance(); |
809 |
} |
} |
810 |
catch (Exception _) |
catch (Exception _) |
811 |
{ |
{ |
812 |
return null; |
return null; |
813 |
} |
} |
814 |
catch (java.lang.LinkageError _) |
catch (java.lang.LinkageError _) |
815 |
{ |
{ |
816 |
return null; |
return null; |
817 |
} |
} |
818 |
} |
} |
819 |
} |
} |