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 南山隱士 閱讀(1059) 評論(0)  編輯  收藏

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


          網站導航:
           
          主站蜘蛛池模板: 宕昌县| 井冈山市| 彰化县| 三门峡市| 绵竹市| 兴国县| 乌鲁木齐县| 库车县| 崇义县| 四川省| 广南县| 沧州市| 周宁县| 梅河口市| 怀集县| 汤阴县| 双峰县| 樟树市| 清流县| 扎赉特旗| 观塘区| 瑞丽市| 湘乡市| 屯门区| 偃师市| 满洲里市| 民乐县| 稻城县| 抚顺市| 云浮市| 台北市| 寿光市| 攀枝花市| 启东市| 济源市| 剑河县| 治多县| 漾濞| 宜兰县| 克什克腾旗| 临桂县|