KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > aop > instrument > CallerInfoAdder


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.aop.instrument;
23
24 import javassist.CannotCompileException;
25 import javassist.CtClass;
26 import javassist.CtField;
27 import javassist.Modifier;
28 import javassist.NotFoundException;
29
30 /**
31  * Strategy for adding caller info fields to class
32  *
33  * @author <a HREF="mailto:kabir.khan@jboss.org">Kabir Khan</a>
34  * @version $Revision$
35  */

36 public abstract class CallerInfoAdder
37 {
38    Instrumentor instrumentor;
39    int infoModifier = Modifier.PRIVATE | Modifier.STATIC;
40    
41    protected CallerInfoAdder(Instrumentor instrumentor)
42    {
43       this.instrumentor = instrumentor;
44    }
45    
46    protected CallerInfoAdder(Instrumentor instrumentor, int mod)
47    {
48       this.instrumentor = instrumentor;
49       infoModifier = mod;
50    }
51    
52    protected abstract void addMethodByMethodInfoField(CtClass addTo, String JavaDoc fieldName, long callingHash, String JavaDoc classname, long calledHash) throws NotFoundException, CannotCompileException;
53    
54    protected abstract void addConByMethodInfoField(CtClass addTo, String JavaDoc fieldName, long callingHash, String JavaDoc classname, long calledHash) throws NotFoundException, CannotCompileException;
55
56    protected abstract void addConByConInfoField(CtClass addTo, String JavaDoc fieldName, int callingIndex, String JavaDoc classname, long calledHash) throws NotFoundException, CannotCompileException;
57
58    protected abstract void addMethodByConInfoField(CtClass addTo, String JavaDoc fieldName, int callingIndex, String JavaDoc classname, long calledHash) throws NotFoundException, CannotCompileException;
59    
60    
61    protected void addConByConInfoField(CtClass addTo, String JavaDoc fieldName, String JavaDoc init) throws NotFoundException, CannotCompileException
62    {
63       addField(addTo, "org.jboss.aop.ConByConInfo", fieldName, init);
64    }
65
66    protected void addConByMethodInfoField(CtClass addTo, String JavaDoc fieldName,
67          String JavaDoc init) throws NotFoundException, CannotCompileException
68    {
69       addField(addTo, "org.jboss.aop.ConByMethodInfo", fieldName, init);
70    }
71
72    protected void addMethodByConInfoField(CtClass addTo, String JavaDoc fieldName,
73          String JavaDoc init) throws NotFoundException, CannotCompileException
74    {
75       addField(addTo, "org.jboss.aop.MethodByConInfo", fieldName, init);
76    }
77
78    protected void addMethodByMethodInfoField(CtClass addTo, String JavaDoc fieldName,
79          String JavaDoc init) throws NotFoundException, CannotCompileException
80    {
81       addField(addTo, "org.jboss.aop.MethodByMethodInfo", fieldName, init);
82    }
83    
84    private void addField(CtClass addTo, String JavaDoc typeName, String JavaDoc fieldName,
85          String JavaDoc init) throws NotFoundException, CannotCompileException
86    {
87       CtField.Initializer initializer = (init != null ) ? CtField.Initializer.byExpr(init) : null;
88       TransformerCommon.addInfoField(instrumentor, typeName, fieldName, infoModifier, addTo, addInfoAsWeakReference(), initializer);
89    }
90
91    protected abstract boolean addInfoAsWeakReference();
92 }
93
Popular Tags