import com.sgcc.isc.service.adapter.exception.ISCServiceAgentException;
import com.sgcc.isc.service.adapter.helper.IDomainService;
import com.sgcc.isc.service.adapter.helper.IIdentityService;
import com.sgcc.isc.service.adapter.helper.IOrganizationService;
import com.sgcc.isc.service.adapter.helper.IResourceService;
import com.sgcc.isc.service.adapter.helper.IRoleService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public final class AdapterFactory {
public static Log log = LogFactory.getLog(AdapterFactory.class);
public static final String resourceService = "resourceService";
public static final String organizationService = "organizationService";
public static final String roleService = "roleService";
public static final String domainService = "domainService";
public static final String identityService = "identityService";
public static final String defaultSpringContextConfigFileName = "bean-core-config.xml";
private static ApplicationContext ctx = null;
static {
ctx = new ClassPathXmlApplicationContext("bean-core-config.xml", AdapterFactory.class);
}
public AdapterFactory() {
}
public static void initApplicationContext() {
log.info("启动鉴权代理服务组件容器......");
}
public static Object getInstance(String className) {
return getApplicationContext().getBean(className);
}
public static IResourceService getResourceService() {
Object bean = getInstance("resourceService");
if (bean instanceof IResourceService) {
return (IResourceService)bean;
} else {
throw new ISCServiceAgentException("IResourceService 服务接口配置错误,无法获得服务组件");
}
}
public static IOrganizationService getOrganizationService() {
Object bean = getInstance("organizationService");
if (bean instanceof IOrganizationService) {
return (IOrganizationService)bean;
} else {
throw new ISCServiceAgentException("IOrganizationService 服务接口配置错误,无法获得服务组件");
}
}
public static IRoleService getRoleService() {
Object bean = getInstance("roleService");
if (bean instanceof IRoleService) {
return (IRoleService)bean;
} else {
throw new ISCServiceAgentException("IRoleService 服务接口配置错误,无法获得服务组件");
}
}
public static IDomainService getDomainService() {
Object bean = getInstance("domainService");
if (bean instanceof IDomainService) {
return (IDomainService)bean;
} else {
throw new ISCServiceAgentException("IDomainService 服务接口配置错误,无法获得服务组件");
}
}
public static IIdentityService getIdentityService() {
Object bean = getInstance("identityService");
if (bean instanceof IIdentityService) {
return (IIdentityService)bean;
} else {
throw new ISCServiceAgentException("IIdentityService 服务接口配置错误,无法获得服务组件");
}
}
public static ApplicationContext getApplicationContext() {
return ctx;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="logInfoResolver" class="com.sgcc.isc.service.adapter.log.LogInfoResolver"></bean>
<bean id="jsonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>application/json;charset=UTF-8</value>
</list>
</property>
</bean>
<bean id="restTemplate" class="org.springframework.web.client.RestTemplate">
<property name="messageConverters">
<list>
<bean id="stringHttpMessageConverter" class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/plain;charset=UTF-8</value>
</list>
</property>
</bean>
<ref bean="jsonHttpMessageConverter"/>
<bean
class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter">
<constructor-arg>
<bean class="org.springframework.oxm.xstream.XStreamMarshaller">
</bean>
</constructor-arg>
</bean>
</list>
</property>
</bean>
<bean id="baseService" abstract="true" class="com.sgcc.isc.service.adapter.common.BaseService">
<property name="restTemplate" ref="restTemplate"></property>
</bean>
<bean id="identityService" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="target" >
<bean class="com.sgcc.isc.service.adapter.impl.IdentityService" parent="baseService"></bean>
</property>
<property name="interceptorNames">
<list>
<value>logAspect</value>
</list>
</property>
</bean>
<bean id="organizationService" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="target" >
<bean class="com.sgcc.isc.service.adapter.impl.OrganizationService" parent="baseService"></bean>
</property>
<property name="interceptorNames">
<list>
<value>logAspect</value>
</list>
</property>
</bean>
<bean id="roleService" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="target" >
<bean class="com.sgcc.isc.service.adapter.impl.RoleService" parent="baseService"></bean>
</property>
<property name="interceptorNames">
<list>
<value>logAspect</value>
</list>
</property>
</bean>
<bean id="domainService" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="target" >
<bean class="com.sgcc.isc.service.adapter.impl.DomainService" parent="baseService"></bean>
</property>
<property name="interceptorNames">
<list>
<value>logAspect</value>
</list>
</property>
</bean>
<bean id="resourceService" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="target" >
<bean class="com.sgcc.isc.service.adapter.impl.ResourceService" parent="baseService"></bean>
</property>
<property name="interceptorNames">
<list>
<value>logAspect</value>
</list>
</property>
</bean>
<bean id="logAspect" class="com.sgcc.isc.service.adapter.log.LogAspect">
<property name="advice" ref="logAdvice"></property>
</bean>
<bean id="logAdvice" class="com.sgcc.isc.service.adapter.log.MethodAdvice">
<property name="logInfoResolver" ref="logInfoResolver"></property>
<property name="logService" ref="logService"></property>
</bean>
<bean id="logService" class="com.sgcc.isc.service.adapter.log.LogService"></bean>
<bean id="logMsgUtil" class="com.sgcc.isc.service.adapter.common.LogMsgUtil">
</bean>
</beans>