1 17 18 package org.objectweb.jac.aspects.integrity; 19 20 import org.aopalliance.intercept.ConstructorInvocation; 21 import org.aopalliance.intercept.MethodInvocation; 22 import org.apache.log4j.Logger; 23 import org.objectweb.jac.core.AspectComponent; 24 import org.objectweb.jac.core.Interaction; 25 import org.objectweb.jac.core.Wrapper; 26 import org.objectweb.jac.core.rtti.ClassItem; 27 import org.objectweb.jac.core.rtti.ClassRepository; 28 29 32 33 public class PrePostWrapper extends Wrapper { 34 static final Logger logger = Logger.getLogger("integrity.conditions"); 35 36 public PrePostWrapper(AspectComponent ac) { 37 super(ac); 38 } 39 40 44 45 public Object checkPrePost(Interaction interaction) throws Exception { 46 logger.debug( 47 "entering test conditions for " + interaction.method); 48 49 ClassItem curClass = 50 ClassRepository.get().getClass(interaction.wrappee); 51 52 Boolean pre = Boolean.TRUE; 53 Boolean post = Boolean.TRUE; 54 55 try { 57 pre = 58 (Boolean ) curClass.invoke( 59 interaction.wrappee, 60 "PRE_" + interaction.method.getName(), 61 interaction.args); 62 } catch (org.objectweb.jac.core.rtti.NoSuchMethodException e) { 63 logger.debug( 64 "no pre for " + interaction.method.getName()); 65 } catch (Exception e) { 66 e.printStackTrace(); 67 } 68 if (!pre.booleanValue()) { 69 logger.debug( 70 "precondition failed for method " 71 + interaction.method.getName()); 72 throw new Exception ( 73 "precondition failed for method " 74 + interaction.method.getName()); 75 } 76 77 Object ret = proceed(interaction); 78 79 try { 81 post = 82 (Boolean ) curClass.invoke( 83 interaction.wrappee, 84 "POST_" + interaction.method.getName(), 85 interaction.args); 86 } catch (org.objectweb.jac.core.rtti.NoSuchMethodException e) { 87 logger.debug( 88 "no post for " + interaction.method.getName()); 89 } catch (Exception e) { 90 e.printStackTrace(); 91 } 92 if (!post.booleanValue()) { 93 logger.debug( 94 "precondition failed for method " 95 + interaction.method.getName()); 96 throw new Exception ( 97 "postcondition failed for method " 98 + interaction.method.getName()); 99 } 100 return ret; 101 } 102 103 106 public Object invoke(MethodInvocation invocation) throws Throwable { 107 return null; 109 } 110 111 114 public Object construct(ConstructorInvocation invocation) 115 throws Throwable { 116 return null; 118 } 119 } 120 | Popular Tags |