Example usage for org.springframework.beans.factory.support RootBeanDefinition setLazyInit

List of usage examples for org.springframework.beans.factory.support RootBeanDefinition setLazyInit

Introduction

In this page you can find the example usage for org.springframework.beans.factory.support RootBeanDefinition setLazyInit.

Prototype

@Override
public void setLazyInit(boolean lazyInit) 

Source Link

Document

Set whether this bean should be lazily initialized.

Usage

From source file:com.weibo.api.motan.config.springsupport.MotanBeanDefinitionParser.java

@SuppressWarnings({ "rawtypes", "unchecked" })
private static BeanDefinition parse(Element element, ParserContext parserContext, Class<?> beanClass,
        boolean required) throws ClassNotFoundException {
    RootBeanDefinition bd = new RootBeanDefinition();
    bd.setBeanClass(beanClass);//from   ww  w  . j a  v  a2s . c  o  m
    // ??lazy init
    bd.setLazyInit(false);

    // id?id,idcontext
    String id = element.getAttribute("id");
    if ((id == null || id.length() == 0) && required) {
        String generatedBeanName = element.getAttribute("name");
        if (generatedBeanName == null || generatedBeanName.length() == 0) {
            generatedBeanName = element.getAttribute("class");
        }
        if (generatedBeanName == null || generatedBeanName.length() == 0) {
            generatedBeanName = beanClass.getName();
        }
        id = generatedBeanName;
        int counter = 2;
        while (parserContext.getRegistry().containsBeanDefinition(id)) {
            id = generatedBeanName + (counter++);
        }
    }
    if (id != null && id.length() > 0) {
        if (parserContext.getRegistry().containsBeanDefinition(id)) {
            throw new IllegalStateException("Duplicate spring bean id " + id);
        }
        parserContext.getRegistry().registerBeanDefinition(id, bd);
    }
    bd.getPropertyValues().addPropertyValue("id", id);
    if (ProtocolConfig.class.equals(beanClass)) {
        MotanNamespaceHandler.protocolDefineNames.add(id);

    } else if (RegistryConfig.class.equals(beanClass)) {
        MotanNamespaceHandler.registryDefineNames.add(id);

    } else if (BasicServiceInterfaceConfig.class.equals(beanClass)) {
        MotanNamespaceHandler.basicServiceConfigDefineNames.add(id);

    } else if (BasicRefererInterfaceConfig.class.equals(beanClass)) {
        MotanNamespaceHandler.basicRefererConfigDefineNames.add(id);

    } else if (ServiceConfigBean.class.equals(beanClass)) {
        String className = element.getAttribute("class");
        if (className != null && className.length() > 0) {
            RootBeanDefinition classDefinition = new RootBeanDefinition();
            classDefinition.setBeanClass(
                    Class.forName(className, true, Thread.currentThread().getContextClassLoader()));
            classDefinition.setLazyInit(false);
            parseProperties(element.getChildNodes(), classDefinition);
            bd.getPropertyValues().addPropertyValue("ref",
                    new BeanDefinitionHolder(classDefinition, id + "Impl"));
        }
    }

    Set<String> props = new HashSet<String>();
    ManagedMap parameters = null;
    // ??setbd
    for (Method setter : beanClass.getMethods()) {
        String name = setter.getName();
        // setXXX
        if (name.length() <= 3 || !name.startsWith("set") || !Modifier.isPublic(setter.getModifiers())
                || setter.getParameterTypes().length != 1) {
            continue;
        }
        String property = (name.substring(3, 4).toLowerCase() + name.substring(4)).replaceAll("_", "-");
        props.add(property);
        if ("id".equals(property)) {
            bd.getPropertyValues().addPropertyValue("id", id);
            continue;
        }
        String value = element.getAttribute(property);
        if ("methods".equals(property)) {
            parseMethods(id, element.getChildNodes(), bd, parserContext);
        }
        if (StringUtils.isBlank(value)) {
            continue;
        }
        value = value.trim();
        if (value.length() == 0) {
            continue;
        }
        Object reference;
        if ("ref".equals(property)) {
            if (parserContext.getRegistry().containsBeanDefinition(value)) {
                BeanDefinition refBean = parserContext.getRegistry().getBeanDefinition(value);
                if (!refBean.isSingleton()) {
                    throw new IllegalStateException(
                            "The exported service ref " + value + " must be singleton! Please set the " + value
                                    + " bean scope to singleton, eg: <bean id=\"" + value
                                    + "\" scope=\"singleton\" ...>");
                }
            }
            reference = new RuntimeBeanReference(value);
        } else if ("protocol".equals(property) && !StringUtils.isBlank(value)) {
            if (!value.contains(",")) {
                reference = new RuntimeBeanReference(value);
            } else {
                parseMultiRef("protocols", value, bd, parserContext);
                reference = null;
            }
        } else if ("registry".equals(property)) {
            parseMultiRef("registries", value, bd, parserContext);
            reference = null;
        } else if ("basicService".equals(property)) {
            reference = new RuntimeBeanReference(value);

        } else if ("basicReferer".equals(property)) {
            reference = new RuntimeBeanReference(value);

        } else if ("extConfig".equals(property)) {
            reference = new RuntimeBeanReference(value);
        } else {
            reference = new TypedStringValue(value);
        }

        if (reference != null) {
            bd.getPropertyValues().addPropertyValue(property, reference);
        }
    }
    if (ProtocolConfig.class.equals(beanClass)) {
        // protocolparameters?
        NamedNodeMap attributes = element.getAttributes();
        int len = attributes.getLength();
        for (int i = 0; i < len; i++) {
            Node node = attributes.item(i);
            String name = node.getLocalName();
            if (!props.contains(name)) {
                if (parameters == null) {
                    parameters = new ManagedMap();
                }
                String value = node.getNodeValue();
                parameters.put(name, new TypedStringValue(value, String.class));
            }
        }
        bd.getPropertyValues().addPropertyValue("parameters", parameters);
    }
    return bd;
}

From source file:org.hummer.spring.ServicePaser.java

public BeanDefinition parse(Element ele, ParserContext context) {
    //?//from   w ww . ja v a 2  s.  c om
    service = ele.getAttribute(ATTR_SERVICE);
    version = ele.getAttribute(ATTR_VERSION);
    ref = ele.getAttribute(ATTR_REF);

    RootBeanDefinition root = new RootBeanDefinition(ServiceBean.class);
    root.setLazyInit(false);
    root.getPropertyValues().add("service", service);
    root.getPropertyValues().add("version", version);
    root.getPropertyValues().add("ref", new RuntimeBeanReference(ref));
    context.getRegistry()
            .registerBeanDefinition(beanNameGenerator.generateBeanName(root, context.getRegistry()), root);
    return null;
}

From source file:com.newlandframework.rpc.spring.NettyRpcServiceParser.java

public BeanDefinition parse(Element element, ParserContext parserContext) {
    String interfaceName = element.getAttribute("interfaceName");
    String ref = element.getAttribute("ref");

    RootBeanDefinition beanDefinition = new RootBeanDefinition();
    beanDefinition.setBeanClass(NettyRpcService.class);
    beanDefinition.setLazyInit(false);
    beanDefinition.getPropertyValues().addPropertyValue("interfaceName", interfaceName);
    beanDefinition.getPropertyValues().addPropertyValue("ref", ref);

    parserContext.getRegistry().registerBeanDefinition(interfaceName, beanDefinition);

    return beanDefinition;
}

From source file:com.newlandframework.rpc.spring.NettyRpcReferenceParser.java

public BeanDefinition parse(Element element, ParserContext parserContext) {
    String interfaceName = element.getAttribute("interfaceName");
    String id = element.getAttribute("id");
    String ipAddr = element.getAttribute("ipAddr");
    String protocolType = element.getAttribute("protocol");

    RootBeanDefinition beanDefinition = new RootBeanDefinition();
    beanDefinition.setBeanClass(NettyRpcReference.class);
    beanDefinition.setLazyInit(false);

    beanDefinition.getPropertyValues().addPropertyValue("interfaceName", interfaceName);
    beanDefinition.getPropertyValues().addPropertyValue("ipAddr", ipAddr);
    beanDefinition.getPropertyValues().addPropertyValue("protocol", protocolType);

    parserContext.getRegistry().registerBeanDefinition(id, beanDefinition);
    return beanDefinition;
}

From source file:com.codestd.spring.cxf.config.schema.AnnotationBeanDefinitionParser.java

@Override
public BeanDefinition parse(Element element, ParserContext parserContext) {
    RootBeanDefinition beanDefinition = new RootBeanDefinition();
    beanDefinition.setBeanClass(beanClass);
    beanDefinition.setLazyInit(false);

    String id = element.getAttribute("id");
    if (id == null || id.length() == 0) {
        String name = element.getAttribute("name");
        if (!StringUtils.isEmpty(name))
            id = name;/*from   w w  w  .  j  a v  a2s  .  c  o m*/
        else
            id = beanClass.getName();
    }

    if (parserContext.getRegistry().containsBeanDefinition(id)) {
        throw new IllegalStateException("Duplicate spring bean id " + id);
    }
    parserContext.getRegistry().registerBeanDefinition(id, beanDefinition);

    String annotationPackage = element.getAttribute("package");
    if (!StringUtils.isEmpty(annotationPackage))
        beanDefinition.getPropertyValues().add("annotationPackage", annotationPackage);

    return beanDefinition;
}

From source file:com.clican.pluto.dataprocess.spring.parser.DeployParser.java

public BeanDefinition parse(Element element, ParserContext parserContext) {
    BeanDefinitionRegistry bdr = parserContext.getRegistry();
    RootBeanDefinition beanDef = new RootBeanDefinition();
    beanDef.setAbstract(false);/*w w  w  .j a  v  a2s. c  o m*/
    beanDef.setBeanClass(Deploy.class);
    beanDef.setLazyInit(false);
    beanDef.setAutowireMode(Autowire.BY_NAME.value());
    String id = element.getAttribute("id");
    if (StringUtils.isEmpty(id)) {
        id = "dplDeploy#" + element.hashCode();
    }
    bdr.registerBeanDefinition(id, beanDef);

    this.setBeanDefinitionStringProperty("name", beanDef, element);
    this.setBeanDefinitionStringProperty("url", beanDef, element);
    this.setBeanDefinitionStringProperty("propertyResources", beanDef, element);

    return beanDef;
}

From source file:com.clican.pluto.dataprocess.spring.parser.ParamProcessorParser.java

@SuppressWarnings("unchecked")

public void customiseBeanDefinition(BeanDefinition beanDef, Element element, ParserContext parserContext) {
    List paramBeanList = new ManagedList();
    NodeList nodeList = element.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node node = nodeList.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            String localName = node.getLocalName();
            if ("param".equals(localName)) {
                RootBeanDefinition bean = new RootBeanDefinition();
                bean.setAbstract(false);
                bean.setBeanClass(ParamBean.class);
                bean.setLazyInit(false);
                bean.setAutowireMode(Autowire.BY_NAME.value());
                Element paramElement = (Element) node;
                String paramName = paramElement.getAttribute("paramName");
                String paramValue = paramElement.getAttribute("paramValue");
                String type = paramElement.getAttribute("type");
                String override = paramElement.getAttribute("override");
                String pattern = paramElement.getAttribute("pattern");
                bean.getPropertyValues().addPropertyValue("paramName", paramName);
                bean.getPropertyValues().addPropertyValue("paramValue", paramValue);
                bean.getPropertyValues().addPropertyValue("type", type);
                bean.getPropertyValues().addPropertyValue("pattern", pattern);
                if (StringUtils.isNotEmpty(override)) {
                    RootBeanDefinition over = new RootBeanDefinition();
                    over.setAbstract(false);
                    over.setBeanClass(Boolean.class);
                    over.setLazyInit(false);
                    over.getConstructorArgumentValues().addIndexedArgumentValue(0, override);
                    bean.getPropertyValues().addPropertyValue("override", over);
                }/*from w w  w . j a v a 2s  .  co m*/
                paramBeanList.add(bean);
            }
        }
    }
    beanDef.getPropertyValues().addPropertyValue("paramBeanList", paramBeanList);
}

From source file:com.clican.pluto.dataprocess.spring.parser.ExcelProcessorParser.java

@SuppressWarnings("unchecked")

public void customiseBeanDefinition(BeanDefinition beanDef, Element element, ParserContext parserContext) {
    List excelBeanList = new ManagedList();
    NodeList nodeList = element.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node node = nodeList.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            String localName = node.getLocalName();
            if ("write".equals(localName) || "read".equals(localName)) {
                RootBeanDefinition bean = new RootBeanDefinition();
                bean.setAbstract(false);
                bean.setBeanClass(ExcelExecBean.class);
                bean.setLazyInit(false);
                bean.setAutowireMode(Autowire.BY_NAME.value());
                Element paramElement = (Element) node;
                String paramName = paramElement.getAttribute("paramName");
                String resultName = paramElement.getAttribute("resultName");
                String resource = paramElement.getAttribute("resource");
                String sheetName = paramElement.getAttribute("sheetName");
                String columns = paramElement.getAttribute("columns");
                String columnsVarName = paramElement.getAttribute("columnsVarName");
                String sheetVarName = paramElement.getAttribute("sheetVarName");
                String typeMapStr = paramElement.getAttribute("typeMap");
                String resourceVarName = paramElement.getAttribute("resourceVarName");
                Map<String, String> typeMap = new HashMap<String, String>();
                if ("read".equals(localName)) {
                    for (String type : typeMapStr.split(";")) {
                        typeMap.put(type.split("=>")[0], type.split("=>")[1]);
                    }//from w  ww  .j a  v a 2  s  .c  om
                }
                bean.getPropertyValues().addPropertyValue("paramName", paramName);
                bean.getPropertyValues().addPropertyValue("resultName", resultName);
                bean.getPropertyValues().addPropertyValue("sheetName", sheetName);
                if (StringUtils.isNotEmpty(columns)) {
                    bean.getPropertyValues().addPropertyValue("columns", columns.split(","));
                }
                bean.getPropertyValues().addPropertyValue("resource", resource);
                bean.getPropertyValues().addPropertyValue("typeMap", typeMap);
                bean.getPropertyValues().addPropertyValue("columnsVarName", columnsVarName);
                bean.getPropertyValues().addPropertyValue("sheetVarName", sheetVarName);
                bean.getPropertyValues().addPropertyValue("resourceVarName", resourceVarName);
                if ("write".equals(localName)) {
                    bean.getPropertyValues().addPropertyValue("read", false);
                }
                excelBeanList.add(bean);
            }
        }
    }
    beanDef.getPropertyValues().addPropertyValue("excelExecBeanList", excelBeanList);

}

From source file:com.clican.pluto.dataprocess.spring.parser.JdbcExecProcessorParser.java

@SuppressWarnings("unchecked")

public void customiseBeanDefinition(BeanDefinition beanDef, Element element, ParserContext parserContext) {
    String jdbcTemplate = element.getAttribute("jdbcTemplate");
    beanDef.getPropertyValues().addPropertyValue("jdbcTemplate", new RuntimeBeanReference(jdbcTemplate));
    List jdbcExecBeanList = new ManagedList();
    NodeList nodeList = element.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node node = nodeList.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            String localName = node.getLocalName();
            if ("exec".equals(localName)) {
                RootBeanDefinition bean = new RootBeanDefinition();
                bean.setAbstract(false);
                bean.setBeanClass(JdbcExecBean.class);
                bean.setLazyInit(false);
                bean.setAutowireMode(Autowire.BY_NAME.value());

                Element jdbcExecElement = (Element) node;
                String batch = jdbcExecElement.getAttribute("batch");
                String paramName = jdbcExecElement.getAttribute("paramName");
                String resultName = jdbcExecElement.getAttribute("resultName");
                String paramNameMap = jdbcExecElement.getAttribute("paramNameMap");
                String singleRow = jdbcExecElement.getAttribute("singleRow");
                String clazz = jdbcExecElement.getAttribute("clazz");
                String sql = jdbcExecElement.getTextContent();
                if (StringUtils.isNotEmpty(paramNameMap)) {
                    Map<String, String> map = new HashMap<String, String>();
                    for (String pnm : paramNameMap.split(";")) {
                        String contextName = pnm.split("=>")[0].trim();
                        String ibatisName = pnm.split("=>")[1].trim();
                        map.put(contextName, ibatisName);
                    }/* www .  ja v a2s.c o  m*/
                    bean.getPropertyValues().addPropertyValue("paramNameMap", map);
                }
                if (StringUtils.isNotEmpty(batch)) {
                    bean.getPropertyValues().addPropertyValue("batch", Boolean.parseBoolean(batch));
                }
                if (StringUtils.isNotEmpty(singleRow)) {
                    bean.getPropertyValues().addPropertyValue("singleRow", Boolean.parseBoolean(singleRow));
                }
                if (StringUtils.isNotEmpty(clazz)) {
                    try {
                        bean.getPropertyValues().addPropertyValue("clazz", Class.forName(clazz));
                    } catch (Exception e) {
                        throw new RuntimeException(e);
                    }
                }
                bean.getPropertyValues().addPropertyValue("paramName", paramName);
                bean.getPropertyValues().addPropertyValue("resultName", resultName);
                bean.getPropertyValues().addPropertyValue("sql", sql);
                jdbcExecBeanList.add(bean);
            }
        }
    }
    beanDef.getPropertyValues().addPropertyValue("jdbcExecBeanList", jdbcExecBeanList);
}

From source file:com.clican.pluto.dataprocess.spring.parser.AbstractProcessorParser.java

@SuppressWarnings({ "unchecked", "rawtypes" })
public BeanDefinition parse(Element element, ParserContext parserContext) {
    BeanDefinitionRegistry bdr = parserContext.getRegistry();
    RootBeanDefinition beanDef = new RootBeanDefinition();
    beanDef.setDestroyMethodName("destroy");
    beanDef.setAbstract(false);//from   w  ww. j av  a 2s  .  com
    beanDef.setBeanClass(getDataProcessorClass());
    beanDef.setLazyInit(false);
    beanDef.setAutowireMode(Autowire.BY_NAME.value());
    String id = element.getAttribute("id");
    if (bdr.containsBeanDefinition(id)) {
        throw new RuntimeException("id[" + id + "]??");
    }
    bdr.registerBeanDefinition(id, beanDef);
    beanDef.getPropertyValues().addPropertyValue("id", id);
    String startProcessor = element.getAttribute("startProcessor");
    boolean sp = false;
    if (StringUtils.isNotEmpty(startProcessor)) {
        sp = Boolean.parseBoolean(startProcessor);
    }
    beanDef.getPropertyValues().addPropertyValue("startProcessor", sp);

    String transaction = element.getAttribute("transaction");
    if (StringUtils.isNotEmpty(transaction)) {
        beanDef.getPropertyValues().addPropertyValue("transaction", transaction);
    } else if (sp) {
        beanDef.getPropertyValues().addPropertyValue("transaction", TransactionMode.BEGIN.getMode());
    }
    String cloneContext = element.getAttribute("cloneContext");
    if (StringUtils.isNotEmpty(cloneContext)) {
        beanDef.getPropertyValues().addPropertyValue("cloneContext", Boolean.parseBoolean(cloneContext));
    }
    String propagations = element.getAttribute("propagations");
    if (StringUtils.isNotEmpty(propagations)) {
        List<String> propataionList = new ArrayList<String>();
        for (String propagation : propagations.split(",")) {
            propataionList.add(propagation);
        }
        beanDef.getPropertyValues().addPropertyValue("propagations", propataionList);
    }
    String nextDataProcessors = element.getAttribute("nextDataProcessors");
    if (StringUtils.isNotEmpty(nextDataProcessors)) {
        List nextDataProcessList = new ManagedList();
        for (String nextDataProcess : nextDataProcessors.split(",")) {
            nextDataProcess = nextDataProcess.trim();
            nextDataProcessList.add(new RuntimeBeanReference(nextDataProcess));
        }
        beanDef.getPropertyValues().addPropertyValue("nextDataProcessors", nextDataProcessList);
    }

    customiseBeanDefinition(beanDef, element, parserContext);

    return beanDef;
}