posts - 13,comments - 19,trackbacks - 0
          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 南山隱士 閱讀(1060) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 洛浦县| 开封县| 凯里市| 囊谦县| 吉安市| 武平县| 阿尔山市| 颍上县| 资阳市| 祥云县| 娄底市| 类乌齐县| 阜南县| 通山县| 定边县| 克拉玛依市| 文登市| 通许县| 呼玛县| 阿荣旗| 顺平县| 依安县| 沙田区| 蓬安县| 巴彦淖尔市| 金坛市| 嵩明县| 清丰县| 定襄县| 云龙县| 沂水县| 察隅县| 搜索| 邵阳市| 道真| 张家港市| 彩票| 嵊泗县| 徐闻县| 湘乡市| 新密市|