Skip to content

Commit b85c4ea

Browse files
committed
java/se: refine proxy sample
1 parent d402018 commit b85c4ea

File tree

38 files changed

+430
-98
lines changed

38 files changed

+430
-98
lines changed

java/javaee/annotation/annotation-spring-aop/src/main/java/cn/edu/ntu/javaee/annotation/usage/before/proxy/ArithmeticCalculatorProxy.java

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -46,41 +46,41 @@ public Object getProxy() {
4646
}
4747

4848
// /** mock up Proxy work */
49-
// class $Proxy0 extends Proxy implements ArithmeticCalculator {
50-
//
51-
// /**
52-
// * Constructs a new {@code Proxy} instance from a subclass (typically, a dynamic proxy
53-
// class)
54-
// * with the specified value for its invocation handler.
55-
// *
56-
// * @param h the invocation handler for this proxy instance
57-
// * @throws NullPointerException if the given invocation handler, {@code h}, is {@code
58-
// null}.
59-
// */
60-
// protected $Proxy0(InvocationHandler h) {
61-
// super(h);
62-
// }
63-
//
64-
// private Method METHOD_NAME;
65-
//
66-
// @Override
67-
// public int add(int a, int b) throws Throwable {
68-
// return (int) h.invoke(this, METHOD_NAME, new Object[] {a, b});
69-
// }
70-
//
71-
// @Override
72-
// public int sub(int a, int b) {
73-
// return 0;
74-
// }
75-
//
76-
// @Override
77-
// public int mul(int a, int b) {
78-
// return 0;
79-
// }
80-
//
81-
// @Override
82-
// public int div(int a, int b) {
83-
// return 0;
84-
// }
85-
// }
49+
class $Proxy0 extends Proxy implements ArithmeticCalculator {
50+
51+
/**
52+
* Constructs a new {@code Proxy} instance from a subclass (typically, a dynamic proxy
53+
class)
54+
* with the specified value for its invocation handler.
55+
*
56+
* @param h the invocation handler for this proxy instance
57+
* @throws NullPointerException if the given invocation handler, {@code h}, is {@code
58+
null}.
59+
*/
60+
protected $Proxy0(InvocationHandler h) {
61+
super(h);
62+
}
63+
64+
private Method METHOD_NAME;
65+
66+
@Override
67+
public int add(int a, int b) throws Throwable {
68+
return (int) h.invoke(this, METHOD_NAME, new Object[] {a, b});
69+
}
70+
71+
@Override
72+
public int sub(int a, int b) {
73+
return 0;
74+
}
75+
76+
@Override
77+
public int mul(int a, int b) {
78+
return 0;
79+
}
80+
81+
@Override
82+
public int div(int a, int b) {
83+
return 0;
84+
}
85+
}
8686
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package cn.edu.ntu.java.javase.reflect.classloader;
1+
package cn.edu.ntu.java.javase.jvm.classloader;
22

33
import org.slf4j.Logger;
44
import org.slf4j.LoggerFactory;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package cn.edu.ntu.java.javase.reflect.model;
1+
package cn.edu.ntu.java.javase.jvm.spi;
22

33
import org.slf4j.Logger;
44
import org.slf4j.LoggerFactory;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
package cn.edu.ntu.java.javase.reflect.model.impl;
1+
package cn.edu.ntu.java.javase.jvm.spi.impl;
22

3-
import cn.edu.ntu.java.javase.reflect.model.Animal;
3+
import cn.edu.ntu.java.javase.jvm.spi.Animal;
44
import org.slf4j.Logger;
55
import org.slf4j.LoggerFactory;
66

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
package cn.edu.ntu.java.javase.reflect.model.impl;
1+
package cn.edu.ntu.java.javase.jvm.spi.impl;
22

3-
import cn.edu.ntu.java.javase.reflect.model.Animal;
3+
import cn.edu.ntu.java.javase.jvm.spi.Animal;
44
import org.slf4j.Logger;
55
import org.slf4j.LoggerFactory;
66

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
package cn.edu.ntu.java.javase.reflect.model.impl;
1+
package cn.edu.ntu.java.javase.jvm.spi.impl;
22

3-
import cn.edu.ntu.java.javase.reflect.model.Animal;
3+
import cn.edu.ntu.java.javase.jvm.spi.Animal;
44
import org.slf4j.Logger;
55
import org.slf4j.LoggerFactory;
66

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
package cn.edu.ntu.java.javase.reflect.model.type;
1+
package cn.edu.ntu.java.javase.jvm.spi.type;
22

3-
import cn.edu.ntu.java.javase.reflect.model.Animal;
4-
import cn.edu.ntu.java.javase.reflect.model.impl.Cat;
5-
import cn.edu.ntu.java.javase.reflect.model.impl.Dog;
6-
import cn.edu.ntu.java.javase.reflect.model.impl.Elephant;
3+
import cn.edu.ntu.java.javase.jvm.spi.impl.Elephant;
4+
import cn.edu.ntu.java.javase.jvm.spi.Animal;
5+
import cn.edu.ntu.java.javase.jvm.spi.impl.Cat;
6+
import cn.edu.ntu.java.javase.jvm.spi.impl.Dog;
77
import lombok.extern.slf4j.Slf4j;
88
import org.junit.Test;
99
import org.slf4j.Logger;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
cn.edu.ntu.java.javase.jvm.spi.impl.Cat
2+
cn.edu.ntu.java.javase.jvm.spi.impl.Dog
3+
cn.edu.ntu.java.javase.jvm.spi.impl.Elephant
4+

java/javase/javase-proxy/pom.xml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>javase</artifactId>
7+
<groupId>cn.edu.ntu.java</groupId>
8+
<version>1.0-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>javase-proxy</artifactId>
13+
14+
<dependencies>
15+
<dependency>
16+
<groupId>cn.edu.ntu.java</groupId>
17+
<artifactId>javase-common</artifactId>
18+
<version>${project.version}</version>
19+
</dependency>
20+
21+
<dependency>
22+
<groupId>cglib</groupId>
23+
<artifactId>cglib</artifactId>
24+
<version>3.1</version>
25+
</dependency>
26+
</dependencies>
27+
</project>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package cn.edu.ntu.proxy;
2+
3+
/**
4+
* @author zack <br>
5+
* @create 2022-12-22 17:16 <br>
6+
* @project javas-jhm <br>
7+
*/
8+
public interface Calculator {
9+
10+
int add(int i, int j);
11+
12+
int sub(int i, int j);
13+
14+
int mult(int i, int j);
15+
16+
int div(int i, int j);
17+
}

0 commit comments

Comments
 (0)