1
2
3
4
5
6
7
8 package it.imolinfo.jbi4ejb.webservice.generator.bcm;
9
10 import it.imolinfo.jbi4ejb.Logger;
11 import it.imolinfo.jbi4ejb.LoggerFactory;
12
13 import org.objectweb.asm.ClassVisitor;
14 import org.objectweb.asm.FieldVisitor;
15 import org.objectweb.asm.Opcodes;
16 import org.objectweb.asm.Type;
17
18
19
20
21 public class SerializableDecorationAdapter
22 extends SerializableInspectorAdapter {
23
24
25
26
27 private static final Logger LOG
28 = LoggerFactory.getLogger(SerializableDecorationAdapter.class);
29
30
31
32
33 private Long newSerialVersionUid = 0L;
34
35
36
37
38
39
40
41 public SerializableDecorationAdapter(ClassVisitor cv,
42 Long aNewSerialVersionUid) {
43 super(cv);
44 if (aNewSerialVersionUid != null) {
45 newSerialVersionUid = aNewSerialVersionUid;
46 } else {
47 newSerialVersionUid = Long.valueOf(0L);
48 }
49 }
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67 public void visit(int version, int access, String name, String signature,
68 String superName, String [] interfaces) {
69
70 String [] implementsArray = interfaces;
71
72 if (! implementsSerializable(interfaces)) {
73 LOG.debug("The class " + name + " does not implement Serializable.");
74
75 int implementsSize = 0;
76 if (interfaces != null) {
77 implementsSize = interfaces.length;
78 }
79
80 implementsArray = new String[implementsSize + 1];
81
82 if (implementsSize == 0 ) {
83
84 implementsArray[0]
85 = SerializableInspectorAdapter.INTERNAL_NAME_OF_SERIALIZABLE;
86
87 } else {
88
89 System.arraycopy(interfaces, 0, implementsArray, 0, implementsSize);
90 implementsArray[implementsSize]
91 = SerializableInspectorAdapter.INTERNAL_NAME_OF_SERIALIZABLE;
92
93 }
94
95 }
96
97 super.visit(version, access, name, signature, superName, implementsArray);
98 }
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119 public FieldVisitor visitField(int access, String name, String desc,
120 String signature, Object value) {
121
122 Object retValue = value;
123 LOG.debug("visitField. access=" + access + "; name=" + name
124 + "; desc=" + desc + "; signature=" + signature + "; value=" + value);
125
126 if (hasSerialVersionUIDField(name, desc)) {
127 LOG.debug("The class " + name + " has a serial version UID:" + value);
128
129 retValue = newSerialVersionUid;
130 }
131
132 return super.visitField(access, name, desc, signature, retValue);
133 }
134
135
136
137
138
139
140 public void visitEnd() {
141 if (getClassMetaInfo().getClassSerialVersionUid() == null) {
142 super.visitField(Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL + Opcodes.ACC_STATIC,
143 SerializableInspectorAdapter.FIELDNAME_SERIAL_VERSION_UID,
144 Type.LONG_TYPE.getDescriptor(),
145 null,
146 newSerialVersionUid);
147
148 getClassMetaInfo().setClassSerialVersionUid(newSerialVersionUid);
149 }
150 }
151 }