/
JTransfoJrebelPlugin.java
91 lines (76 loc) · 2.59 KB
/
JTransfoJrebelPlugin.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
* This file is part of jTransfo, a library for converting to and from transfer objects.
* Copyright (c) PROGS bvba, Belgium
*
* The program is available in open source according to the Apache License, Version 2.0.
* For full licensing details, see LICENSE.txt in the project root.
*/
package org.jtransfo;
import org.zeroturnaround.javarebel.ClassEventListener;
import org.zeroturnaround.javarebel.ClassResourceSource;
import org.zeroturnaround.javarebel.LoggerFactory;
import org.zeroturnaround.javarebel.Plugin;
import org.zeroturnaround.javarebel.ReloaderFactory;
/**
* Jrebel plugin, assure jTransfo does not keep working with 'old' class definitions.
*/
public class JTransfoJrebelPlugin implements Plugin {
private JTransfoImpl jTransfo;
/**
* Set instance for which this plugin (instance) applies.
*
* @param instance jTransfo registry instance
*/
public void setInstance(JTransfoImpl instance) {
jTransfo = instance;
}
@Override
public void preinit() {
registerListener();
}
private void registerListener() {
// Set up the reload listener
ReloaderFactory.getInstance().addClassReloadListener(
new ClassEventListener() {
public void onClassEvent(int eventType, Class klass) {
try {
if (klass.isAnnotationPresent(DomainClass.class) ||
klass.isAnnotationPresent(DomainClassDelegate.class)) {
jTransfo.clearCaches();
}
} catch (Exception e) {
LoggerFactory.getInstance().error(e);
System.out.println(e);
}
}
public int priority() {
return 0;
}
}
);
}
@Override
public boolean checkDependencies(ClassLoader classLoader, ClassResourceSource classResourceSource) {
return classResourceSource.getClassResource("org.jtransfo.JTransfoImpl") != null;
}
@Override
public String getId() {
return "JTransfoJrebelPlugin";
}
@Override
public String getName() {
return "JRebel Plugin for jTransfo";
}
@Override
public String getDescription() {
return "Assure jTransfo notices changes in mapped classes - clear cache.";
}
@Override
public String getAuthor() {
return null;
}
@Override
public String getWebsite() {
return null;
}
}