1、spring类
springFactory
package cn.com.dosoft.tax.factory;
import flex.messaging.services.ServiceException;
import flex.messaging.FactoryInstance;
import flex.messaging.FlexFactory;
import flex.messaging.config.ConfigMap;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
public class SpringFactory implements FlexFactory {
//定义一个常量资源
private static final String SOURCE = "source";
public void initialize(String id, ConfigMap configMap) {
}
/**
* This method is called when we initialize the definition of an instance
* which will be looked up by this factory. It should validate that
* the properties supplied are valid to define an instance.
* Any valid properties used for this configuration must be accessed to
* avoid warnings about unused configuration elements. If your factory
* is only used for application scoped components, this method can simply
* return a factory instance which delegates the creation of the component
* to the FactoryInstance's lookup method.
*/
//创建一个factory实例
public FactoryInstance createFactoryInstance(String id, ConfigMap properties) {
//生成一个Spring的实例
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();
}
//内部静态类
static class SpringFactoryInstance extends FactoryInstance
{
//内部类构造函数
SpringFactoryInstance(SpringFactory factory, String id, ConfigMap properties)
{
super(factory, id, properties);
}
//用于测试
public String toString()
{
return "SpringFactory instance for id=" + getId() + " source=" + getSource() + " scope=" + getScope();
}
//查询
public Object lookup()
{
//这就是从spring容器中getbean了
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(flex.messaging.FlexContext.getServletConfig().getServletContext());
String beanName = getSource();
try
{
return appContext.getBean(beanName);
}
catch (NoSuchBeanDefinitionException nexc)
{
ServiceException e = new ServiceException();
String msg = "Spring service named '" + beanName + "' does not exist.";
e.setMessage(msg);
e.setRootCause(nexc);
e.setDetails(msg);
e.setCode("Server.Processing");
throw e;
}
catch (BeansException bexc)
{
ServiceException e = new ServiceException();
String msg = "Unable to create Spring service named '" + beanName + "' ";
e.setMessage(msg);
e.setRootCause(bexc);
e.setDetails(msg);
e.setCode("Server.Processing");
throw e;
}
}
}
}
2、remoting-config配置
<destination id="infoArticleService">
<properties>
<factory>springFactory</factory>
<source>infoArticleService</source>
</properties>
</destination>
3、services-config配置
<factories>
<factory id="springFactory" class="cn.com.dosoft.tax.factory.SpringFactory" />
</factories>
posted on 2009-03-17 08:03
南山隐士 阅读(1058)
评论(0) 编辑 收藏