9
9
10
10
public class Weaver {
11
11
private final ClassPool _pool ;
12
- private final CtClass _dtask , _iced , _enum ;
12
+ private final CtClass _dtask , _iced , _enum , _freezable ;
13
13
private final CtClass [] _serBases ;
14
14
private final CtClass _fielddoc ;
15
15
private final CtClass _arg ;
@@ -22,7 +22,8 @@ public class Weaver {
22
22
_iced = _pool .get ("water.Iced" ); // Needs serialization
23
23
_dtask = _pool .get ("water.DTask" );// Needs serialization and remote execution
24
24
_enum = _pool .get ("java.lang.Enum" ); // Needs serialization
25
- _serBases = new CtClass [] { _iced , _dtask , _enum , };
25
+ _freezable = _pool .get ("water.Freezable" ); // Needs serialization
26
+ _serBases = new CtClass [] { _iced , _dtask , _enum , _freezable };
26
27
for ( CtClass c : _serBases ) c .freeze ();
27
28
_fielddoc = _pool .get ("water.api.DocGen$FieldDoc" );// Is auto-documentation result
28
29
_arg = _pool .get ("water.api.RequestArguments$Argument" ); // Needs auto-documentation
@@ -74,6 +75,16 @@ private synchronized CtClass javassistLoadClass(String name) {
74
75
if ( cc .subclassOf (base ) )
75
76
return javassistLoadClass (cc );
76
77
78
+ // Subtype of an alternative freezable?
79
+ if ( cc .subtypeOf ( _freezable ) ) {
80
+ // Find the alternative freezable base
81
+ CtClass xcc = cc ;
82
+ CtClass ycc = null ;
83
+ while ( xcc .subtypeOf (_freezable ) ) { ycc = xcc ; xcc = xcc .getSuperclass (); }
84
+ if ( !ycc .isFrozen () ) ycc .freeze (); // Freeze the alternative base
85
+ return cc == ycc ? cc : javassistLoadClass (cc ); // And weave the subclass
86
+ }
87
+
77
88
return cc ;
78
89
} catch ( NotFoundException nfe ) {
79
90
return null ; // Not found? Use the normal loader then
@@ -125,7 +136,8 @@ CtClass addSerializationMethods( CtClass cc ) throws CannotCompileException, Not
125
136
if ( cc .subclassOf (_enum ) ) exposeRawEnumArray (cc );
126
137
if ( cc .subclassOf (_iced ) ) ensureAPImethods (cc );
127
138
if ( cc .subclassOf (_iced ) ||
128
- cc .subclassOf (_dtask ) ) {
139
+ cc .subclassOf (_dtask )||
140
+ cc .subtypeOf (_freezable )) {
129
141
cc .setModifiers (javassist .Modifier .setPublic (cc .getModifiers ()));
130
142
ensureSerMethods (cc );
131
143
ensureNullaryCtor (cc );
@@ -335,11 +347,11 @@ private void ensureSerMethods(CtClass cc) throws NotFoundException, CannotCompil
335
347
boolean w = hasExisting ("write" , "(Lwater/AutoBuffer;)Lwater/AutoBuffer;" , ccms );
336
348
boolean r = hasExisting ("read" , "(Lwater/AutoBuffer;)Lwater/Freezable;" , ccms );
337
349
boolean d = cc .subclassOf (_dtask ); // Subclass of DTask?
338
- boolean c = hasExisting ("copyOver" , "(Lwater/DTask ;)V" , ccms );
350
+ boolean c = hasExisting ("copyOver" , "(Lwater/Freezable ;)V" , ccms );
339
351
if ( w && r && (!d || c ) ) return ;
340
352
if ( w || r || c )
341
353
throw new RuntimeException (cc .getName () +" must implement all of " +
342
- "read(AutoBuffer) and write(AutoBuffer) and copyOver(DTask ) or none" );
354
+ "read(AutoBuffer) and write(AutoBuffer) and copyOver(Freezable ) or none" );
343
355
344
356
// Add the serialization methods: read, write.
345
357
CtField ctfs [] = cc .getDeclaredFields ();
@@ -396,7 +408,7 @@ private void ensureSerMethods(CtClass cc) throws NotFoundException, CannotCompil
396
408
// _d = s._d;
397
409
// }
398
410
if ( d ) make_body (cc ,ctfs ,callsuper ,
399
- "public void copyOver(water.DTask i) {\n " +
411
+ "public void copyOver(water.Freezable i) {\n " +
400
412
" " +cc .getName ()+" s = (" +cc .getName ()+")i;\n " ,
401
413
" super.copyOver(s);\n " ,
402
414
" %s = s.%s;\n " ,
0 commit comments