public void mergeProperties()

in activemq-runtime-config/src/main/java/org/apache/activemq/plugin/PropertiesPlaceHolderUtil.java [90:168]


    public void mergeProperties(Document doc, Properties initialProperties, BrokerContext brokerContext) {
        // find resources
        //        <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        //            <property name="locations" || name="properties">
        //              ...
        //            </property>
        //          </bean>
        LinkedList<String> resources = new LinkedList<String>();
        LinkedList<String> propertiesClazzes = new LinkedList<String>();
        NodeList beans = doc.getElementsByTagNameNS("*", "bean");
        for (int i = 0; i < beans.getLength(); i++) {
            Node bean = beans.item(0);
            if (bean.hasAttributes() && bean.getAttributes().getNamedItem("class").getTextContent().contains("PropertyPlaceholderConfigurer")) {
                if (bean.hasChildNodes()) {
                    NodeList beanProps = bean.getChildNodes();
                    for (int j = 0; j < beanProps.getLength(); j++) {
                        Node beanProp = beanProps.item(j);
                        if (Node.ELEMENT_NODE == beanProp.getNodeType() && beanProp.hasAttributes() && beanProp.getAttributes().getNamedItem("name") != null) {
                            String propertyName = beanProp.getAttributes().getNamedItem("name").getTextContent();
                            if ("locations".equals(propertyName)) {

                                // interested in value or list/value of locations property
                                Element beanPropElement = (Element) beanProp;
                                NodeList values = beanPropElement.getElementsByTagNameNS("*", "value");
                                for (int k = 0; k < values.getLength(); k++) {
                                    Node value = values.item(k);
                                    resources.add(value.getFirstChild().getTextContent());
                                }
                            } else if ("properties".equals(propertyName)) {

                                // bean or beanFactory
                                Element beanPropElement = (Element) beanProp;
                                NodeList values = beanPropElement.getElementsByTagNameNS("*", "bean");
                                for (int k = 0; k < values.getLength(); k++) {
                                    Node value = values.item(k);
                                    if (value.hasAttributes()) {
                                        Node beanClassTypeNode = value.getAttributes().getNamedItem("class");
                                        if (beanClassTypeNode != null) {
                                            propertiesClazzes.add(beanClassTypeNode.getFirstChild().getTextContent());
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        for (String value : propertiesClazzes) {
            try {
                Object springBean = getClass().getClassLoader().loadClass(value).getConstructor().newInstance();
                if (springBean instanceof FactoryBean) {
                    // can't access the factory or created properties from spring context so we got to recreate
                    initialProperties.putAll((Properties) FactoryBean.class.getMethod("getObject", (Class<?>[]) null).invoke(springBean));
                }
            } catch (Throwable e) {
                LOG.debug("unexpected exception processing properties bean class: " + propertiesClazzes, e);
            }
        }
        List<Resource> propResources = new LinkedList<Resource>();
        for (String value : resources) {
            try {
                if (!value.isEmpty()) {
                    propResources.add(Utils.resourceFromString(filter(value)));
                }
            } catch (MalformedURLException e) {
                LOG.info("failed to resolve resource: " + value, e);
            }
        }
        for (Resource resource : propResources) {
            Properties properties = new Properties();
            try {
                properties.load(resource.getInputStream());
            } catch (IOException e) {
                LOG.info("failed to load properties resource: " + resource, e);
            }
            initialProperties.putAll(properties);
        }
    }