WindChat/windchat-business/src/main/java/com/windchat/im/business/service/ApiServiceFactory.java

75 lines
2.7 KiB
Java
Raw Normal View History

2020-10-21 23:35:02 +08:00
/**
* Copyright 2018-2028 WindChat Group
2019-07-29 23:42:16 +08:00
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
2020-10-21 23:35:02 +08:00
* limitations under the License.
2019-07-29 23:42:16 +08:00
*/
2019-11-27 23:33:33 +08:00
package com.windchat.im.business.service;
2019-07-29 23:42:16 +08:00
2020-10-21 23:35:02 +08:00
import com.windchat.im.business.bean.ApiActions;
2019-11-27 23:36:54 +08:00
import com.windchat.im.business.impl.IRequestService;
import com.windchat.im.business.impl.tai.ApiDeviceService;
import com.windchat.im.business.impl.tai.ApiFileService;
import com.windchat.im.business.impl.tai.ApiFriendService;
import com.windchat.im.business.impl.tai.ApiGroupService;
import com.windchat.im.business.impl.tai.ApiPluginService;
import com.windchat.im.business.impl.tai.ApiSecretChatService;
import com.windchat.im.business.impl.tai.ApiSiteService;
import com.windchat.im.business.impl.tai.ApiUserService;
2020-10-21 23:35:02 +08:00
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
2019-07-29 23:42:16 +08:00
/**
* API业务请求分发工厂
2020-10-21 23:35:02 +08:00
*
2019-07-29 23:42:16 +08:00
* @author Sam{@link an.guoyue254@gmail.com}
* @since 2017.10.24 18:25:31
*/
public class ApiServiceFactory {
2020-10-21 23:35:02 +08:00
private static final Logger logger = LoggerFactory.getLogger(ApiServiceFactory.class);
private static Map<String, IRequestService> serviceMap = new LinkedHashMap<String, IRequestService>();
private static List<IRequestService> serviceList = new LinkedList<IRequestService>();
static {
serviceList.add(new ApiSiteService());
serviceList.add(new ApiUserService());
serviceList.add(new ApiFriendService());
serviceList.add(new ApiGroupService());
serviceList.add(new ApiSecretChatService());
serviceList.add(new ApiFileService());
serviceList.add(new ApiDeviceService());
serviceList.add(new ApiPluginService());
init();
}
private static void init() {
for (IRequestService requestService : serviceList) {
ApiActions serviceApiAction = requestService.getClass().getDeclaredAnnotation(ApiActions.class);
if (serviceApiAction != null) {
serviceMap.put(serviceApiAction.action(), requestService);
}
}
}
2019-07-29 23:42:16 +08:00
2020-10-21 23:35:02 +08:00
public static IRequestService getService(String serviceAction) {
return serviceMap.get(serviceAction);
}
2019-07-29 23:42:16 +08:00
}