You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TraceFactory.java 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*******************************************************************************
  2. * Copyright (c) 2006 IBM Corporation and others.
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Eclipse Public License v 2.0
  5. * which accompanies this distribution, and is available at
  6. * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  7. *
  8. * Contributors:
  9. * Matthew Webster - initial implementation
  10. *******************************************************************************/
  11. package org.aspectj.weaver.tools;
  12. public abstract class TraceFactory {
  13. public final static String DEBUG_PROPERTY = "org.aspectj.tracing.debug";
  14. public final static String FACTORY_PROPERTY = "org.aspectj.tracing.factory";
  15. public final static String DEFAULT_FACTORY_NAME = "default";
  16. protected static boolean debug = getBoolean(DEBUG_PROPERTY,false);
  17. private static TraceFactory instance;
  18. public Trace getTrace (Class clazz) {
  19. return instance.getTrace(clazz);
  20. }
  21. public static TraceFactory getTraceFactory () {
  22. return instance;
  23. }
  24. protected static boolean getBoolean(String name, boolean def) {
  25. String defaultValue = String.valueOf(def);
  26. String value = System.getProperty(name,defaultValue);
  27. return Boolean.parseBoolean(value);
  28. }
  29. static {
  30. /*
  31. * Allow user to override default behaviour or specify their own factory
  32. */
  33. String factoryName = System.getProperty(FACTORY_PROPERTY);
  34. if (factoryName != null) try {
  35. if (factoryName.equals(DEFAULT_FACTORY_NAME)) {
  36. instance = new DefaultTraceFactory();
  37. }
  38. else {
  39. Class factoryClass = Class.forName(factoryName);
  40. instance = (TraceFactory)factoryClass.getDeclaredConstructor().newInstance();
  41. }
  42. }
  43. catch (Throwable th) {
  44. if (debug) th.printStackTrace();
  45. }
  46. /*
  47. * Try to load external trace infrastructure using supplied factories
  48. */
  49. if (instance == null) try {
  50. {
  51. Class factoryClass = Class.forName("org.aspectj.weaver.tools.Jdk14TraceFactory");
  52. instance = (TraceFactory)factoryClass.getDeclaredConstructor().newInstance();
  53. }
  54. }
  55. catch (Throwable th) {
  56. if (debug) th.printStackTrace();
  57. }
  58. /*
  59. * Use default trace
  60. */
  61. if (instance == null) {
  62. instance = new DefaultTraceFactory();
  63. }
  64. if (debug) System.err.println("TraceFactory.instance=" + instance);
  65. }
  66. }