日期:2014-05-17  浏览次数:20755 次

谁能解释下SpringFactory里每个方法具体的作用
如题,
Java code

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





------解决方案--------------------
找个Spring源码分析的资料看看吧。你这个类中牵扯到了其它的类,越说越多哦。