Example usage for org.springframework.beans PropertyValue getValue

List of usage examples for org.springframework.beans PropertyValue getValue

Introduction

In this page you can find the example usage for org.springframework.beans PropertyValue getValue.

Prototype

@Nullable
public Object getValue() 

Source Link

Document

Return the value of the property.

Usage

From source file:org.guicerecipes.spring.converter.SpringConverter.java

@SuppressWarnings("unchecked")
protected void generateBeanDefinition(ModuleGenerator generator, String name, BeanDefinition definition,
        String className) {/* ww w. j ava 2s . co  m*/
    String shortClassName = addImport(className);
    ProduceMethod method = generator.startProvides(name, shortClassName);

    ConstructorArgumentValues constructors = definition.getConstructorArgumentValues();
    Map map = constructors.getIndexedArgumentValues();
    for (int i = 0, size = map.size(); i < size; i++) {
        ValueHolder valueHolder = (ValueHolder) map.get(i);
        if (valueHolder != null) {
            Object value = valueHolder.getValue();
            if (value instanceof TypedStringValue) {
                TypedStringValue stringValue = (TypedStringValue) value;
                String text = stringValue.getValue();
                System.out.printf("param %s=\"%s\"\n", i, text);
                String expression = null;
                String namedParameter = namedParameter(text);
                if (namedParameter != null) {
                    expression = addParameter(method, "String", namedParameter);
                } else {
                    expression = "\"" + text + "\"";
                }
                method.addConstructorExpression(expression);
            } else if (value instanceof BeanReference) {
                BeanReference reference = (BeanReference) value;
                String beanRef = reference.getBeanName();
                // TODO
                String typeName = "Object";
                String expression = addParameter(method, typeName, beanRef);
                method.addConstructorExpression(expression);
            }
        }
    }

    MutablePropertyValues propertyValues = definition.getPropertyValues();
    PropertyValue[] propertyArray = propertyValues.getPropertyValues();
    for (PropertyValue propertyValue : propertyArray) {
        String property = getSetterMethod(propertyValue);
        Object value = propertyValue.getConvertedValue();
        if (value == null) {
            value = propertyValue.getValue();
        }
        if (value instanceof BeanReference) {
            BeanReference reference = (BeanReference) value;
            String beanRef = reference.getBeanName();
            // TODO
            String typeName = "Object";
            String expression = addParameter(method, typeName, beanRef);
            method.addMethodCall("answer", getSetterMethod(propertyValue), expression);
        } else if (value instanceof BeanDefinitionHolder) {
            BeanDefinitionHolder beanDefinitionHolder = (BeanDefinitionHolder) value;
            addChildBeanDefinition(generator, method, name, propertyValue,
                    beanDefinitionHolder.getBeanDefinition());
        } else if (value instanceof ChildBeanDefinition) {
            ChildBeanDefinition childBeanDefinition = (ChildBeanDefinition) value;
            addChildBeanDefinition(generator, method, name, propertyValue, childBeanDefinition);
        } else {
            if (value instanceof TypedStringValue) {
                TypedStringValue stringValue = (TypedStringValue) value;
                value = stringValue.getValue();

            }
            String valueType = (value == null) ? null : value.getClass().getName();
            System.out.printf("property %s=%s of type %s\n", property, value, valueType);

            String expression;
            if (value instanceof String) {
                String text = (String) value;
                String namedParameter = namedParameter(text);
                if (namedParameter != null) {
                    expression = addParameter(method, "String", namedParameter);
                } else {
                    expression = "\"" + value + "\"";
                }
            } else if (value == null) {
                expression = "null";
            } else {
                expression = value.toString();
            }
            method.addMethodCall("answer", getSetterMethod(propertyValue), expression);
        }
    }
}

From source file:org.guiceyfruit.spring.converter.SpringConverter.java

protected void generateBeanDefinition(ModuleGenerator generator, String name, BeanDefinition definition,
        String className) {/*w w  w .jav a  2 s .  c o  m*/
    String shortClassName = addImport(className);
    ProduceMethod method = generator.startProvides(name, shortClassName);

    ConstructorArgumentValues constructors = definition.getConstructorArgumentValues();
    Map map = constructors.getIndexedArgumentValues();
    for (int i = 0, size = map.size(); i < size; i++) {
        ValueHolder valueHolder = (ValueHolder) map.get(i);
        if (valueHolder != null) {
            Object value = valueHolder.getValue();
            if (value instanceof TypedStringValue) {
                TypedStringValue stringValue = (TypedStringValue) value;
                String text = stringValue.getValue();
                System.out.printf("param %s=\"%s\"\n", i, text);
                String expression = null;
                String namedParameter = namedParameter(text);
                if (namedParameter != null) {
                    expression = addParameter(method, "String", namedParameter);
                } else {
                    expression = "\"" + text + "\"";
                }
                method.addConstructorExpression(expression);
            } else if (value instanceof BeanReference) {
                BeanReference reference = (BeanReference) value;
                String beanRef = reference.getBeanName();
                // TODO
                String typeName = "Object";
                String expression = addParameter(method, typeName, beanRef);
                method.addConstructorExpression(expression);
            }
        }
    }

    MutablePropertyValues propertyValues = definition.getPropertyValues();
    PropertyValue[] propertyArray = propertyValues.getPropertyValues();
    for (PropertyValue propertyValue : propertyArray) {
        String property = getSetterMethod(propertyValue);
        Object value = propertyValue.getConvertedValue();
        if (value == null) {
            value = propertyValue.getValue();
        }
        if (value instanceof BeanReference) {
            BeanReference reference = (BeanReference) value;
            String beanRef = reference.getBeanName();
            // TODO
            String typeName = "Object";
            String expression = addParameter(method, typeName, beanRef);
            method.addMethodCall("answer", getSetterMethod(propertyValue), expression);
        } else if (value instanceof BeanDefinitionHolder) {
            BeanDefinitionHolder beanDefinitionHolder = (BeanDefinitionHolder) value;
            addChildBeanDefinition(generator, method, name, propertyValue,
                    beanDefinitionHolder.getBeanDefinition());
        } else if (value instanceof ChildBeanDefinition) {
            ChildBeanDefinition childBeanDefinition = (ChildBeanDefinition) value;
            addChildBeanDefinition(generator, method, name, propertyValue, childBeanDefinition);
        } else {
            if (value instanceof TypedStringValue) {
                TypedStringValue stringValue = (TypedStringValue) value;
                value = stringValue.getValue();

            }
            String valueType = (value == null) ? null : value.getClass().getName();
            System.out.printf("property %s=%s of type %s\n", property, value, valueType);

            String expression;
            if (value instanceof String) {
                String text = (String) value;
                String namedParameter = namedParameter(text);
                if (namedParameter != null) {
                    expression = addParameter(method, "String", namedParameter);
                } else {
                    expression = "\"" + value + "\"";
                }
            } else if (value == null) {
                expression = "null";
            } else {
                expression = value.toString();
            }
            method.addMethodCall("answer", getSetterMethod(propertyValue), expression);
        }
    }
}

From source file:com.brienwheeler.apps.schematool.SchemaToolBean.java

@SuppressWarnings("unchecked")
private PersistenceUnitManager simulateDefaultPum(NonInitializingClassPathXmlApplicationContext context,
        BeanDefinition emfBeanDef) {//from w  w  w  . j a  va  2 s.c  om
    // Simulate Spring's use of DefaultPersistenceUnitManager
    DefaultPersistenceUnitManager defpum = new DefaultPersistenceUnitManager();

    // Set the location of the persistence XML -- when using the DPUM,
    // you can only set one persistence XML location on the EntityManagerFactory
    PropertyValue locationProperty = emfBeanDef.getPropertyValues().getPropertyValue("persistenceXmlLocation");
    if (locationProperty == null || !(locationProperty.getValue() instanceof TypedStringValue)) {
        throw new RuntimeException(
                "no property 'persistenceXmlLocation' defined on bean: " + emfContextBeanName);
    }

    // Since PersistenceUnitPostProcessors may do things like set properties
    // onto the persistence unit, we need to instantiate them here so that
    // they get called when preparePersistenceUnitInfos() executes
    PropertyValue puiPostProcProperty = emfBeanDef.getPropertyValues()
            .getPropertyValue("persistenceUnitPostProcessors");
    if (puiPostProcProperty != null && puiPostProcProperty.getValue() instanceof ManagedList) {
        List<PersistenceUnitPostProcessor> postProcessors = new ArrayList<PersistenceUnitPostProcessor>();
        for (BeanDefinitionHolder postProcBeanDef : (ManagedList<BeanDefinitionHolder>) puiPostProcProperty
                .getValue()) {
            String beanName = postProcBeanDef.getBeanName();
            BeanDefinition beanDefinition = postProcBeanDef.getBeanDefinition();
            PersistenceUnitPostProcessor postProcessor = (PersistenceUnitPostProcessor) context
                    .createBean(beanName, beanDefinition);
            postProcessors.add(postProcessor);
        }
        defpum.setPersistenceUnitPostProcessors(
                postProcessors.toArray(new PersistenceUnitPostProcessor[postProcessors.size()]));
    }

    defpum.setPersistenceXmlLocation(((TypedStringValue) locationProperty.getValue()).getValue());
    defpum.preparePersistenceUnitInfos();

    return defpum;
}

From source file:com.brienwheeler.apps.schematool.SchemaToolBean.java

private Configuration determineHibernateConfiguration()
        throws MappingException, ClassNotFoundException, IOException {
    // Read in the bean definitions but don't go creating all the singletons,
    // because that causes creation of data sources and connections to database, etc.
    NonInitializingClassPathXmlApplicationContext context = new NonInitializingClassPathXmlApplicationContext(
            new String[] { emfContextLocation });
    try {//w w  w .  ja v  a  2 s .c  o m
        context.loadBeanDefinitions();

        // Get well-known EntityManagerFactory bean definition by name
        BeanDefinition emfBeanDef = context.getBeanDefinition(emfContextBeanName);
        if (emfBeanDef == null) {
            throw new RuntimeException("no bean defined: " + emfContextBeanName);
        }

        // Get the name of the persistence unit for this EntityManagerFactory
        PropertyValue puNameProperty = emfBeanDef.getPropertyValues().getPropertyValue("persistenceUnitName");
        if (puNameProperty == null || !(puNameProperty.getValue() instanceof TypedStringValue)) {
            throw new RuntimeException(
                    "no property 'persistenceUnitName' defined on bean: " + emfContextBeanName);
        }
        String puName = ((TypedStringValue) puNameProperty.getValue()).getValue();

        // Get the name of the persistence unit for this EntityManagerFactory
        PropertyValue pumProperty = emfBeanDef.getPropertyValues().getPropertyValue("persistenceUnitManager");
        PersistenceUnitManager pum = null;
        if (pumProperty != null) {
            pum = createConfiguredPum(context, pumProperty);
        } else {
            pum = simulateDefaultPum(context, emfBeanDef);
        }

        // create the Hibernate configuration
        PersistenceUnitInfo pui = pum.obtainPersistenceUnitInfo(puName);
        Configuration configuration = new Configuration();
        configuration.setProperties(pui.getProperties());
        for (String className : pui.getManagedClassNames()) {
            configuration.addAnnotatedClass(Class.forName(className));
        }

        return configuration;
    } finally {
        context.close();
    }
}

From source file:org.bytesoft.bytetcc.supports.zk.TransactionCuratorClient.java

public void initZookeeperAddressIfNecessary(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    String[] beanNameArray = beanFactory.getBeanDefinitionNames();
    for (int i = 0; i < beanNameArray.length; i++) {
        String beanName = beanNameArray[i];
        BeanDefinition beanDef = beanFactory.getBeanDefinition(beanName);
        if (com.alibaba.dubbo.config.RegistryConfig.class.getName().equals(beanDef.getBeanClassName())) {
            MutablePropertyValues mpv = beanDef.getPropertyValues();
            PropertyValue protpv = mpv.getPropertyValue(KEY_DUBBO_REGISTRY_PROTOCOL);
            PropertyValue addrpv = mpv.getPropertyValue(KEY_DUBBO_REGISTRY_ADDRESS);

            String protocol = null;
            String address = null;
            if (addrpv == null) {
                throw new FatalBeanException("zookeeper address cannot be null!"); // should never happen
            } else if (protpv == null) {
                String value = String.valueOf(addrpv.getValue());
                try {
                    URL url = new URL(null, value, this);
                    protocol = url.getProtocol();
                    address = url.getAuthority();
                } catch (Exception ex) {
                    throw new FatalBeanException("Unsupported format!");
                }//from   w w  w. ja v  a  2s. co  m
            } else {
                protocol = String.valueOf(protpv.getValue());
                String value = StringUtils.trimToEmpty(String.valueOf(addrpv.getValue()));
                int index = value.indexOf(protocol);
                if (index == -1) {
                    address = value;
                } else if (index == 0) {
                    String str = StringUtils.trimToEmpty(value.substring(protocol.length()));
                    if (str.startsWith("://")) {
                        address = StringUtils.trimToEmpty(str.substring(3));
                    } else {
                        throw new FatalBeanException("Unsupported format!");
                    }
                } else {
                    throw new FatalBeanException("Unsupported format!");
                }
            }

            if (KEY_DUBBO_REGISTRY_ZOOKEEPER.equalsIgnoreCase(protocol) == false) {
                throw new FatalBeanException("Unsupported protocol!");
            }

            String addrKey = "zookeeperAddr";
            String[] watcherBeanArray = beanFactory
                    .getBeanNamesForType(org.bytesoft.bytetcc.supports.zk.TransactionCuratorClient.class);
            BeanDefinition watcherBeanDef = beanFactory.getBeanDefinition(watcherBeanArray[0]);
            MutablePropertyValues warcherMpv = watcherBeanDef.getPropertyValues();
            PropertyValue warcherPv = warcherMpv.getPropertyValue(addrKey);
            if (warcherPv == null) {
                warcherMpv.addPropertyValue(new PropertyValue(addrKey, address));
            } else {
                warcherMpv.removePropertyValue(addrKey);
                warcherMpv.addPropertyValue(new PropertyValue(addrKey, address));
            }

        }
    }
}

From source file:org.musicrecital.dao.spring.HibernateExtensionPostProcessor.java

/**
 * Adds the annotated classes and the mapping resources to the existing Session Factory configuration.
 * @param configurableListableBeanFactory the good ol' bean factory
 *//*from  ww w.  j a v  a2s .c  o  m*/
@SuppressWarnings("unchecked")
public void postProcessBeanFactory(ConfigurableListableBeanFactory configurableListableBeanFactory) {
    if (configurableListableBeanFactory.containsBean(sessionFactoryBeanName)) {
        BeanDefinition sessionFactoryBeanDefinition = configurableListableBeanFactory
                .getBeanDefinition(sessionFactoryBeanName);
        MutablePropertyValues propertyValues = sessionFactoryBeanDefinition.getPropertyValues();

        if (mappingResources != null) {
            // do we have existing resourses?
            PropertyValue propertyValue = propertyValues.getPropertyValue("mappingResources");

            if (propertyValue == null) {
                propertyValue = new PropertyValue("mappingResources", new ArrayList());
                propertyValues.addPropertyValue(propertyValue);
            }

            // value is expected to be a list.
            List existingMappingResources = (List) propertyValue.getValue();
            existingMappingResources.addAll(mappingResources);
        }

        if (annotatedClasses != null) {
            // do we have existing resources?
            PropertyValue propertyValue = propertyValues.getPropertyValue("annotatedClasses");

            if (propertyValue == null) {
                propertyValue = new PropertyValue("annotatedClasses", new ArrayList());
                propertyValues.addPropertyValue(propertyValue);
            }

            // value is expected to be a list.
            List existingMappingResources = (List) propertyValue.getValue();
            existingMappingResources.addAll(annotatedClasses);
        }

        if (configLocations != null) {
            PropertyValue propertyValue = propertyValues.getPropertyValue("configLocations");
            if (propertyValue == null) {
                propertyValue = new PropertyValue("configLocations", new ArrayList());
                propertyValues.addPropertyValue(propertyValue);
            }
            List existingConfigLocations = (List) propertyValue.getValue();
            existingConfigLocations.addAll(configLocations);
        }

        if (hibernateProperties != null) {
            PropertyValue propertyValue = propertyValues.getPropertyValue("hibernateProperties");
            if (propertyValue == null) {
                propertyValue = new PropertyValue("hibernateProperties", new Properties());
                propertyValues.addPropertyValue(propertyValue);
            }
            Properties existingHibernateProperties = (Properties) propertyValue.getValue();
            existingHibernateProperties.putAll(hibernateProperties);
        }
    } else {
        throw new NoSuchBeanDefinitionException(
                "No bean named [" + sessionFactoryBeanName + "] exists within the bean factory. "
                        + "Cannot post process session factory to add Hibernate resource definitions.");
    }
}

From source file:org.drools.container.spring.namespace.KnowledgeSessionDefinitionParser.java

@SuppressWarnings("unchecked")
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {

    String id = element.getAttribute("id");
    emptyAttributeCheck(element.getLocalName(), "id", id);

    String kbase = element.getAttribute(KBASE_ATTRIBUTE);
    emptyAttributeCheck(element.getLocalName(), KBASE_ATTRIBUTE, kbase);

    String sessionType = element.getAttribute(TYPE_ATTRIBUTE);
    BeanDefinitionBuilder factory;//from  w  w w.  j  av a  2s .  c  o m

    if ("stateful".equals(sessionType)) {
        factory = BeanDefinitionBuilder.rootBeanDefinition(StatefulKnowledgeSessionBeanFactory.class);
    } else if ("stateless".equals(sessionType)) {
        factory = BeanDefinitionBuilder.rootBeanDefinition(StatelessKnowledgeSessionBeanFactory.class);
    } else {
        throw new IllegalArgumentException(
                "Invalid value for " + TYPE_ATTRIBUTE + " attribute: " + sessionType);
    }

    factory.addPropertyReference("kbase", kbase);

    String node = element.getAttribute(GRID_NODE_ATTRIBUTE);
    if (node != null && node.length() > 0) {
        factory.addPropertyReference("node", node);
    }

    String name = element.getAttribute(NAME_ATTRIBUTE);
    if (StringUtils.hasText(name)) {
        factory.addPropertyValue("name", name);
    } else {
        factory.addPropertyValue("name", id);
    }

    // Additions for JIRA JBRULES-3076
    String listeners = element.getAttribute(LISTENERS_ATTRIBUTE);
    if (StringUtils.hasText(listeners)) {
        factory.addPropertyValue("eventListenersFromGroup", new RuntimeBeanReference(listeners));
    }
    EventListenersUtil.parseEventListeners(parserContext, factory, element);
    // End of Additions for JIRA JBRULES-3076

    Element ksessionConf = DomUtils.getChildElementByTagName(element, "configuration");
    if (ksessionConf != null) {
        Element persistenceElm = DomUtils.getChildElementByTagName(ksessionConf, "jpa-persistence");
        if (persistenceElm != null) {
            BeanDefinitionBuilder beanBuilder = BeanDefinitionBuilder
                    .genericBeanDefinition(JpaConfiguration.class);

            String loadId = persistenceElm.getAttribute("load");
            if (StringUtils.hasText(loadId)) {
                beanBuilder.addPropertyValue("id", Long.parseLong(loadId));
            }

            Element tnxMng = DomUtils.getChildElementByTagName(persistenceElm, TX_MANAGER_ATTRIBUTE);
            String ref = tnxMng.getAttribute("ref");

            beanBuilder.addPropertyReference("platformTransactionManager", ref);

            Element emf = DomUtils.getChildElementByTagName(persistenceElm, EMF_ATTRIBUTE);
            ref = emf.getAttribute("ref");
            beanBuilder.addPropertyReference("entityManagerFactory", ref);

            Element variablePersisters = DomUtils.getChildElementByTagName(persistenceElm,
                    "variable-persisters");
            if (variablePersisters != null && variablePersisters.hasChildNodes()) {
                List<Element> childPersisterElems = DomUtils.getChildElementsByTagName(variablePersisters,
                        "persister");
                ManagedMap persistors = new ManagedMap(childPersisterElems.size());
                for (Element persisterElem : childPersisterElems) {
                    String forClass = persisterElem.getAttribute(FORCLASS_ATTRIBUTE);
                    String implementation = persisterElem.getAttribute(IMPLEMENTATION_ATTRIBUTE);
                    if (!StringUtils.hasText(forClass)) {
                        throw new RuntimeException("persister element must have valid for-class attribute");
                    }
                    if (!StringUtils.hasText(implementation)) {
                        throw new RuntimeException(
                                "persister element must have valid implementation attribute");
                    }
                    persistors.put(forClass, implementation);
                }
                beanBuilder.addPropertyValue("variablePersisters", persistors);
            }

            factory.addPropertyValue("jpaConfiguration", beanBuilder.getBeanDefinition());
        }
        BeanDefinitionBuilder rbaseConfBuilder = BeanDefinitionBuilder
                .rootBeanDefinition(SessionConfiguration.class);
        Element e = DomUtils.getChildElementByTagName(ksessionConf, KEEP_REFERENCE);
        if (e != null && StringUtils.hasText(e.getAttribute("enabled"))) {
            rbaseConfBuilder.addPropertyValue("keepReference", Boolean.parseBoolean(e.getAttribute("enabled")));
        }

        e = DomUtils.getChildElementByTagName(ksessionConf, CLOCK_TYPE);
        if (e != null && StringUtils.hasText(e.getAttribute("type"))) {
            rbaseConfBuilder.addPropertyValue("clockType", ClockType.resolveClockType(e.getAttribute("type")));
        }
        factory.addPropertyValue("conf", rbaseConfBuilder.getBeanDefinition());

        e = DomUtils.getChildElementByTagName(ksessionConf, WORK_ITEMS);
        if (e != null) {
            List<Element> children = DomUtils.getChildElementsByTagName(e, WORK_ITEM);
            if (children != null && !children.isEmpty()) {
                ManagedMap workDefs = new ManagedMap();
                for (Element child : children) {
                    workDefs.put(child.getAttribute("name"),
                            new RuntimeBeanReference(child.getAttribute("ref")));
                }
                factory.addPropertyValue("workItems", workDefs);
            }
        }
    }

    Element batch = DomUtils.getChildElementByTagName(element, "batch");
    if (batch == null) {
        // just temporary legacy suppport
        batch = DomUtils.getChildElementByTagName(element, "script");
    }
    if (batch != null) {
        // we know there can only ever be one
        ManagedList children = new ManagedList();

        for (int i = 0, length = batch.getChildNodes().getLength(); i < length; i++) {
            Node n = batch.getChildNodes().item(i);
            if (n instanceof Element) {
                Element e = (Element) n;

                BeanDefinitionBuilder beanBuilder = null;
                if ("insert-object".equals(e.getLocalName())) {
                    String ref = e.getAttribute("ref");
                    Element nestedElm = getFirstElement(e.getChildNodes());
                    beanBuilder = BeanDefinitionBuilder.genericBeanDefinition(InsertObjectCommand.class);
                    if (StringUtils.hasText(ref)) {
                        beanBuilder.addConstructorArgReference(ref);
                    } else if (nestedElm != null) {
                        beanBuilder.addConstructorArgValue(
                                parserContext.getDelegate().parsePropertySubElement(nestedElm, null, null));
                    } else {
                        throw new IllegalArgumentException(
                                "insert-object must either specify a 'ref' attribute or have a nested bean");
                    }
                } else if ("set-global".equals(e.getLocalName())) {
                    String ref = e.getAttribute("ref");
                    Element nestedElm = getFirstElement(e.getChildNodes());
                    beanBuilder = BeanDefinitionBuilder.genericBeanDefinition(SetGlobalCommand.class);
                    beanBuilder.addConstructorArgValue(e.getAttribute("identifier"));
                    if (StringUtils.hasText(ref)) {
                        beanBuilder.addConstructorArgReference(ref);
                    } else if (nestedElm != null) {
                        beanBuilder.addConstructorArgValue(
                                parserContext.getDelegate().parsePropertySubElement(nestedElm, null, null));
                    } else {
                        throw new IllegalArgumentException(
                                "set-global must either specify a 'ref' attribute or have a nested bean");
                    }
                } else if ("fire-until-halt".equals(e.getLocalName())) {
                    beanBuilder = BeanDefinitionBuilder.genericBeanDefinition(FireUntilHaltCommand.class);
                } else if ("fire-all-rules".equals(e.getLocalName())) {
                    beanBuilder = BeanDefinitionBuilder.genericBeanDefinition(FireAllRulesCommand.class);
                    String max = e.getAttribute("max");
                    if (StringUtils.hasText(max)) {
                        beanBuilder.addPropertyValue("max", max);
                    }
                } else if ("start-process".equals(e.getLocalName())) {

                    beanBuilder = BeanDefinitionBuilder.genericBeanDefinition(StartProcessCommand.class);
                    String processId = e.getAttribute("process-id");
                    if (!StringUtils.hasText(processId)) {
                        throw new IllegalArgumentException("start-process must specify a process-id");
                    }
                    beanBuilder.addConstructorArgValue(processId);

                    List<Element> params = DomUtils.getChildElementsByTagName(e, "parameter");
                    if (!params.isEmpty()) {
                        ManagedMap map = new ManagedMap();
                        for (Element param : params) {
                            String identifier = param.getAttribute("identifier");
                            if (!StringUtils.hasText(identifier)) {
                                throw new IllegalArgumentException(
                                        "start-process paramaters must specify an identifier");
                            }

                            String ref = param.getAttribute("ref");
                            Element nestedElm = getFirstElement(param.getChildNodes());
                            if (StringUtils.hasText(ref)) {
                                map.put(identifier, new RuntimeBeanReference(ref));
                            } else if (nestedElm != null) {
                                map.put(identifier, parserContext.getDelegate()
                                        .parsePropertySubElement(nestedElm, null, null));
                            } else {
                                throw new IllegalArgumentException(
                                        "start-process parameters must either specify a 'ref' attribute or have a nested bean");
                            }
                        }
                        beanBuilder.addPropertyValue("parameters", map);
                    }
                } else if ("signal-event".equals(e.getLocalName())) {
                    beanBuilder = BeanDefinitionBuilder.genericBeanDefinition(SignalEventCommand.class);
                    String processInstanceId = e.getAttribute("process-instance-id");
                    if (StringUtils.hasText(processInstanceId)) {
                        beanBuilder.addConstructorArgValue(processInstanceId);
                    }

                    beanBuilder.addConstructorArgValue(e.getAttribute("event-type"));

                    String ref = e.getAttribute("ref");
                    Element nestedElm = getFirstElement(e.getChildNodes());
                    if (StringUtils.hasText(ref)) {
                        beanBuilder.addConstructorArgReference(ref);
                    } else if (nestedElm != null) {
                        beanBuilder.addConstructorArgValue(
                                parserContext.getDelegate().parsePropertySubElement(nestedElm, null, null));
                    } else {
                        throw new IllegalArgumentException(
                                "signal-event must either specify a 'ref' attribute or have a nested bean");
                    }
                }
                if (beanBuilder == null) {
                    throw new IllegalStateException("Unknow element: " + e.getLocalName());
                }
                children.add(beanBuilder.getBeanDefinition());
            }
        }
        factory.addPropertyValue("batch", children);
    }

    // find any kagent's for the current kbase and assign (only if this 
    // is a stateless session)
    if (sessionType.equals("stateless")) {
        for (String beanName : parserContext.getRegistry().getBeanDefinitionNames()) {
            BeanDefinition def = parserContext.getRegistry().getBeanDefinition(beanName);
            if (KnowledgeAgentBeanFactory.class.getName().equals(def.getBeanClassName())) {
                PropertyValue pvalue = def.getPropertyValues().getPropertyValue("kbase");
                RuntimeBeanReference tbf = (RuntimeBeanReference) pvalue.getValue();
                if (kbase.equals(tbf.getBeanName())) {
                    factory.addPropertyValue("knowledgeAgent", new RuntimeBeanReference(beanName));
                }
            }
        }
    }

    return factory.getBeanDefinition();
}

From source file:com.dianping.zebra.monitor.spring.DataSourceAutoMonitor.java

@SuppressWarnings("unchecked")
private void replaceInnerDataSourceInZebra(String beanName, BeanDefinition zebraDataSourceDefinition) {
    MutablePropertyValues propertyValues = zebraDataSourceDefinition.getPropertyValues();
    PropertyValue dataSourcePoolVal = propertyValues.getPropertyValue("dataSourcePool");

    if (dataSourcePoolVal == null) {
        if (logger.isWarnEnabled()) {
            logger.warn("Zebra dataSource's dataSourcePool property not found, maybe its name is modified, "
                    + "change the automonitor's implementation, otherwise some inner dataSource cannot be monitored.");
        }/*from w  w w  .j  a v a  2  s .  c o  m*/
        return;
    }

    Map<TypedStringValue, Object> innerDSDefinitionMap = (Map<TypedStringValue, Object>) dataSourcePoolVal
            .getValue();
    for (Entry<TypedStringValue, Object> innerDSDefEntry : innerDSDefinitionMap.entrySet()) {
        Object innerDSDefVal = innerDSDefEntry.getValue();
        if (innerDSDefVal instanceof BeanDefinitionHolder) {
            BeanDefinitionHolder innerDSDefHolder = (BeanDefinitionHolder) innerDSDefVal;
            BeanDefinition innerDSDefinition = innerDSDefHolder.getBeanDefinition();
            innerDSDefEntry.setValue(
                    new BeanDefinitionHolder(createMonitorableBeanDefinition(beanName, innerDSDefinition),
                            innerDSDefHolder.getBeanName(), innerDSDefHolder.getAliases()));
        }
    }
}

From source file:com.dianping.zebra.monitor.spring.DataSourceAutoMonitor.java

@SuppressWarnings("unchecked")
private boolean checkInnerDataSourceInZebra(String beanName, BeanDefinition zebraDataSourceDefinition) {
    MutablePropertyValues propertyValues = zebraDataSourceDefinition.getPropertyValues();
    PropertyValue dataSourcePoolVal = propertyValues.getPropertyValue("dataSourcePool");

    if (dataSourcePoolVal == null) {
        if (logger.isWarnEnabled()) {
            logger.warn("Zebra dataSource's dataSourcePool property not found, maybe its name is modified, "
                    + "change the automonitor's implementation, otherwise some inner dataSource cannot be monitored.");
        }/*from   ww w .  j  a v a2 s. c o  m*/
        return true;
    }

    Map<TypedStringValue, Object> innerDSDefinitionMap = (Map<TypedStringValue, Object>) dataSourcePoolVal
            .getValue();
    for (Entry<TypedStringValue, Object> innerDSDefEntry : innerDSDefinitionMap.entrySet()) {
        Object innerDSDefVal = innerDSDefEntry.getValue();
        if (innerDSDefVal instanceof BeanDefinitionHolder) {
            BeanDefinitionHolder innerDSDefHolder = (BeanDefinitionHolder) innerDSDefVal;
            BeanDefinition innerDSDefinition = innerDSDefHolder.getBeanDefinition();
            if (GroupDataSource.class.getName().equals(innerDSDefinition.getBeanClassName())) {
                return false;
            }
        }
    }

    return false;
}

From source file:de.acosix.alfresco.mtsupport.repo.beans.TenantLDAPAttributeMappingPostProcessor.java

/**
 * {@inheritDoc}/*from w w w  .j av a 2s. c o  m*/
 */
@SuppressWarnings("unchecked")
@Override
public void postProcessBeanDefinitionRegistry(final BeanDefinitionRegistry registry) throws BeansException {
    if (this.isEnabled()) {
        final String enabledTenantsProperty = this.effectiveProperties
                .getProperty(this.enabledTenantPropertyKey);
        if (enabledTenantsProperty == null || enabledTenantsProperty.trim().isEmpty()) {
            LOGGER.debug("No tenants have been defined as enabled");
        } else {
            final List<String> enabledTenants = Arrays.asList(enabledTenantsProperty.trim().split("\\s*,\\s*"));
            LOGGER.debug("Processing custom LDAP attribute mappings for property {} and enabled tenants {}",
                    this.propertyName, enabledTenants);

            for (final String enabledTenant : enabledTenants) {
                final String tenantBasePrefix = this.mappingPropertyPrefix + "." + enabledTenant + "."
                        + this.propertyName + ".";
                final String globalBasePrefix = this.mappingPropertyPrefix + "." + this.propertyName + ".";

                final String tenantMappingPropertiesKey = tenantBasePrefix + "customMappings";
                final String globalMappingPropertiesKey = globalBasePrefix + "customMappings";

                final String globalMappingsPropertyString = this.effectiveProperties
                        .getProperty(globalMappingPropertiesKey);
                final String tenantMappingsPropertyString = this.effectiveProperties
                        .getProperty(tenantMappingPropertiesKey, globalMappingsPropertyString);

                if (tenantMappingsPropertyString != null && !tenantMappingsPropertyString.trim().isEmpty()) {
                    final BeanDefinition beanDefinition = TenantBeanUtils.getBeanDefinitionForTenant(registry,
                            this.beanName, enabledTenant);

                    Map<Object, Object> configuredMapping;
                    final PropertyValue propertyValue = beanDefinition.getPropertyValues()
                            .getPropertyValue(this.propertyName);
                    if (propertyValue == null) {
                        configuredMapping = new ManagedMap<>();
                        beanDefinition.getPropertyValues().add(this.propertyName, configuredMapping);
                    } else {
                        final Object value = propertyValue.getValue();
                        if (value instanceof Map<?, ?>) {
                            configuredMapping = (Map<Object, Object>) value;
                        } else {
                            throw new IllegalStateException("Configured property value is not a map");
                        }
                    }

                    final String[] mappingProperties = tenantMappingsPropertyString.trim().split("\\s*,\\s*");
                    for (final String mappingProperty : mappingProperties) {
                        final String globalMappingValuePropertyKey = globalBasePrefix + mappingProperty;
                        final String tenantMappingValuePropertyKey = tenantBasePrefix + mappingProperty;

                        final String globalMappingValue = this.effectiveProperties
                                .getProperty(globalMappingValuePropertyKey);
                        final String tenantMappingValue = this.effectiveProperties
                                .getProperty(tenantMappingValuePropertyKey, globalMappingValue);

                        final String trimmedMappingValue = tenantMappingValue != null
                                ? tenantMappingValue.trim()
                                : null;
                        if (trimmedMappingValue != null && !trimmedMappingValue.isEmpty()) {
                            if (this.beanReferences) {
                                if (VALUE_NULL.equals(trimmedMappingValue)) {
                                    configuredMapping.remove(mappingProperty);
                                } else {
                                    configuredMapping.put(mappingProperty,
                                            new RuntimeBeanReference(trimmedMappingValue));
                                }
                            } else {
                                if (VALUE_NULL.equals(trimmedMappingValue)) {
                                    configuredMapping.put(mappingProperty, null);
                                } else {
                                    configuredMapping.put(mappingProperty, trimmedMappingValue);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}