实现FX-PLus和Spring结合的Demo

This commit is contained in:
billkiller
2019-07-07 12:21:30 +08:00
parent bb53425b43
commit 7ce75c9206
35 changed files with 1326 additions and 497 deletions

View File

@@ -0,0 +1,14 @@
package cn.edu.scau.biubiusuisui.annotation;
import java.lang.annotation.*;
/**
* @Author jack
* @Date:2019/7/4 13:58
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@Inherited
public @interface FXBind {
String [] bind();
}

View File

@@ -1,5 +1,7 @@
package cn.edu.scau.biubiusuisui.config;
import cn.edu.scau.biubiusuisui.entity.FXBaseController;
import cn.edu.scau.biubiusuisui.factory.FXFactory;
import javafx.fxml.*;
/*
@@ -109,6 +111,16 @@ public class FXMLLoaderPlus {
private static final RuntimePermission GET_CLASSLOADER_PERMISSION =
new RuntimePermission("getClassLoader");
private boolean show = false;
public boolean isShow() {
return show;
}
public void setShow(boolean show) {
this.show = show;
}
// Abstract base class for elements
private abstract class Element {
public final cn.edu.scau.biubiusuisui.config.FXMLLoaderPlus.Element parent;
@@ -747,6 +759,8 @@ public class FXMLLoaderPlus {
super.processStartElement();
updateValue(constructValue());
//如果是FXBaseController对象需要注入fxml
//因为如果只是单纯反射不具有FXPlus功能只有FX功能
if (value instanceof Builder<?>) {
processInstancePropertyAttributes();
@@ -1009,12 +1023,17 @@ public class FXMLLoaderPlus {
if (value == null) {
try {
value = ReflectUtil.newInstance(type);
if(FXBaseController.class.isAssignableFrom(type)) {
value = FXFactory.getFXController(type,fx_id);
}else{
value = type.newInstance();
}
} catch (InstantiationException exception) {
throw constructLoadException(exception);
} catch (IllegalAccessException exception) {
throw constructLoadException(exception);
}
}
}
@@ -2551,27 +2570,29 @@ public class FXMLLoaderPlus {
((Initializable)controller).initialize(location, resources);
} else {
// Inject controller fields
Map<String, List<Field>> controllerFields =
controllerAccessor.getControllerFields();
if (!show) {
Map<String, List<Field>> controllerFields =
controllerAccessor.getControllerFields();
injectFields(LOCATION_KEY, location);
injectFields(LOCATION_KEY, location);
injectFields(RESOURCES_KEY, resources);
injectFields(RESOURCES_KEY, resources);
// Initialize the controller
Method initializeMethod = controllerAccessor
.getControllerMethods()
.get(cn.edu.scau.biubiusuisui.config.FXMLLoaderPlus.SupportedType.PARAMETERLESS)
.get(INITIALIZE_METHOD_NAME);
// Initialize the controller
Method initializeMethod = controllerAccessor
.getControllerMethods()
.get(cn.edu.scau.biubiusuisui.config.FXMLLoaderPlus.SupportedType.PARAMETERLESS)
.get(INITIALIZE_METHOD_NAME);
if (initializeMethod != null) {
try {
MethodUtil.invoke(initializeMethod, controller, new Object [] {});
} catch (IllegalAccessException exception) {
// TODO Throw when Initializable is deprecated/removed
// throw constructLoadException(cn.edu.scau.biubiusuisui.exception);
} catch (InvocationTargetException exception) {
throw constructLoadException(exception);
if (initializeMethod != null) {
try {
MethodUtil.invoke(initializeMethod, controller, new Object[]{});
} catch (IllegalAccessException exception) {
// TODO Throw when Initializable is deprecated/removed
// throw constructLoadException(cn.edu.scau.biubiusuisui.exception);
} catch (InvocationTargetException exception) {
throw constructLoadException(exception);
}
}
}
}

View File

@@ -1,7 +1,10 @@
package cn.edu.scau.biubiusuisui.config;
import cn.edu.scau.biubiusuisui.annotation.FXScan;
import cn.edu.scau.biubiusuisui.factory.BeanBuilder;
import cn.edu.scau.biubiusuisui.factory.FXBuilder;
import cn.edu.scau.biubiusuisui.factory.FXFactory;
import cn.edu.scau.biubiusuisui.function.FXWindowParser;
import cn.edu.scau.biubiusuisui.utils.ClassUtils;
import java.util.List;
@@ -17,7 +20,14 @@ import java.util.Set;
public class FXPlusApplication {
public static void start(Class clazz){
private static FXWindowParser windowAnnotationParser = new FXWindowParser();
private static BeanBuilder DEFALUT_BEAN_FACTORY = new FXBuilder();
private static BeanBuilder beanBuilder;
public static void start(Class clazz, BeanBuilder beanBuilder){
FXPlusApplication.beanBuilder = beanBuilder;
Annotation []annotations = clazz.getDeclaredAnnotations();
for(Annotation annotation : annotations){
if(FXScan.class.equals(annotation.annotationType())){
@@ -32,7 +42,7 @@ public class FXPlusApplication {
List<String> temps = classUtils.scanAllClassName(dir);
for(String className:temps){
try {
loadFXPlusClass(className);
loadFXPlusClass(className,beanBuilder);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
@@ -41,9 +51,12 @@ public class FXPlusApplication {
}
}
}
public static void start(Class clazz){
start(clazz,DEFALUT_BEAN_FACTORY);
}
private static void loadFXPlusClass(String className) throws ClassNotFoundException {
private static void loadFXPlusClass(String className,BeanBuilder beanBuilder) throws ClassNotFoundException {
Class clazz = Class.forName(className);
FXFactory.loadFXController(clazz);
FXFactory.loadFXController(clazz,beanBuilder);
}
}

View File

@@ -56,6 +56,7 @@ public class FXBaseController extends Pane {
FXMLLoaderPlus fxmlLoader = new FXMLLoaderPlus(getClass().getClassLoader().getResource(fxController.path()));
fxmlLoader.setRoot(this);
fxmlLoader.setController(this);
fxmlLoader.setShow(true);
try {
fxmlLoader.load();
} catch (IOException e) {

View File

@@ -2,8 +2,11 @@ package cn.edu.scau.biubiusuisui.example;
import cn.edu.scau.biubiusuisui.annotation.FXScan;
import cn.edu.scau.biubiusuisui.config.FXPlusApplication;
import cn.edu.scau.biubiusuisui.factory.BeanBuilder;
import javafx.application.Application;
import javafx.stage.Stage;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* @Author jack
@@ -14,6 +17,12 @@ import javafx.stage.Stage;
public class Demo extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
FXPlusApplication.start(Demo.class);
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
FXPlusApplication.start(Demo.class, new BeanBuilder() {
@Override
public Object getBean(Class type) {
return context.getBean(type);
}
});
}
}

View File

@@ -0,0 +1,8 @@
package cn.edu.scau.biubiusuisui.example;
/**
* @Author jack
* @Date:2019/7/7 10:44
*/
public class HelloFXPlusDemo {
}

View File

@@ -0,0 +1,23 @@
package cn.edu.scau.biubiusuisui.example;
import cn.edu.scau.biubiusuisui.annotation.FXController;
import cn.edu.scau.biubiusuisui.annotation.FXWindow;
import cn.edu.scau.biubiusuisui.entity.FXBaseController;
import javafx.stage.StageStyle;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* @Author jack
* @Date:2019/7/4 11:36
*/
@FXController(path = "Main.fxml")
@Component
@FXWindow(title = "hello",resizable = true,style = StageStyle.UNDECORATED)
public class Main2 extends FXBaseController {
@Autowired
Student student;
}

View File

@@ -1,7 +1,6 @@
package cn.edu.scau.biubiusuisui.example;
import cn.edu.scau.biubiusuisui.annotation.FXController;
import cn.edu.scau.biubiusuisui.annotation.FXWindow;
import cn.edu.scau.biubiusuisui.annotation.*;
import cn.edu.scau.biubiusuisui.entity.FXBaseController;
import cn.edu.scau.biubiusuisui.entity.FXPlusContext;
import cn.edu.scau.biubiusuisui.factory.FXEntityFactory;
@@ -9,6 +8,7 @@ import javafx.beans.property.Property;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.stage.StageStyle;
@@ -20,7 +20,7 @@ import java.util.ResourceBundle;
* @Date:2019/6/25 1:47
*/
@FXController(path = "Main.fxml")
@FXWindow(title = "demo1", draggable = true, resizable = true,style = StageStyle.UNDECORATED)
//@FXWindow(title = "demo1", draggable = true, resizable = true,style = StageStyle.UNDECORATED)
public class MainController extends FXBaseController{
@FXML
@@ -38,9 +38,14 @@ public class MainController extends FXBaseController{
@FXML
private ListView<String> list;
@FXML
@FXBind(bind = {"text=${student.name}"})
Label label;
Student student;
@FXML
@FXSender
void addWord(ActionEvent event) {
student.addList("hello" );
}
@@ -50,6 +55,12 @@ public class MainController extends FXBaseController{
student.delList("hello");
}
@FXReceiver(name = "MainController#haha:addWord")
void test2(){
System.out.println("?--?");
}
@Override
public void initialize() {
student = (Student) FXEntityFactory.createJavaBeanProxy(Student.class);

View File

@@ -2,6 +2,7 @@ package cn.edu.scau.biubiusuisui.example;
import cn.edu.scau.biubiusuisui.annotation.FXEntity;
import cn.edu.scau.biubiusuisui.annotation.FXField;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
@@ -11,6 +12,7 @@ import java.util.List;
*/
@FXEntity
@Component
public class Student {
@FXField
@@ -63,4 +65,5 @@ public class Student {
public void delList(String word){
list.remove(word);
}
}

View File

@@ -0,0 +1,50 @@
package cn.edu.scau.biubiusuisui.example.springDemo;
import cn.edu.scau.biubiusuisui.annotation.FXController;
import cn.edu.scau.biubiusuisui.annotation.FXWindow;
import cn.edu.scau.biubiusuisui.entity.FXBaseController;
import cn.edu.scau.biubiusuisui.entity.FXPlusContext;
import cn.edu.scau.biubiusuisui.example.Student;
import cn.edu.scau.biubiusuisui.factory.FXEntityFactory;
import cn.edu.scau.biubiusuisui.factory.FXFactory;
import javafx.beans.property.Property;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.stage.StageStyle;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* @Author jack
* @Date:2019/7/4 11:36
*/
@FXController(path = "springDemo.fxml")
@Component
@FXWindow(title = "hello",resizable = true,style = StageStyle.UNDECORATED)
public class SpringController extends FXBaseController {
@Autowired
Student student;
Student studentProxy;
@FXML
Label label;
int count = 1;
@Override
public void initialize() {
studentProxy = (Student) FXEntityFactory.createJavaBeanProxy(student);
Property property = FXPlusContext.getEntityPropertyByName(studentProxy, "name");
label.textProperty().bind(property);
}
@FXML
public void add(){
studentProxy.setName("Jack : " + count);
count++;
}
}

View File

@@ -0,0 +1,29 @@
package cn.edu.scau.biubiusuisui.example.springDemo;
import cn.edu.scau.biubiusuisui.annotation.FXScan;
import cn.edu.scau.biubiusuisui.config.FXPlusApplication;
import cn.edu.scau.biubiusuisui.example.Demo;
import cn.edu.scau.biubiusuisui.factory.BeanBuilder;
import javafx.application.Application;
import javafx.stage.Stage;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* @Author jack
* @Date:2019/7/7 10:43
*/
@FXScan(base = {"cn.edu.scau.biubiusuisui.example.springDemo"})
public class SpringDemo extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
FXPlusApplication.start(SpringDemo.class, new BeanBuilder() {
@Override
public Object getBean(Class type) {
System.out.println(type);
return context.getBean(type);
}
});
}
}

View File

@@ -0,0 +1,9 @@
package cn.edu.scau.biubiusuisui.factory;
/**
* @Author jack
* @Date:2019/7/4 11:16
*/
public interface BeanBuilder {
Object getBean(Class type);
}

View File

@@ -0,0 +1,20 @@
package cn.edu.scau.biubiusuisui.factory;
/**
* @Author jack
* @Date:2019/7/4 11:13
*/
public class FXBuilder implements BeanBuilder{
@Override
public Object getBean(Class type) {
Object object = null;
try {
object = type.newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return object;
}
}

View File

@@ -22,16 +22,17 @@ public class FXEntityFactory {
private FXEntityFactory(){}
public static Object createJavaBeanProxy(Class clazz) {
public static Object createJavaBeanProxy(Class clazz){
return createJavaBeanProxy(clazz, new FXBuilder());
}
public static Object createJavaBeanProxy(Class clazz,BeanBuilder beanBuilder) {
Object object = null;
try {
object = clazz.newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
object = beanBuilder.getBean(clazz);
if(object !=null){
return createJavaBeanProxy(object);
}else {
return null;
}
return createJavaBeanProxy(object);
}
public static Object createJavaBeanProxy(Object object){

View File

@@ -5,9 +5,13 @@ import cn.edu.scau.biubiusuisui.annotation.FXWindow;
import cn.edu.scau.biubiusuisui.config.FXMLLoaderPlus;
import cn.edu.scau.biubiusuisui.entity.FXBaseController;
import cn.edu.scau.biubiusuisui.entity.FXPlusContext;
import cn.edu.scau.biubiusuisui.example.Student;
import cn.edu.scau.biubiusuisui.function.FXExpressionParser;
import cn.edu.scau.biubiusuisui.function.FXWindowParser;
import cn.edu.scau.biubiusuisui.messageQueue.MessageQueue;
import cn.edu.scau.biubiusuisui.proxy.classProxy.FXControllerProxy;
import com.sun.javafx.fxml.BeanAdapter;
import javafx.collections.ObservableMap;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
@@ -15,6 +19,7 @@ import javafx.stage.Stage;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.net.URL;
import java.util.Map;
/**
* @Author jack
@@ -22,100 +27,119 @@ import java.net.URL;
*/
public class FXFactory {
private static final BeanBuilder BEAN_BUILDER = new FXBuilder();
private static FXWindowParser windowAnnotationParser = new FXWindowParser();
private static FXExpressionParser expressionParser = new FXExpressionParser();
private FXFactory() { }
public static void loadFXController(Class clazz) {
getFXController(clazz, "");
private FXFactory() {
}
public static void loadFXController(Class clazz, BeanBuilder beanBuilder) {
if (clazz.getDeclaredAnnotation(FXWindow.class) != null) {
getFXController(clazz, null, beanBuilder);
}
}
public static FXBaseController getFXController(Class clazz) {
FXBaseController fxBaseController = getFXController(clazz, "");
return getFXController(clazz, BEAN_BUILDER);
}
public static FXBaseController getFXController(Class clazz, BeanBuilder beanBuilder) {
FXBaseController fxBaseController = getFXController(clazz, null, beanBuilder);
return fxBaseController;
}
public static FXBaseController getFXController(Class clazz, String controllerName) {
FXBaseController fxBaseController = getFxBaseController(clazz, controllerName);
return getFXController(clazz, controllerName, BEAN_BUILDER);
}
public static FXBaseController getFXController(Class clazz, String controllerName, BeanBuilder beanBuilder) {
FXBaseController fxBaseController = getFxBaseController(clazz, controllerName, beanBuilder);
return fxBaseController;
}
private static void register(FXBaseController fxBaseController, FXBaseController fxBaseControllerProxy) {
FXPlusContext.addController(fxBaseController);
MessageQueue.getInstance().registerCosumer(fxBaseController, fxBaseControllerProxy);
FXPlusContext.addController(fxBaseController); //保存
MessageQueue.getInstance().registerCosumer(fxBaseController, fxBaseControllerProxy); // 添加进入消息队列 信号功能
}
private static FXBaseController getFxBaseController(Class clazz, String controllerName) {
return null;
}
/**
*
* @param clazz instance that extends by FXBaseController
* @param clazz instance that extends by FXBaseController
* @param controllerName
* @return
*/
private static FXBaseController getFxBaseController(Class clazz, String controllerName) {
Annotation[] annotations = clazz.getAnnotations();
private static FXBaseController getFxBaseController(Class clazz, String controllerName, BeanBuilder beanBuilder) {
Boolean isController = false;
URL fxmlPath;
Boolean isWindow = false;
FXWindow fxWindow = null;
FXController fxController = null;
//reflect and get FXController cn.edu.scau.biubiusuisui.annotation
for (Annotation annotation : annotations) {
if (annotation.annotationType().equals(FXController.class)) {
fxController = (FXController) annotation;
isController = true;
} else if (annotation.annotationType().equals(FXWindow.class)) {
fxWindow = (FXWindow) annotation;
isWindow = true;
}
}
fxController = (FXController) clazz.getDeclaredAnnotation(FXController.class);
fxWindow = (FXWindow) clazz.getDeclaredAnnotation(FXWindow.class);
Pane parent = null;
FXBaseController fxControllerProxy = null;
FXBaseController fxBaseController = null;
if (isController) {
if (fxController != null) {
String name = fxController.path();
fxmlPath = clazz.getClassLoader().getResource(name);
FXMLLoaderPlus fxmlLoader = new FXMLLoaderPlus(fxmlPath);
try {
// create a cn.edu.scau.biubiusuisui.proxy for monitoring methods
fxBaseController = (FXBaseController) clazz.newInstance();
// create a cn.edu.scau.biubiusuisui.proxy for monitoring methods
fxBaseController = (FXBaseController) beanBuilder.getBean(clazz);
if (fxBaseController != null) {
FXControllerProxy controllerProxy = new FXControllerProxy();
fxControllerProxy = (FXBaseController) controllerProxy.getInstance(fxBaseController);
fxControllerProxy.setName(controllerName);
fxBaseController.setName(controllerName);
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
fxmlLoader.setRoot(fxControllerProxy);
fxmlLoader.setController(fxControllerProxy);
try {
parent = fxmlLoader.load();
if (controllerName != null) {
fxControllerProxy.setName(controllerName);
fxBaseController.setName(controllerName);
} else {
fxBaseController.setName(parent.getId());
}
register(fxBaseController, fxControllerProxy);
} catch (IOException exception) {
throw new RuntimeException(exception);
}
}
fxmlLoader.setRoot(fxControllerProxy);
fxmlLoader.setController(fxControllerProxy);
try {
parent = fxmlLoader.load();
} catch (IOException exception) {
throw new RuntimeException(exception);
}
}else{
} else {
return null;
}
//register
register(fxBaseController, fxControllerProxy);
if (isWindow) {
Stage stage = new Stage();
fxControllerProxy.setStage(stage);
fxBaseController.setStage(stage);
double preWidth = fxWindow.preWidth() == 0 ? fxControllerProxy.getPrefWidth() : fxWindow.preWidth();
double preHeight = fxWindow.preHeight() == 0 ? fxControllerProxy.getPrefWidth() : fxWindow.preHeight();
Scene scene = new Scene(fxControllerProxy, preWidth, preHeight);
stage.setScene(scene);
windowAnnotationParser.parse(stage, fxControllerProxy, fxWindow);
stage.show();
if (fxWindow != null) {
createWindow(fxWindow, fxControllerProxy, fxBaseController);
}
return fxControllerProxy;
}
private static void createWindow(FXWindow fxWindow, FXBaseController fxControllerProxy, FXBaseController fxBaseController) {
Stage stage = new Stage();
fxControllerProxy.setStage(stage);
fxBaseController.setStage(stage);
double preWidth = fxWindow.preWidth() == 0 ? fxControllerProxy.getPrefWidth() : fxWindow.preWidth();
double preHeight = fxWindow.preHeight() == 0 ? fxControllerProxy.getPrefWidth() : fxWindow.preHeight();
Scene scene = new Scene(fxControllerProxy, preWidth, preHeight);
stage.setScene(scene);
windowAnnotationParser.parse(stage, fxControllerProxy, fxWindow);
stage.show();
}
private static void parseControllerBindExpression(FXBaseController fxBaseController, ObservableMap<String, Object> namespaces) {
expressionParser.parse(fxBaseController, namespaces);
}
}

View File

@@ -0,0 +1,56 @@
package cn.edu.scau.biubiusuisui.function;
import cn.edu.scau.biubiusuisui.annotation.FXBind;
import cn.edu.scau.biubiusuisui.entity.FXBaseController;
import cn.edu.scau.biubiusuisui.entity.FXPlusContext;
import com.sun.javafx.fxml.BeanAdapter;
import com.sun.javafx.fxml.expression.Expression;
import com.sun.javafx.fxml.expression.ExpressionValue;
import javafx.beans.property.Property;
import javafx.beans.value.ObservableValue;
import javafx.collections.ObservableMap;
import java.lang.reflect.Field;
import java.util.Map;
/**
* @Author jack
* @Date:2019/7/4 13:55
*/
public class FXExpressionParser {
private static final String BIND_EXPRESSION_PREFIX = "${";
private static final String BIND_EXPRESSION_SUFIX = "}";
public static void parse(FXBaseController fxBaseController, ObservableMap<String, Object> namespaces) {
// Class clazz = fxBaseController.getClass();
// Field[] fields = clazz.getDeclaredFields();
// for (Field field : fields) {
// FXBind fxBind = field.getDeclaredAnnotation(FXBind.class);
// if (fxBind != null) {
// String[] names = fxBind.bind();
// for (String propertyName : names) {
// String args[] = propertyName.split("=");
// String name = args[0];
// String value = args[1];
// if (value.startsWith(BIND_EXPRESSION_PREFIX) && value.endsWith(BIND_EXPRESSION_SUFIX)) {
// value = value.substring(BIND_EXPRESSION_PREFIX.length(), value.length() - 1);
// Object object = null;
// try {
// field.setAccessible(true);
// object = field.get(fxBaseController);
// } catch (IllegalAccessException e) {
// e.printStackTrace();
// }
//
// BeanAdapter targetAdapter = new BeanAdapter(object);
// ObservableValue<Object> propertyModel = targetAdapter.getPropertyModel(name);
// Class<?> type = targetAdapter.getType(name);
// if (propertyModel instanceof Property<?>) {
// ((Property<Object>) propertyModel).bind(FXPlusContext.getEntityPropertyByName(fxBaseController,));
// }
// }
// }
// }
}
}

View File

@@ -58,6 +58,8 @@ public class MessageQueue {
if (lists != null) {
for (FXMethodEntity fxMethodEntity : lists) {
Method method = fxMethodEntity.getMethod();
method.setAccessible(true);
FXBaseController fxBaseController = fxMethodEntity.getFxBaseController();
if (method.getParameterCount() == 0) {
try {

View File

@@ -8,6 +8,7 @@ import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
/**
@@ -23,18 +24,23 @@ public class FXControllerProxy implements MethodInterceptor {
FXBaseController target;
public Object getInstance(FXBaseController target) {
this.target = target;
Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(this.target.getClass());
enhancer.setCallback(this);
return enhancer.create();
Object proxy = enhancer.create();
inject(target, proxy);
return proxy;
}
@Override
public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
Object o1 = methodProxy.invokeSuper(o, objects);
Annotation []annotations = method.getDeclaredAnnotations();
// System.out.println("name" +target.getName());
for(Annotation annotation : annotations){
if(FXSender.class.equals(annotation.annotationType())){
FXSender fxSender = (FXSender)annotation;
@@ -44,10 +50,24 @@ public class FXControllerProxy implements MethodInterceptor {
}else{
name += fxSender.name();
}
System.out.println("method" + name);
MessageQueue.getInstance().sendMsg(name,o1);
}
}
return o1;
}
private void inject(Object target,Object proxy){
Field[] fields = target.getClass().getDeclaredFields();
for (Field field : fields) {
field.setAccessible(true);
try {
Object filedValue = field.get(target);
System.out.println(filedValue);
field.set(proxy,filedValue);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
}

View File

@@ -41,8 +41,8 @@ public class FXEntityProxy implements MethodInterceptor {
*/
@Override
public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
Object o1 = methodProxy.invokeSuper(o, objects);
Object o1 = methodProxy.invokeSuper(o, objects);
String methodName = method.getName();
String fieldName = null;
if (methodName.length() >= 3) {
@@ -55,7 +55,7 @@ public class FXEntityProxy implements MethodInterceptor {
if(fxFieldPropertyMapping == null || property == null){
return o1;
}
System.out.println("??? <--->");
Class type = fxFieldPropertyMapping.getType();
if (methodName.startsWith("set")) {
if(Boolean.class.equals(type)){