KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jibx > binding > classes > ExistingMethod


1 /*
2 Copyright (c) 2003-2005, Dennis M. Sosnoski
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without modification,
6 are permitted provided that the following conditions are met:
7
8  * Redistributions of source code must retain the above copyright notice, this
9    list of conditions and the following disclaimer.
10  * Redistributions in binary form must reproduce the above copyright notice,
11    this list of conditions and the following disclaimer in the documentation
12    and/or other materials provided with the distribution.
13  * Neither the name of JiBX nor the names of its contributors may be used
14    to endorse or promote products derived from this software without specific
15    prior written permission.
16
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */

28
29 package org.jibx.binding.classes;
30
31 import org.apache.bcel.classfile.Method;
32 import org.jibx.runtime.JiBXException;
33
34 /**
35  * Information for an existing binding method. It supplies hash code and
36  * equality checking based on the method signature and actual byte code of the
37  * generated method, ignoring the method name.
38  *
39  * @author Dennis M. Sosnoski
40  * @version 1.0
41  */

42
43 public class ExistingMethod extends BindingMethod
44 {
45     /** Class item information. */
46     private ClassItem m_item;
47     
48     /** Actual method information. */
49     private Method m_method;
50     
51     /** Accumulated hash code from adding instructions. */
52     private int m_hashCode;
53     
54     /** Flag for method used in code. */
55     private boolean m_used;
56
57     /**
58      * Constructor.
59      *
60      * @param method actual method information
61      * @param item class item information for method
62      * @param file class file information
63      */

64
65     public ExistingMethod(Method method, ClassItem item, ClassFile file) {
66         super(file);
67         m_item = item;
68         m_method = method;
69         m_hashCode = computeMethodHash(method);
70 // System.out.println("Computed hash for existing method " +
71
// m_classFile.getName() + '.' + method.getName() + " as " + m_hashCode);
72
}
73
74     /**
75      * Get name of method.
76      *
77      * @return method name
78      */

79
80     public String JavaDoc getName() {
81         return m_item.getName();
82     }
83     
84     /**
85      * Get signature.
86      *
87      * @return signature for method
88      */

89      
90     public String JavaDoc getSignature() {
91         return m_item.getSignature();
92     }
93     
94     /**
95      * Get access flags.
96      *
97      * @return flags for access type of method
98      */

99      
100     public int getAccessFlags() {
101         return m_item.getAccessFlags();
102     }
103     
104     /**
105      * Set access flags.
106      *
107      * @param flags access type to be set
108      */

109      
110     public void setAccessFlags(int flags) {
111         m_item.setAccessFlags(flags);
112     }
113     
114     /**
115      * Check method used status.
116      *
117      * @return method used status
118      */

119      
120     public boolean isUsed() {
121         return m_used;
122     }
123     
124     /**
125      * Set method used status.
126      */

127      
128     public void setUsed() {
129         m_used = true;
130     }
131     
132     /**
133      * Get the actual method.
134      *
135      * @return method information
136      */

137      
138     public Method getMethod() {
139         return m_method;
140     }
141     
142     /**
143      * Get the method item.
144      *
145      * @return method item information
146      */

147      
148     public ClassItem getItem() {
149         return m_item;
150     }
151
152     /**
153      * Delete method from class.
154      *
155      * @throws JiBXException if unable to delete method
156      */

157
158     public void delete() throws JiBXException {
159         getClassFile().removeMethod(m_method);
160     }
161
162     /**
163      * Get hash code.
164      *
165      * @return hash code for this method
166      */

167
168     public int hashCode() {
169         return m_hashCode;
170     }
171 }
172
Popular Tags