1
2
3
4
5
6
7
8 package it.imolinfo.jbi4corba.webservice.generator.bcm;
9
10 import it.imolinfo.jbi4corba.Logger;
11 import it.imolinfo.jbi4corba.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 protected Long newSerialVersionUid = 0L;
34
35
36
37
38
39
40
41 public SerializableDecorationAdapter(ClassVisitor cv,
42 Long aNewSerialVersionUid) {
43 super(cv);
44 newSerialVersionUid = aNewSerialVersionUid != null ? aNewSerialVersionUid
45 : new Long(0L);
46 }
47
48
49
50
51
52
53
54
55
56
57 @Override
58 public void visit(int version, int access, String name, String signature,
59 String superName, String [] interfaces) {
60
61 String [] implementsArray = interfaces;
62
63 if (! implementsSerializable(interfaces)) {
64 LOG.debug("The class " + name + " does not implement Serializable.");
65
66 int implementsSize = interfaces == null ? 0 : interfaces.length;
67
68 implementsArray = new String[implementsSize + 1];
69
70 if (implementsSize == 0 ) {
71
72 implementsArray[0]
73 = SerializableInspectorAdapter.INTERNAL_NAME_OF_SERIALIZABLE;
74
75 } else {
76
77 System.arraycopy(interfaces, 0, implementsArray, 0, implementsSize);
78 implementsArray[implementsSize]
79 = SerializableInspectorAdapter.INTERNAL_NAME_OF_SERIALIZABLE;
80
81 }
82
83 }
84
85 super.visit(version, access, name, signature, superName, implementsArray);
86 }
87
88
89
90
91
92
93
94
95
96
97 @Override
98 public FieldVisitor visitField(int access, String name, String desc,
99 String signature, Object value) {
100
101 LOG.debug("visitField. access=" + access + "; name=" + name
102 + "; desc=" + desc + "; signature=" + signature + "; value=" + value);
103
104 if (hasSerialVersionUIDField(name, desc)) {
105 LOG.debug("The class " + name + " has a serial version UID:" + value);
106
107 value = newSerialVersionUid;
108 }
109
110 return super.visitField(access, name, desc, signature, value);
111 }
112
113
114
115
116 @Override
117 public void visitEnd() {
118 if (getClassMetaInfo().getClassSerialVersionUid() == null) {
119 super.visitField(Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL + Opcodes.ACC_STATIC,
120 SerializableInspectorAdapter.FIELDNAME_SERIAL_VERSION_UID,
121 Type.LONG_TYPE.getDescriptor(),
122 null,
123 newSerialVersionUid);
124
125 getClassMetaInfo().setClassSerialVersionUid(newSerialVersionUid);
126 }
127 }
128 }