1 13 14 15 package org.aspectj.runtime.internal; 16 17 import java.util.Stack ; 18 19 import org.aspectj.lang.NoAspectBoundException; 20 import org.aspectj.runtime.CFlow; 21 import org.aspectj.runtime.internal.cflowstack.ThreadStack; 22 import org.aspectj.runtime.internal.cflowstack.ThreadStackFactory; 23 import org.aspectj.runtime.internal.cflowstack.ThreadStackFactoryImpl; 24 import org.aspectj.runtime.internal.cflowstack.ThreadStackFactoryImpl11; 25 26 52 53 public class CFlowStack { 54 55 private static ThreadStackFactory tsFactory; 56 private ThreadStack stackProxy; 57 58 static { 59 selectFactoryForVMVersion(); 60 } 61 62 public CFlowStack() { 63 stackProxy = tsFactory.getNewThreadStack(); 64 } 65 66 private Stack getThreadStack() { 67 return stackProxy.getThreadStack(); 68 } 69 70 public void push(Object obj) { 72 getThreadStack().push(obj); 73 } 74 75 public void pushInstance(Object obj) { 76 getThreadStack().push(new CFlow(obj)); 77 } 78 79 public void push(Object [] obj) { 80 getThreadStack().push(new CFlowPlusState(obj)); 81 } 82 83 public void pop() { 84 getThreadStack().pop(); 85 } 86 87 public Object peek() { 88 Stack stack = getThreadStack(); 89 if (stack.isEmpty()) throw new org.aspectj.lang.NoAspectBoundException(); 90 return (Object )stack.peek(); 91 } 92 93 public Object get(int index) { 94 CFlow cf = peekCFlow(); 95 return (null == cf ? null : cf.get(index)); 96 } 97 98 public Object peekInstance() { 99 CFlow cf = peekCFlow(); 100 if (cf != null ) return cf.getAspect(); 101 else throw new NoAspectBoundException(); 102 } 103 104 public CFlow peekCFlow() { 105 Stack stack = getThreadStack(); 106 if (stack.isEmpty()) return null; 107 return (CFlow)stack.peek(); 108 } 109 110 public CFlow peekTopCFlow() { 111 Stack stack = getThreadStack(); 112 if (stack.isEmpty()) return null; 113 return (CFlow)stack.elementAt(0); 114 } 115 116 public boolean isValid() { 117 return !getThreadStack().isEmpty(); 118 } 119 120 private static ThreadStackFactory getThreadLocalStackFactory() { return new ThreadStackFactoryImpl(); } 121 private static ThreadStackFactory getThreadLocalStackFactoryFor11() { return new ThreadStackFactoryImpl11(); } 122 123 private static void selectFactoryForVMVersion() { 124 String override = getSystemPropertyWithoutSecurityException("aspectj.runtime.cflowstack.usethreadlocal","unspecified"); 125 boolean useThreadLocalImplementation = false; 126 if (override.equals("unspecified")) { 127 String v = System.getProperty("java.class.version","0.0"); 128 useThreadLocalImplementation = (v.compareTo("46.0") >= 0); 130 } else { 131 useThreadLocalImplementation = override.equals("yes") || override.equals("true"); 132 } 133 if (useThreadLocalImplementation) { 135 tsFactory = getThreadLocalStackFactory(); 136 } else { 137 tsFactory = getThreadLocalStackFactoryFor11(); 138 } 139 } 140 141 private static String getSystemPropertyWithoutSecurityException (String aPropertyName, String aDefaultValue) { 142 try { 143 return System.getProperty(aPropertyName, aDefaultValue); 144 } 145 catch (SecurityException ex) { 146 return aDefaultValue; 147 } 148 } 149 150 151 public static String getThreadStackFactoryClassName() { 153 return tsFactory.getClass().getName(); 154 } 155 156 } 157 | Popular Tags |