diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..4ab6e41
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,4 @@
+.idea
+*~*
+*.iml
+target
diff --git a/README.md b/README.md
index 36e2d83..e620ac9 100644
--- a/README.md
+++ b/README.md
@@ -1,14 +1,115 @@
# JavaAOP
+
## 内容
-* 使用JDK的动态代理实现了简单地AOP思想编程
-* 使用反射结合JDK动态代理实现了类似于Spring框架的简单“ @xxx(xx="xxxx") ”的数据注入
-* 仅此,分享给大家,正在学爪哇的大家
+- 使用 JDK 的动态代理实现了简单地 AOP 思想编程
+- 使用反射结合 JDK 动态代理实现了类似于 Spring
+ 框架的简单“ @xxx(xx="xxxx") ”的数据注入
+- 仅此,分享给大家,正在学爪哇的大家
## 相关文章
-* [知乎-怎样理解 java 注解和运用注解编程?Accelerator的回答](https://www.zhihu.com/question/47449512/answer/106034220)
-* [知乎-Accelerator的日常学习与分享专栏](https://zhuanlan.zhihu.com/Accelerator)
-## 关于
-* QQ群 :[吾爱Java: 170936712](http://jq.qq.com/?_wv=1027&k=28XUDSI)
-* 个人博客 :[https://matrixseven.github.io](https://matrixseven.github.io)
+- [知乎-怎样理解 java 注解和运用注解编程?Accelerator的回答](https://www.zhihu.com/question/47449512/answer/106034220)
+- [知乎-Accelerator的日常学习与分享专栏](https://zhuanlan.zhihu.com/Accelerator)
+
+---
+
+使用反射结合 JDK 动态代理实现了类似于 Spring 框架
+的简单 “@xxx(xx="xxxx") ” 的数据注入。
+
+Quotes:
+
+> 在软件业,**AOP 为 Aspect Oriented Programming**
+> 的缩写,意为:面向切面编程,通过
+>
+> - **预编译方式**和
+> - **运行期动态代理**
+>
+> 实现程序功能的统一维护的一种技术。AOP 是 OOP 的延
+> 续,是软件开发中的一个热点,也是 Spring 框架中的一
+> 个重要内容,是函数式编程的一种衍生范型。利用 AOP
+> 可以对业务逻辑的各个部分进行隔离,从而使得业务逻辑
+> 各部分之间的耦合度降低,提高程序的可重用性,同时提
+> 高了开发的效率。
+>
+> Aspect,没错,的确是 “方面” 的意思。不过,华语传统
+> 语义中的 “方面”,大多数情况下指的是一件事情的不同
+> 维度、或者说不同角度上的特性,比如我们常说:“这件
+> 事情要从几个方面来看待”,往往意思是:需要从不同的
+> 角度来看待同一个事物。
+>
+> **这里的 “方面”,指的是事物的外在特性在不同观察角
+> 度下的体现。**而在 AOP 中, Aspect 的含义,可能更
+> 多的理解为 “切面” 比较合适。所以笔者更倾向于 “面向
+> 切面编程” 的译法。
+
+---
+
+```
+== 给 'com.tangzhixiong.javaaop.DogImp@deb6432' 注入属性 ==
+属性注入:'name' = '坏🐶' (通过 setter)
+属性无注入:'property'
+== 给 'com.tangzhixiong.javaaop.DogImp@deb6432' 注入方法 ==
+方法注入:'setProperty' = '水陆两栖战士'
+方法注入:'setProperty' = '水陆两栖战士'
+方法无注入:'getProperty'
+方法无注入:'getProperty'
+方法无注入:'getName'
+方法无注入:'setName'
+方法无注入:'setName'
+ 成功拦截 'getProperty' 方法, 启动
+
+ 成功拦截 'getProperty' 方法, 结束
+```
+
+## 小结
+
+- 一个类的 annotation 可以注解到属性(field)也可以注解到方法(method)
+- 注解为何生效?因为你多加了一层 indirection,解析了注解,包装了一下,所以注解有效
+- 从类上我们可以拿到 fields 和 methods,以及上面的注解
+- 获取注解的时候你要告诉 field 你要啥样的注解(注解类名称),它会给你返回一个注解类的对象
+- 这个对象的属性和值就是注解的 KEY=VALUE 键值对
+- 注入就是把这个注解信息(一个注解类的成员,包含这种注解的一切可能信息(有默认值)拿到,然后自己调用相应的函数来让使生效
+
+为啥注解类的定义要用 `@interface`?
+
+- 先看这篇文章:https://stackoverflow.com/questions/918393/whats-the-difference-between-interface-and-interface-in-java
+- 这个命名的逻辑从两点来,一个是注解也是 `@` 开头的,二是注解不能被实例化,所以用 interface。
+
+## [Java: Annotations](http://docs.oracle.com/javase/1.5.0/docs/guide/language/annotations.html)
+
+Here is an example annotation type declaration:
+
+ /**
+ * Describes the Request-For-Enhancement(RFE) that led
+ * to the presence of the annotated API element.
+ */
+ public @interface RequestForEnhancement {
+ int id();
+ String synopsis();
+ String engineer() default "[unassigned]";
+ String date(); default "[unimplemented]";
+ }
+
+**Once an annotation type is defined, you can use
+it to annotate declarations.** An annotation is a
+special kind of modifier, and can be used anywhere
+that other modifiers (such as public, static, or
+final) can be used.
+**@ANNOTATION 是一个 modifier,就跟 public、static,final 一样。
+通产放在其它 modifier 前面**
+By convention, annotations precede other modifiers.
+**Annotations consist of an
+at-sign (@) followed by an annotation type and a
+parenthesized list of element-value pairs.** The
+values must be compile-time constants. Here is a
+method declaration with an annotation
+corresponding to the annotation type declared
+above:
+
+ @RequestForEnhancement(
+ id = 2868724,
+ synopsis = "Enable time-travel",
+ engineer = "Mr. Peabody",
+ date = "4/1/3007"
+ )
diff --git a/junit-4.8.1.jar b/junit-4.8.1.jar
deleted file mode 100644
index 524cd65..0000000
Binary files a/junit-4.8.1.jar and /dev/null differ
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..460c266
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,54 @@
+
+
+ 4.0.0
+
+ com.tangzhixiong
+ javaaop
+ 1.0
+
+
+ 1.8
+ 1.8
+ UTF-8
+ UTF-8
+
+
+
+
+ junit
+ junit
+ 4.12
+
+
+ org.hamcrest
+ hamcrest-junit
+ 2.0.0.0
+
+
+
+
+ javaaop
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 2.3.2
+
+ ${project.java.version}
+ ${project.java.version}
+ ${project.build.sourceEncoding}
+
+
+
+ org.apache.maven.plugins
+ maven-resources-plugin
+ 2.6
+
+ ${project.build.sourceEncoding}
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/com/tangzhixiong/javaaop/AOPHandle.java b/src/main/java/com/tangzhixiong/javaaop/AOPHandle.java
new file mode 100644
index 0000000..529b4fd
--- /dev/null
+++ b/src/main/java/com/tangzhixiong/javaaop/AOPHandle.java
@@ -0,0 +1,34 @@
+package com.tangzhixiong.javaaop;
+
+import com.tangzhixiong.javaaop.imp.AOPMethod;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+
+public class AOPHandle implements InvocationHandler {
+ private Object object;
+ private AOPMethod method;
+
+ public AOPHandle(Object object, AOPMethod method) {
+ this.object = object;
+ this.method = method;
+ }
+
+ /**
+ * 这个方法会自动调用, Java 动态代理机制
+ * 会传入下面是个参数
+ *
+ * @param Object proxy 代理对象的接口, 不同于对象
+ * @param Method method 被调用方法
+ * @param Object[] args 方法参数
+ * 不能使用 invoke 时使用 proxy 作为反射参数时, 因为代理对象的接口, 不同于对象
+ * 这种代理机制是面向接口,而不是面向类的
+ **/
+ @Override
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ this.method.before(proxy, method, args);
+ Object ret = method.invoke(object, args);
+ this.method.after(proxy, method, args);
+ return ret;
+ }
+}
diff --git a/src/main/java/com/tangzhixiong/javaaop/AnimalFactory.java b/src/main/java/com/tangzhixiong/javaaop/AnimalFactory.java
new file mode 100644
index 0000000..c37f450
--- /dev/null
+++ b/src/main/java/com/tangzhixiong/javaaop/AnimalFactory.java
@@ -0,0 +1,54 @@
+package com.tangzhixiong.javaaop;
+
+import com.tangzhixiong.javaaop.annon.AnnoInjection;
+import com.tangzhixiong.javaaop.imp.AOPMethod;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+
+public class AnimalFactory {
+
+ private static Object getAnimalBase(Object obj, AOPMethod method) {
+ /*
+ public static Object newProxyInstance(ClassLoader loader,
+ Class>[] interfaces,
+ InvocationHandler h)
+ */
+ return Proxy.newProxyInstance(
+ obj.getClass().getClassLoader(),
+ obj.getClass().getInterfaces(),
+ new AOPHandle(AnnoInjection.getBean(obj), method));
+// (proxy, method1, args) -> method1.invoke(AnnoInjection.getBean(proxy),args));
+ }
+
+ @SuppressWarnings("unchecked")
+ public static T getAnimal(Object obj, AOPMethod aopMethod) {
+ // 调用方法:AnimalInterface dog = AnimalFactory.getAnimal(new DogImp(), new AOPMethod() {...});
+ return (T) getAnimalBase(obj, aopMethod);
+ }
+
+ @SuppressWarnings("unchecked")
+ public static T getAnimal(String className, AOPMethod method) {
+ // 调用方法:AnimalInterface dog = AnimalFactory.getAnimal("com.tangzhixiong.javaaop.DogImp", new AOPMethod() {...}
+ Object obj = null;
+ try {
+ obj = getAnimal(Class.forName(className).newInstance(), method);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return (T) obj;
+ }
+
+ @SuppressWarnings("unchecked")
+ public static T getAnimal(Class extends T> clz, AOPMethod method) {
+ // 调用方法: AnimalInterface dog = AnimalFactory.getAnimal(DogImp.class, new AOPMethod() {...});
+ Object obj = null;
+ try {
+ obj = getAnimalBase(clz.newInstance(), method);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return (T) obj;
+ }
+}
diff --git a/src/main/java/com/tangzhixiong/javaaop/DogImp.java b/src/main/java/com/tangzhixiong/javaaop/DogImp.java
new file mode 100644
index 0000000..c528ca1
--- /dev/null
+++ b/src/main/java/com/tangzhixiong/javaaop/DogImp.java
@@ -0,0 +1,38 @@
+package com.tangzhixiong.javaaop;
+
+import com.tangzhixiong.javaaop.annon.Seven;
+import com.tangzhixiong.javaaop.imp.AnimalInterface;
+
+public class DogImp implements AnimalInterface {
+
+// @Seven,这个注解会注入默认的值,也就是"🐶"
+// @Seven("坏🐶"),这个也等价,如果注解里面的 KEY=VALUE 没有 KEY,默认就是 value=VALUE。
+ @Seven(value = "坏🐶")
+ private String name;
+
+ // 无注入
+ private String property;
+
+ @Override
+ public DogImp setName(String name) {
+ this.name = name;
+ return this;
+ }
+
+ @Override
+ public String getName() {
+ return this.name;
+ }
+
+ @Override
+ @Seven(Property = "水陆两栖战士")
+ public DogImp setProperty(Object Property) {
+ this.property = (String)Property;
+ return this;
+ }
+
+ @Override
+ public String getProperty() {
+ return this.property;
+ }
+}
diff --git a/src/main/java/com/tangzhixiong/javaaop/annon/AnnoInjection.java b/src/main/java/com/tangzhixiong/javaaop/annon/AnnoInjection.java
new file mode 100644
index 0000000..94db3b9
--- /dev/null
+++ b/src/main/java/com/tangzhixiong/javaaop/annon/AnnoInjection.java
@@ -0,0 +1,59 @@
+package com.tangzhixiong.javaaop.annon;
+
+import com.tangzhixiong.javaaop.DogImp;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+public class AnnoInjection {
+
+ public static Object getBean(Object obj) {
+ try {
+
+ System.err.println("== 给 '" + obj + "' 注入属性 ==");
+ // 获得类属性
+ Field declaredFields[] = obj.getClass().getDeclaredFields(); // DogImp.class.getDeclaredFields();
+ // 遍历属性
+ for (Field field : declaredFields) {
+ // 获得属性上的注解
+ Seven annotation = field.getAnnotation(Seven.class);
+ if (annotation == null) {
+ System.err.println("属性无注入:'" + field.getName() + "'");
+ } else {
+ System.err.println("属性注入:'" + field.getName() + "' = '" + annotation.value() + "' (通过 setter)");
+ // ????? 反射调用 public set 方法, 如果为访问级别 private, 那么可以直接使用属性的 set(obj,value);
+ String fieldSetter = "set" + field.getName().substring(0, 1).toUpperCase() + field.getName().substring(1);
+ obj.getClass()
+ .getMethod(fieldSetter, new Class>[]{String.class}) // 函数名和参数类型 <=> 函数签名
+ .invoke(obj, annotation.value()); // 我们知道这个 setter 怎么调用
+ }
+ }
+
+ System.err.println("== 给 '" + obj + "' 注入方法 ==");
+ // 获得所有方法
+ /*
+ * Returns an array containing {@code Method} objects reflecting all the
+ * declared methods of the class or interface represented by this {@code
+ * Class} object, including public, protected, default (package)
+ * access, and private methods, but excluding inherited methods.
+ */
+ Method declaredMethods[] = obj.getClass().getDeclaredMethods();
+ for (Method method : declaredMethods) {
+ // 获得方法注解
+ Seven annotation = method.getAnnotation(Seven.class);
+ if (annotation == null) {
+ System.err.println("方法无注入:'" + method.getName() + "'");
+ } else {
+ System.err.println("方法注入:'" + method.getName() + "' = '" + annotation.Property() + "'");
+ method.invoke(obj, annotation.Property());
+ }
+ }
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return obj;
+ }
+
+}
diff --git a/src/proxy/annon/Seven.java b/src/main/java/com/tangzhixiong/javaaop/annon/Seven.java
similarity index 52%
rename from src/proxy/annon/Seven.java
rename to src/main/java/com/tangzhixiong/javaaop/annon/Seven.java
index 3070908..1dc088b 100644
--- a/src/proxy/annon/Seven.java
+++ b/src/main/java/com/tangzhixiong/javaaop/annon/Seven.java
@@ -1,15 +1,18 @@
-package proxy.annon;
+package com.tangzhixiong.javaaop.annon;
+
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.FIELD,ElementType.METHOD})
+@Target({ElementType.FIELD, ElementType.METHOD})
public @interface Seven {
-
- public String value() default "С";
-
- public String Property() default "";
-
+
+ // for fields
+ String value() default "🐶";
+
+ // for methods
+ String Property() default "无属性";
+
}
diff --git a/src/main/java/com/tangzhixiong/javaaop/imp/AOPMethod.java b/src/main/java/com/tangzhixiong/javaaop/imp/AOPMethod.java
new file mode 100644
index 0000000..4125d40
--- /dev/null
+++ b/src/main/java/com/tangzhixiong/javaaop/imp/AOPMethod.java
@@ -0,0 +1,11 @@
+package com.tangzhixiong.javaaop.imp;
+
+import java.lang.reflect.Method;
+
+public interface AOPMethod {
+ // 实例方法执行前执行的方法
+ void after(Object proxy, Method method, Object[] args);
+
+ // 实例方法执行后执行的方法
+ void before(Object proxy, Method method, Object[] args);
+}
\ No newline at end of file
diff --git a/src/main/java/com/tangzhixiong/javaaop/imp/AnimalInterface.java b/src/main/java/com/tangzhixiong/javaaop/imp/AnimalInterface.java
new file mode 100644
index 0000000..a01851d
--- /dev/null
+++ b/src/main/java/com/tangzhixiong/javaaop/imp/AnimalInterface.java
@@ -0,0 +1,10 @@
+package com.tangzhixiong.javaaop.imp;
+
+public interface AnimalInterface {
+
+ T setName(String name);
+ String getName();
+
+ Object getProperty();
+ T setProperty(Object Property);
+}
diff --git a/src/main/test/com/tangzhixiong/javaaop/AnimalFactoryTest.java b/src/main/test/com/tangzhixiong/javaaop/AnimalFactoryTest.java
new file mode 100644
index 0000000..dc40247
--- /dev/null
+++ b/src/main/test/com/tangzhixiong/javaaop/AnimalFactoryTest.java
@@ -0,0 +1,36 @@
+package com.tangzhixiong.javaaop;
+
+import com.tangzhixiong.javaaop.imp.AOPMethod;
+import com.tangzhixiong.javaaop.imp.AnimalInterface;
+import org.junit.Test;
+
+import java.lang.reflect.Method;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+public class AnimalFactoryTest {
+
+ @Test
+ public void should_inject() throws Exception {
+ AnimalInterface dog = AnimalFactory.getAnimal(DogImp.class, new AOPMethod() {
+ // 这里写方法执行前的 AOP 切入方法
+ public void before(Object proxy, Method method, Object[] args) {
+ if (method.getName().equals("getProperty")) {
+ System.err.println("\t\t成功拦截 '" + method.getName() + "' 方法, 启动 ");
+ }
+ }
+
+ // 这里系方法执行后的 AOP 切入方法
+ public void after(Object proxy, Method method, Object[] args) {
+ if (method.getName().equals("getProperty"))
+ System.err.println("\t\t成功拦截 '" + method.getName() + "' 方法, 结束 ");
+
+ }
+ });
+ assertThat(dog.getName(), is("坏🐶"));
+ assertThat(dog.setName("好🐶").getName(), is("好🐶"));
+ assertThat(dog.getProperty(), is("水陆两栖战士"));
+ assertThat(dog.setProperty("不会游泳").getProperty(), is("不会游泳"));
+ }
+}
\ No newline at end of file
diff --git a/src/main/test/com/tangzhixiong/javaaop/DogImpTest.java b/src/main/test/com/tangzhixiong/javaaop/DogImpTest.java
new file mode 100644
index 0000000..81cf013
--- /dev/null
+++ b/src/main/test/com/tangzhixiong/javaaop/DogImpTest.java
@@ -0,0 +1,18 @@
+package com.tangzhixiong.javaaop;
+
+import com.tangzhixiong.javaaop.imp.AnimalInterface;
+import org.junit.Test;
+
+import static org.junit.Assert.assertNull;
+
+public class DogImpTest {
+ @Test
+ public void should_fail_to_inject() throws Exception {
+ // 直接拿,注解肯定没有生效,必须要经过 proxy 这一层转化
+ // Butler Lampson:
+ // All problems in computer science can be solved by another level of indirection
+ AnimalInterface animal = new DogImp();
+ assertNull(animal.getName());
+ assertNull(animal.getProperty());
+ }
+}
\ No newline at end of file
diff --git a/src/proxy/AOPHandle.java b/src/proxy/AOPHandle.java
deleted file mode 100644
index a27db87..0000000
--- a/src/proxy/AOPHandle.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package proxy;
-
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-
-import proxy.imp.AOPMethod;
-
-public class AOPHandle implements InvocationHandler{
- //
- private AOPMethod method;
- private Object o;
- public AOPHandle(Object o,AOPMethod method) {
- this.o=o;
- this.method=method;
- }
- /**
- * Զ,Java̬
- * ᴫǸ
- * @param Object proxy Ľӿ,ͬڶ
- * @param Method method ÷
- * @param Object[] args
- * ʹinvokeʱʹproxyΪʱ,ΪĽӿ,ͬڶ
- * ִӿڣ
- **/
- @Override
- public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
- Object ret=null;
- //ĵĵطŶ
- this.method.before(proxy, method, args);
- ret=method.invoke(o, args);
- //ĵĵطŶ
- this.method.after(proxy, method, args);
- return ret;
- }
-}
diff --git a/src/proxy/AOPTest.java b/src/proxy/AOPTest.java
deleted file mode 100644
index 100e050..0000000
--- a/src/proxy/AOPTest.java
+++ /dev/null
@@ -1,38 +0,0 @@
-package proxy;
-
-import java.lang.reflect.Method;
-
-import org.junit.runner.RunWith;
-import org.junit.runners.BlockJUnit4ClassRunner;
-import proxy.imp.AOPMethod;
-import proxy.imp.AnimalInterface;
-
-@RunWith(BlockJUnit4ClassRunner.class)
-public class AOPTest {
-
- public static void main(String[] args) {
-
- AnimalInterface dog = AnimalFactory.getAnimal(DogImp.class, new AOPMethod() {
- // дִǰAOP뷽
- public void before(Object proxy, Method method, Object[] args) {
- if (method.getName().equals("getProperty")) {
- System.err.println("ɹ" + method.getName() + ",");
- }
- }
-
- // ϵִкAOP뷽
- public void after(Object proxy, Method method, Object[] args) {
- if (method.getName().equals("getProperty"))
- System.err.println("ɹ" + method.getName() + ",");
-
- }
- });
- dog.say();
- String name1 = "ҵ" + dog.getName();
- System.out.println(name1);
- dog.setName("");
- String name2 = "ҵ" + dog.getName();
- System.out.println(name2);
- dog.getProperty();
- }
-}
diff --git a/src/proxy/AnimalFactory.java b/src/proxy/AnimalFactory.java
deleted file mode 100644
index b8b2c24..0000000
--- a/src/proxy/AnimalFactory.java
+++ /dev/null
@@ -1,61 +0,0 @@
-package proxy;
-
-import java.lang.reflect.Proxy;
-
-import proxy.annon.AnnoInjection;
-import proxy.imp.AOPMethod;
-public class AnimalFactory {
-
- /***
- * ȡ
- * @param obj
- * @return
- */
- private static Object getAnimalBase(Object obj,AOPMethod method){
- //ȡ
- return Proxy.newProxyInstance(obj.getClass().getClassLoader(),
- obj.getClass().getInterfaces(),
- new AOPHandle(AnnoInjection.getBean(obj),method));
- }
-
- /***
- * ȡ
- * @param obj
- * @return
- */
- @SuppressWarnings("unchecked")
- public static T getAnimal(Object obj,AOPMethod aopMethod){
- return (T) getAnimalBase(obj,aopMethod);
- }
- /***
- * ȡ
- * @param className
- * @return
- */
- @SuppressWarnings("unchecked")
- public static T getAnimal(String className,AOPMethod method){
- Object obj=null;
- try {
- obj= getAnimalBase(Class.forName(className).newInstance(),method);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return (T)obj;
- }
-
- /***
- * ȡ
- * @param clz
- * @return
- */
- @SuppressWarnings("unchecked")
- public static T getAnimal(Class> clz,AOPMethod method){
- Object obj=null;
- try {
- obj= getAnimalBase(clz.newInstance(),method);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return (T)obj;
- }
-}
diff --git a/src/proxy/DogImp.java b/src/proxy/DogImp.java
deleted file mode 100644
index 5a0d866..0000000
--- a/src/proxy/DogImp.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package proxy;
-
-import proxy.annon.Seven;
-import proxy.imp.AnimalInterface;
-
-public class DogImp implements AnimalInterface {
-
- @Seven(value = "Lumia")
- private String name;
-
- private String Property;
-
- public DogImp() {
- }
-
- @Override
- public void setName(String name) {
- this.name = name;
- }
-
- @Override
- public String getName() {
- return this.name;
- }
-
- @Override
- public void say() {
- System.out.println("С:.....");
- }
-
- @Override
- @Seven(Property = "ˮ½սʿ")
- public void setProperty(String Property) {
- this.Property = Property;
- }
-
- @Override
- public void getProperty() {
- System.out.println(this.name + this.Property);
- }
-}
diff --git a/src/proxy/Test.java b/src/proxy/Test.java
deleted file mode 100644
index 6d4d978..0000000
--- a/src/proxy/Test.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package proxy;
-
-public class Test {
-
- public static void main(String[] args) {
- DogImp dogImp = new DogImp();
- System.out.println(dogImp.getName());
- dogImp.getProperty();
- }
-}
diff --git a/src/proxy/annon/AnnoInjection.java b/src/proxy/annon/AnnoInjection.java
deleted file mode 100644
index 455a90f..0000000
--- a/src/proxy/annon/AnnoInjection.java
+++ /dev/null
@@ -1,42 +0,0 @@
-package proxy.annon;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-
-public class AnnoInjection {
-
- public static Object getBean(Object obj) {
- try {
- //
- Field f[] = obj.getClass().getDeclaredFields();
- //
- for (Field ff : f) {
- // ϵע
- Seven s = ff.getAnnotation(Seven.class);
- if (s != null) {
- System.err.println("ע" + ff.getName() + "" + "\t\t" + s.value());
- // public set,Ϊʼprivate,ôֱʹԵset(obj,
- // value);
- obj.getClass()
- .getMethod("set" + ff.getName().substring(0, 1).toUpperCase() + ff.getName().substring(1),
- new Class>[] { String.class })
- .invoke(obj, s.value());
- }
- }
- // з
- Method m[] = obj.getClass().getDeclaredMethods();
- for (Method mm : m) {
- // ÷ע
- Seven s = mm.getAnnotation(Seven.class);
- if (s != null) {
- System.err.println("ע" + mm.getName() + "" + "\t" + s.Property());
- mm.invoke(obj, s.Property());
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return obj;
- }
-
-}
diff --git a/src/proxy/imp/AOPMethod.java b/src/proxy/imp/AOPMethod.java
deleted file mode 100644
index e456efd..0000000
--- a/src/proxy/imp/AOPMethod.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package proxy.imp;
-
-import java.lang.reflect.Method;
-
-public interface AOPMethod{
- //ʵִǰִеķ
- void after(Object proxy, Method method, Object[] args);
- //ʵִкִеķ
- void before(Object proxy, Method method, Object[] args);
-}
\ No newline at end of file
diff --git a/src/proxy/imp/AnimalInterface.java b/src/proxy/imp/AnimalInterface.java
deleted file mode 100644
index 0344c58..0000000
--- a/src/proxy/imp/AnimalInterface.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package proxy.imp;
-
-public interface AnimalInterface {
- //
- void setName(String name);
- //ȡ
- String getName();
- //
- void say();
- //ȡ
- void getProperty();
- //
- void setProperty(String Property);
-}