KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > aspects > integrity > PrePostWrapper


1 /*
2   Copyright (C) 2002 Renaud Pawlak <renaud@aopsys.com>
3
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU Lesser General Public License as
6   published by the Free Software Foundation; either version 2 of the
7   License, or (at your option) any later version.
8
9   This program is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12   GNU Lesser General Public License for more details.
13
14   You should have received a copy of the GNU Lesser General Public License
15   along with this program; if not, write to the Free Software
16   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */

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 /**
30  * This wrapper provides pre-post condition testing.
31  */

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     /**
41      * This wrapping method checks if pre and post conditions are
42      * validated for modified fields.
43      */

44
45     public Object JavaDoc checkPrePost(Interaction interaction) throws Exception JavaDoc {
46         logger.debug(
47             "entering test conditions for " + interaction.method);
48
49         ClassItem curClass =
50             ClassRepository.get().getClass(interaction.wrappee);
51
52         Boolean JavaDoc pre = Boolean.TRUE;
53         Boolean JavaDoc post = Boolean.TRUE;
54
55         // Handle pre
56
try {
57             pre =
58                 (Boolean JavaDoc) 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 JavaDoc 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 JavaDoc(
73                 "precondition failed for method "
74                     + interaction.method.getName());
75         }
76
77         Object JavaDoc ret = proceed(interaction);
78
79         // Handle post
80
try {
81             post =
82                 (Boolean JavaDoc) 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 JavaDoc 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 JavaDoc(
97                 "postcondition failed for method "
98                     + interaction.method.getName());
99         }
100         return ret;
101     }
102
103     /* (non-Javadoc)
104      * @see org.aopalliance.intercept.MethodInterceptor#invoke(org.aopalliance.intercept.MethodInvocation)
105      */

106     public Object JavaDoc invoke(MethodInvocation invocation) throws Throwable JavaDoc {
107         // TODO Auto-generated method stub
108
return null;
109     }
110
111     /* (non-Javadoc)
112      * @see org.aopalliance.intercept.ConstructorInterceptor#construct(org.aopalliance.intercept.ConstructorInvocation)
113      */

114     public Object JavaDoc construct(ConstructorInvocation invocation)
115         throws Throwable JavaDoc {
116         // TODO Auto-generated method stub
117
return null;
118     }
119 }
120
Popular Tags