1 27 package ch.ethz.prose.crosscut; 28 29 import java.util.HashMap ; 31 32 import ch.ethz.jvmai.ExceptionJoinPoint; 33 import ch.ethz.jvmai.FieldAccessJoinPoint; 34 import ch.ethz.jvmai.FieldModificationJoinPoint; 35 import ch.ethz.jvmai.JoinPoint; 36 import ch.ethz.jvmai.MethodEntryJoinPoint; 37 import ch.ethz.jvmai.MethodExitJoinPoint; 38 import ch.ethz.prose.engine.ExceptionThrowRequest; 39 40 62 public abstract class ThrowCut extends AbstractCrosscut implements java.io.Serializable { 63 64 private transient ThrowHandleSignaturePattern advicePattern; 65 66 private static Class throwableClass; 68 69 70 73 protected ThrowCut() 74 { 75 initState(); 76 } 77 78 public void insertionAction(boolean isBeforeInsertion) 79 { 80 if(isBeforeInsertion) 81 initState(); 82 } 83 84 private void initState() 85 { 86 if (advicePattern == null) 87 { 88 advicePattern = new ThrowHandleSignaturePattern(this); 89 } 90 } 91 92 93 96 public void THROW_ARGS(){} 97 98 99 100 protected void joinPointAction(ExceptionJoinPoint etjp) 101 throws IllegalAccessException 102 { 103 104 try 105 { 106 switch(advicePattern.signatureCathegory&(SignaturePattern.WILDCARD_1|SignaturePattern.CONCRETE_1|SignaturePattern.SIGNATURE__EMPTY)) 107 { 108 case SignaturePattern.SIGNATURE__EMPTY: 109 THROW_ARGS(); 110 break; 111 case SignaturePattern.WILDCARD_1: 112 ANY x = new ANY(); 113 x.setObject(etjp.getException()); 114 advicePattern.methodObj.invoke(this,new Object []{x}); 115 break; 116 case SignaturePattern.CONCRETE_1: 117 advicePattern.methodObj.invoke(this,new Object []{etjp.getException()}); 118 break; 119 default: 120 throw new Error ("ThrowCut.joinPointAction: illegal signature pattern"); 121 } 122 } 123 catch (java.lang.reflect.InvocationTargetException e) 124 { 125 throw new Error ("ThrowCut.joinPointAction: wrong arguments; static check failure:" + e); 126 } 127 128 129 } 130 131 132 133 136 protected boolean isPotentialCrosscutClass(Class c) 137 { 138 return Throwable .class.isAssignableFrom(c); 139 } 140 141 142 148 protected CrosscutRequest doCreateRequest(Class cls) 149 { 150 CrosscutRequest result = new CrosscutRequest(); 151 if( (advicePattern.signatureCathegory&(SignaturePattern.CONCRETE_1)) != 0 152 && 153 (!advicePattern.signature[0].isAssignableFrom(cls))) 154 return result; 155 156 result.add(requestFactory.createJoinPointRequest(ExceptionJoinPoint.KIND,cls)); 157 158 return result; 159 } 160 161 164 public String toString() 165 { 166 return " Crosscut: 'ThrowCut' \n" + 167 " Advice:" + advicePattern.toString() + "\n" + 168 " PointCutter: " + getSpecializer() + "\n"; 169 } 170 171 172 } 173 174 | Popular Tags |