日期:2014-05-17 浏览次数:20808 次
package com.base; import flex.messaging.*; import flex.messaging.config.ConfigMap; import flex.messaging.services.ServiceException; import javax.servlet.ServletConfig; import org.springframework.beans.BeansException; import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.context.ApplicationContext; import org.springframework.web.context.support.WebApplicationContextUtils; public class SpringFactory implements FlexFactory { static class SpringFactoryInstance extends FactoryInstance { public String toString() { return (new StringBuilder("SpringFactory instance for id=")) .append(getId()).append(" source=").append(getSource()) .append(" scope=").append(getScope()).toString(); } public Object lookup() { ApplicationContext appContext; String beanName; appContext = WebApplicationContextUtils .getWebApplicationContext(FlexContext.getServletConfig() .getServletContext()); beanName = getSource(); return appContext.getBean(beanName); } SpringFactoryInstance(SpringFactory factory, String id, ConfigMap properties) { super(factory, id, properties); } } private static final String SOURCE = "source"; public SpringFactory() { } public void initialize(String s, ConfigMap configmap) { } public FactoryInstance createFactoryInstance(String id, ConfigMap properties) { SpringFactoryInstance instance = new SpringFactoryInstance(this, id, properties); instance.setSource(properties.getPropertyAsString("source", instance .getId())); return instance; } public Object lookup(FactoryInstance inst) { SpringFactoryInstance factoryInstance = (SpringFactoryInstance) inst; return factoryInstance.lookup(); } }