`
huangyunzeng
  • 浏览: 29718 次
  • 性别: Icon_minigender_1
  • 来自: 秦皇岛
社区版块
存档分类
最新评论

Flex和spring集成时需要的SpringFactory

    博客分类:
  • Java
阅读更多
package springFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;

import flex.messaging.FactoryInstance;
import flex.messaging.FlexFactory;
import flex.messaging.config.ConfigMap;
import flex.messaging.services.ServiceException;


public class SpringFactory implements FlexFactory
{
    private static final String SOURCE = "source";

   
    public void initialize(String id, 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;
    } // end method createFactoryInstance()

   
    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()
        {
            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;
            }
        }
        
    }

}

 

分享到:
评论

相关推荐

    flex-spring

    Spring和Flex整合时用的SpringFactory,SpringFactory实例化Spring bean文件,供表现层Flex远程调用(RemoteObject),我做Spring+Hibernate+Flex做J2EE开发时用到的。下载就可以直接用了,省得手工写。希望对大家有...

    Flex_Spring3_Hibernate3整合Demo

    Flex_Spring3_Hibernate3整合Demo,使用RemoteObject调用java代码。主要配置为applicationContext.xml,web.xml,services-config.xml,remoting-config.xml。另外要引入SpringFactory类。

    SpringFactory.java

    整合SSH+flex所需要的SpringFactory文件,前段时间上传了关于flex与SSH整合的资料、、发现忘记上传这个文件,所以现在补上!很抱歉!希望大家能用上!

    bean-converter-springfactory-0.0.2.jar

    官方版本,亲测可用

    bean-converter-springfactory-0.0.2-sources.jar

    官方版本,亲测可用

    spring 工厂

Global site tag (gtag.js) - Google Analytics