Skip to content

Commit fe3fc8a

Browse files
committed
新增APIJSONRequest并在AccessVerifier和各个model使用,新增FunctionList
1 parent ea8c2d1 commit fe3fc8a

File tree

18 files changed

+821
-99
lines changed

18 files changed

+821
-99
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*Copyright ©2016 TommyLemon(https://github.com/TommyLemon/APIJSON)
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.*/
14+
15+
package zuo.biao.apijson;
16+
17+
import java.lang.annotation.Documented;
18+
import java.lang.annotation.ElementType;
19+
import java.lang.annotation.Retention;
20+
import java.lang.annotation.RetentionPolicy;
21+
import java.lang.annotation.Target;
22+
23+
/**请求方法对应的JSON结构
24+
* @author Lemon
25+
*/
26+
@Target({ElementType.METHOD, ElementType.TYPE})
27+
@Retention(RetentionPolicy.RUNTIME)
28+
@Documented
29+
public @interface APIJSONRequest {
30+
31+
/**
32+
* @return 允许的请求方法
33+
*/
34+
RequestMethod[] method() default {};
35+
36+
37+
/**@see {@link RequestMethod#POST_GET}
38+
* @return 该请求方法允许的结构
39+
*/
40+
String POST_GET() default "";
41+
42+
/**@see {@link RequestMethod#POST_HEAD}
43+
* @return 该请求方法允许的结构
44+
*/
45+
String POST_HEAD() default "";
46+
47+
/**@see {@link RequestMethod#POST}
48+
* @return 该请求方法允许的结构
49+
*/
50+
String POST() default "";
51+
52+
/**@see {@link RequestMethod#PUT}
53+
* @return 该请求方法允许的结构
54+
*/
55+
String PUT() default "";
56+
57+
/**@see {@link RequestMethod#DELETE}
58+
* @return 该请求方法允许的结构
59+
*/
60+
String DELETE() default "";
61+
}
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
/*Copyright ©2016 TommyLemon(https://github.com/TommyLemon/APIJSON)
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.*/
14+
15+
package zuo.biao.apijson;
16+
17+
import java.util.Collection;
18+
import java.util.Map;
19+
20+
/**可远程调用的函数列表
21+
* @author Lemon
22+
*/
23+
public interface FunctionList {
24+
25+
//判断是否为空 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<
26+
/**判断collection是否为空
27+
* @param collection
28+
* @return
29+
*/
30+
public <T> boolean isEmpty(Collection<T> collection);
31+
/**判断map是否为空
32+
* @param <K>
33+
* @param <V>
34+
* @param map
35+
* @return
36+
*/
37+
public <K, V> boolean isEmpty(Map<K, V> map);
38+
//判断是否为空 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>
39+
40+
//判断是否为包含 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<
41+
/**判断collection是否包含object
42+
* @param collection
43+
* @param object
44+
* @return
45+
*/
46+
public <T> boolean isContain(Collection<T> collection, T object);
47+
/**判断map是否包含key
48+
* @param <K>
49+
* @param <V>
50+
* @param map
51+
* @param key
52+
* @return
53+
*/
54+
public <K, V> boolean isContainKey(Map<K, V> map, K key);
55+
/**判断map是否包含value
56+
* @param <K>
57+
* @param <V>
58+
* @param map
59+
* @param value
60+
* @return
61+
*/
62+
public <K, V> boolean isContainValue(Map<K, V> map, V value);
63+
//判断是否为包含 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>
64+
65+
66+
//获取集合长度 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<
67+
/**获取数量
68+
* @param <T>
69+
* @param array
70+
* @return
71+
*/
72+
public <T> int count(T[] array);
73+
/**获取数量
74+
* @param <T>
75+
* @param collection List, Vector, Set等都是Collection的子类
76+
* @return
77+
*/
78+
public <T> int count(Collection<T> collection);
79+
/**获取数量
80+
* @param <K>
81+
* @param <V>
82+
* @param map
83+
* @return
84+
*/
85+
public <K, V> int count(Map<K, V> map);
86+
//获取集合长度 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>
87+
88+
89+
//获取集合长度 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<
90+
/**获取
91+
* @param <T>
92+
* @param array
93+
* @return
94+
*/
95+
public <T> T get(T[] array, int position);
96+
/**获取
97+
* @param <T>
98+
* @param collection List, Vector, Set等都是Collection的子类
99+
* @return
100+
*/
101+
public <T> T get(Collection<T> collection, int position);
102+
/**获取
103+
* @param <K>
104+
* @param <V>
105+
* @param map null ? null
106+
* @param key null ? null : map.get(key);
107+
* @return
108+
*/
109+
public <K, V> V get(Map<K, V> map, K key);
110+
//获取集合长度 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>
111+
112+
113+
114+
//获取非基本类型对应基本类型的非空值 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<
115+
/**获取非空值
116+
* @param value
117+
* @return
118+
*/
119+
public boolean value(Boolean value);
120+
/**获取非空值
121+
* @param value
122+
* @return
123+
*/
124+
public int value(Integer value);
125+
/**获取非空值
126+
* @param value
127+
* @return
128+
*/
129+
public long value(Long value);
130+
/**获取非空值
131+
* @param value
132+
* @return
133+
*/
134+
public float value(Float value);
135+
/**获取非空值
136+
* @param value
137+
* @return
138+
*/
139+
public double value(Double value);
140+
//获取非基本类型对应基本类型的非空值 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>
141+
142+
}

APIJSON(Android)/APIJSON(ADT)/APIJSONLibrary/src/zuo/biao/apijson/JSON.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import com.alibaba.fastjson.parser.Feature;
2424
import com.alibaba.fastjson.serializer.SerializerFeature;
2525

26-
/**阿里json封装类 防止解析时异常
26+
/**阿里FastJSON封装类 防止解析时异常
2727
* @author Lemon
2828
*/
2929
public class JSON {
@@ -34,7 +34,7 @@ public class JSON {
3434
* @return
3535
*/
3636
public static boolean isJsonCorrect(String s) {
37-
Log.i(TAG, "isJsonCorrect <<<< " + s + " >>>>>>>");
37+
// Log.i(TAG, "isJsonCorrect <<<< " + s + " >>>>>>>");
3838
if (s == null
3939
// || s.equals("[]")
4040
// || s.equals("{}")
@@ -171,7 +171,7 @@ public static String toJSONString(Object obj) {
171171
try {
172172
return com.alibaba.fastjson.JSON.toJSONString(obj);
173173
} catch (Exception e) {
174-
Log.i(TAG, "toJSONString catch \n" + e.getMessage());
174+
Log.e(TAG, "toJSONString catch \n" + e.getMessage());
175175
}
176176
return null;
177177
}
@@ -188,7 +188,7 @@ public static String toJSONString(Object obj, SerializerFeature... features) {
188188
try {
189189
return com.alibaba.fastjson.JSON.toJSONString(obj, features);
190190
} catch (Exception e) {
191-
Log.i(TAG, "toJSONString catch \n" + e.getMessage());
191+
Log.e(TAG, "parseArray catch \n" + e.getMessage());
192192
}
193193
return null;
194194
}
@@ -221,9 +221,7 @@ public static boolean isJSONObject(Object obj) {
221221
JSONObject json = parseObject((String) obj);
222222
return json != null && json.isEmpty() == false;
223223
} catch (Exception e) {
224-
//太长 System.out.println(TAG + "select while (rs.next()){ >> i = "
225-
// + i + " try { json = JSON.parse((String) value);"
226-
// + ">> } catch (Exception e) {\n" + e.getMessage());
224+
Log.e(TAG, "isJSONObject catch \n" + e.getMessage());
227225
}
228226
}
229227

@@ -242,14 +240,11 @@ public static boolean isJSONArray(Object obj) {
242240
JSONArray json = parseArray((String) obj);
243241
return json != null && json.isEmpty() == false;
244242
} catch (Exception e) {
245-
//太长 System.out.println(TAG + "select while (rs.next()){ >> i = "
246-
// + i + " try { json = JSON.parse((String) value);"
247-
// + ">> } catch (Exception e) {\n" + e.getMessage());
243+
Log.e(TAG, "isJSONArray catch \n" + e.getMessage());
248244
}
249245
}
250246

251247
return false;
252248
}
253249

254-
255250
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* 示例服务端工程包
3+
*/
4+
/**
5+
* @author Lemon
6+
*
7+
*/
8+
package apijson.demo.server;
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*Copyright ©2016 TommyLemon(https://github.com/TommyLemon/APIJSON)
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.*/
14+
15+
package zuo.biao.apijson;
16+
17+
import java.lang.annotation.Documented;
18+
import java.lang.annotation.ElementType;
19+
import java.lang.annotation.Retention;
20+
import java.lang.annotation.RetentionPolicy;
21+
import java.lang.annotation.Target;
22+
23+
/**请求方法对应的JSON结构
24+
* @author Lemon
25+
*/
26+
@Target({ElementType.METHOD, ElementType.TYPE})
27+
@Retention(RetentionPolicy.RUNTIME)
28+
@Documented
29+
public @interface APIJSONRequest {
30+
31+
/**
32+
* @return 允许的请求方法
33+
*/
34+
RequestMethod[] method() default {};
35+
36+
37+
/**@see {@link RequestMethod#POST_GET}
38+
* @return 该请求方法允许的结构
39+
*/
40+
String POST_GET() default "";
41+
42+
/**@see {@link RequestMethod#POST_HEAD}
43+
* @return 该请求方法允许的结构
44+
*/
45+
String POST_HEAD() default "";
46+
47+
/**@see {@link RequestMethod#POST}
48+
* @return 该请求方法允许的结构
49+
*/
50+
String POST() default "";
51+
52+
/**@see {@link RequestMethod#PUT}
53+
* @return 该请求方法允许的结构
54+
*/
55+
String PUT() default "";
56+
57+
/**@see {@link RequestMethod#DELETE}
58+
* @return 该请求方法允许的结构
59+
*/
60+
String DELETE() default "";
61+
}

0 commit comments

Comments
 (0)