1515 *
1616 */
1717
18- package org .minbox .framework .api .boot .plugin .resource .load .pusher ;
18+ package org .minbox .framework .api .boot .plugin .resource .load .pusher . support ;
1919
2020import org .minbox .framework .api .boot .common .exception .ApiBootException ;
21- import org .minbox .framework .api .boot .plugin .resource .load .ApiBootResourceStoreDelegate ;
2221import org .minbox .framework .api .boot .plugin .resource .load .annotation .ResourceField ;
2322import org .minbox .framework .api .boot .plugin .resource .load .context .ApiBootResourceContext ;
2423import org .minbox .framework .api .boot .plugin .resource .load .loader .ResourceFieldLoader ;
2524import org .minbox .framework .api .boot .plugin .resource .load .model .ResourcePushField ;
25+ import org .minbox .framework .api .boot .plugin .resource .load .pusher .ApiBootResourcePusher ;
2626import org .springframework .util .ObjectUtils ;
2727import org .springframework .util .ReflectionUtils ;
2828
3232import java .util .Map ;
3333
3434/**
35- * ApiBoot Resource Load Pusher
36- *
3735 * @author:恒宇少年 - 于起宇
3836 * <p>
39- * DateTime:2019-04-12 16:27
37+ * DateTime:2019-04-19 09:40
4038 * Blog:http://blog.yuqiyu.com
4139 * WebSite:http://www.jianshu.com/u/092df3f77bca
4240 * Gitee:https://gitee.com/hengboy
4341 * GitHub:https://github.com/hengboy
4442 */
45- public class ResourcePusher {
46- /**
47- * ApiBoot Resource Load Data Store
48- * Use to query resource url
49- */
50- private static ApiBootResourceStoreDelegate resourceStoreDelegate ;
43+ public abstract class ApiBootAbstractResourcePusher implements ApiBootResourcePusher {
5144
5245 /**
5346 * unified push resource
5447 *
5548 * @param method method
5649 * @param result method execute result
5750 */
58- public static void pushResource ( ApiBootResourceStoreDelegate resourceStoreDelegate , Method method , Object result ) {
59- ResourcePusher . resourceStoreDelegate = resourceStoreDelegate ;
51+ @ Override
52+ public void pushResource ( Method method , Object result ) {
6053 // list
6154 if (result instanceof List ) {
62- ResourcePusher . pushToList (method , (List <Object >) result );
55+ pushToList (method , (List <Object >) result );
6356 }
6457 // map
6558 else if (result instanceof Map ) {
66- ResourcePusher . pushToMap (method , (Map ) result );
59+ pushToMap (method , (Map ) result );
6760 }
6861 // single
6962 else if (result instanceof Object ) {
70- ResourcePusher . pushToObject (method , result );
63+ pushToObject (method , result );
7164 }
7265 }
7366
@@ -78,7 +71,7 @@ else if (result instanceof Object) {
7871 * @param executeResultList method execute result list
7972 * @throws Exception Exception
8073 */
81- private static void pushToList (Method method , List <Object > executeResultList ) {
74+ private void pushToList (Method method , List <Object > executeResultList ) {
8275 List <ResourceField > resourceFields = getResourceFields (method );
8376 executeResultList .stream ().forEach (o -> push (method , resourceFields , o ));
8477 }
@@ -90,7 +83,7 @@ private static void pushToList(Method method, List<Object> executeResultList) {
9083 * @param executeResultMap method execute result map
9184 * @throws Exception Exception
9285 */
93- private static void pushToMap (Method method , Map executeResultMap ) {
86+ private void pushToMap (Method method , Map executeResultMap ) {
9487 List <ResourceField > resourceFields = getResourceFields (method );
9588 executeResultMap .keySet ().stream ().forEach (o -> push (method , resourceFields , executeResultMap .get (o )));
9689 }
@@ -101,19 +94,28 @@ private static void pushToMap(Method method, Map executeResultMap) {
10194 * @param method method
10295 * @param executeResult method execute result object
10396 */
104- private static void pushToObject (Method method , Object executeResult ) {
97+ private void pushToObject (Method method , Object executeResult ) {
10598 List <ResourceField > resourceFields = getResourceFields (method );
10699 push (method , resourceFields , executeResult );
107100 }
108101
102+ /**
103+ * load resource url
104+ *
105+ * @param declaredMethod declared method
106+ * @param sourceFieldValue sourceFieldValue
107+ * @param resourceType resourceType
108+ * @return resource list
109+ */
110+ public abstract List <String > loadResourceUrl (Method declaredMethod , String sourceFieldValue , String resourceType );
109111
110112 /**
111113 * execute push
112114 *
113115 * @param resourceFields ResourceField Annotation List
114116 * @param object single object
115117 */
116- private static void push (Method method , List <ResourceField > resourceFields , Object object ) {
118+ private void push (Method method , List <ResourceField > resourceFields , Object object ) {
117119 Class objectClass = object .getClass ();
118120 resourceFields .stream ().forEach (resourceField -> {
119121 try {
@@ -125,7 +127,7 @@ private static void push(Method method, List<ResourceField> resourceFields, Obje
125127 // get source filed value
126128 Object sourceFieldValue = sourceField .get (object );
127129 // load resource urls
128- List <String > resourceUrls = resourceStoreDelegate . loadResourceUrl (String .valueOf (sourceFieldValue ), resourceField .type ());
130+ List <String > resourceUrls = loadResourceUrl (method , String .valueOf (sourceFieldValue ), resourceField .type ());
129131
130132 if (!ObjectUtils .isEmpty (resourceUrls )) {
131133 // resource field is array
@@ -157,7 +159,7 @@ else if (resourceField.isList()) {
157159 * @return Field Instance
158160 * @throws NoSuchFieldException No Such Field Exception
159161 */
160- private static Field getSourceField (Method method , Class objectClass , String sourceFieldName , String resourceFieldName ) throws NoSuchFieldException {
162+ private Field getSourceField (Method method , Class objectClass , String sourceFieldName , String resourceFieldName ) throws NoSuchFieldException {
161163 // cache from memory
162164 ResourcePushField resourcePushField = ApiBootResourceContext .getPushFieldFromCache (method , resourceFieldName );
163165 // if don't have source field from cache
@@ -185,7 +187,7 @@ private static Field getSourceField(Method method, Class objectClass, String sou
185187 * @param resourceFieldName resource field name
186188 * @return Field
187189 */
188- private static Field getResourceField (Method method , Class objectClass , String resourceFieldName ) throws NoSuchFieldException {
190+ private Field getResourceField (Method method , Class objectClass , String resourceFieldName ) throws NoSuchFieldException {
189191 // cache from memory
190192 ResourcePushField resourcePushField = ApiBootResourceContext .getPushFieldFromCache (method , resourceFieldName );
191193 // if don't have source field from cache
@@ -212,7 +214,7 @@ private static Field getResourceField(Method method, Class objectClass, String r
212214 * @param method method
213215 * @return ResourceField List
214216 */
215- private static List <ResourceField > loadMethodResourceFields (Method method ) {
217+ private List <ResourceField > loadMethodResourceFields (Method method ) {
216218 // load method declared ResourceField Annotation List
217219 List <ResourceField > resourceFields = ResourceFieldLoader .getDeclaredResourceField (method );
218220 return resourceFields ;
@@ -226,7 +228,7 @@ private static List<ResourceField> loadMethodResourceFields(Method method) {
226228 * @param method method
227229 * @return List ResourceField
228230 */
229- private static List <ResourceField > getResourceFields (Method method ) {
231+ private List <ResourceField > getResourceFields (Method method ) {
230232 // get from cache
231233 List <ResourceField > resourceFields = ApiBootResourceContext .getResourceFieldFromCache (method );
232234
0 commit comments