/** * Creates an instance of a {@code TidaServer}, which is completely * auto-wired according to the configuration. * * @param properties * properties to be set for the configuration * * @return the created {@code TidaServer} instance */ public static TidaServer create(final Properties properties) { final List<PropertiesLoaderSupport> holders; if (properties == null) { holders = null; } else { holders = new ArrayList<PropertiesLoaderSupport>(); // create a propertyHolder for the properties final SpringPropertyHolder holder = new SpringPropertyHolder(); holder.setProperties(properties); holder.setLocalOverride(true); holder.setSystemPropertiesMode(PropertyPlaceholderConfigurer.SYSTEM_PROPERTIES_MODE_NEVER); holder.setOtherHolderOverride(false); // add the propertyHolder holders.add(holder); } // create the instance final ConfigurationCoreSettings settings = ConfigurationCoreSettings .loadCoreSettings("sbconfigurator-core.xml", TidaConfig.class, holders, null); return settings.getConfiguration().getModule("tidaServer"); }
/** * Creates the list of the properties to be used within the configuration * from the outer world. * * @param element * the parent element which contains all the properties * @param parserContext * the <code>ParserContext</code> * * @return the <code>List</code> containing the beans with properties */ protected List<?> createPropertiesList(final Element element, final ParserContext parserContext) { final List<Element> propEls = DomUtils.getChildElementsByTagName( element, XML_ELEMENT_PROPERTIES); // create the list final ManagedList<Object> list = new ManagedList<Object>(propEls.size()); list.setSource(parserContext.extractSource(element)); list.setElementTypeName(PropertiesLoaderSupport.class.getName()); list.setMergeEnabled(false); for (final Element propEl : propEls) { final String loadId = propEl.getAttribute(XML_ATTRIBUTE_LOADID); final RuntimeBeanReference ref = new RuntimeBeanReference(loadId); ref.setSource(parserContext.extractSource(propEl)); list.add(ref); } return list; }
/** * Gets all the properties of the other defined * <code>SpringPropertyHolder</code> instances, whereby the definition-order * matters concerning the overriding of properties, i.e. the latter * definition overrides the earlier (if the same property is defined several * times). * * @return the properties defined by the other * <code>SpringPropertyHolder</code> instances * * @throws IOException * if a file resource is defined but cannot be read or accessed */ protected Properties getOtherProperties() throws IOException { final Properties result = new Properties(); for (final PropertiesLoaderSupport propertyHolder : propertyHolders) { final Properties properties; if (propertyHolder instanceof SpringPropertyHolder) { final SpringPropertyHolder sph = ((SpringPropertyHolder) propertyHolder); properties = sph.getProperties(false); } else { properties = PropertiesAccess.getProperties(propertyHolder); } CollectionUtils.mergePropertiesIntoMap(properties, result); } return result; }
/** * Tests the usage of a placeholder within the selector * * @throws IOException * if the properties cannot be read */ @Test public void testPlaceHolderInSelector() throws IOException { // check that there is onle ony defined assertEquals(1, corePropertyHolder.getOtherPropertyHolder().size()); // get the one defined in the file final PropertiesLoaderSupport propertyHolder = corePropertyHolder .getOtherPropertyHolder().get(0); assertTrue(propertyHolder instanceof SpringPropertyHolder); final SpringPropertyHolder innerHolder = (SpringPropertyHolder) propertyHolder; assertEquals(false, innerHolder.isOtherHolderOverride()); assertEquals(false, innerHolder.isLocalOverride()); assertEquals( PropertyPlaceholderConfigurer.SYSTEM_PROPERTIES_MODE_OVERRIDE, innerHolder.getSystemPropertiesMode()); assertEquals( "net/meisen/general/sbconfigurator/config/placeholder/loader/sampleBeansToBeLoaded.xml", innerHolder.getProperties().get( "sbconfigurator.loader.selector")); assertEquals( "net/meisen/general/sbconfigurator/config/placeholder/loader/sampleBeansToBeLoaded.xml", corePropertyHolder.getProperties().get( "sbconfigurator.loader.selector")); // check if the configuration was able to load the assertNotNull(configuration.getModule("dateModule")); }
/** * Method to load the <code>ConfigurationCoreSettings</code> and all the * other modules used by the <code>CoreSettings</code>. Additionally some * other modules (beans) can be injected via the <code>injections</code>. * * @param coreSettingsContext * the name of the context file to load the * <code>ConfigurationCoreSettings</code> from * @param clazz * using the <code>coreSettingsContext</code> of the specified * class * @param properties * properties to be used within the configuration, can be * <code>null</code> * @param injections * additional injections to be added, can be <code>null</code> * * @return the loaded <code>ConfigurationCoreSettings</code> */ public static ConfigurationCoreSettings loadCoreSettings( final String coreSettingsContext, final Class<?> clazz, final List<PropertiesLoaderSupport> properties, final Map<String, Object> injections) { final String fCoreSettingsContext = coreSettingsContext == null ? ConfigurationCoreSettings.coreSettingsContext : coreSettingsContext; final Class<?> fClazz = clazz == null ? ConfigurationCoreSettings.class : clazz; // create the factory with auto-wiring this will bring up the // core-system final DefaultListableBeanFactory factory = SpringHelper .createBeanFactory(true, true); if (properties != null) { for (final PropertiesLoaderSupport p : properties) { factory.registerSingleton("PROPERTIES_" + UUID.randomUUID().toString(), p); } } // create the reader final XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader( factory); // load the core resource into the reader final Resource coreRes = new ClassPathResource(fCoreSettingsContext, fClazz); reader.loadBeanDefinitions(coreRes); // get the bean final ConfigurationCoreSettings settings = (ConfigurationCoreSettings) factory .getBean(IConfiguration.coreSettingsId); if (LOG.isTraceEnabled()) { LOG.trace("The coreSettings are loaded and auto-wired."); } // trigger the loading of the Configuration if (injections == null) { settings.getConfiguration().loadConfiguration( new HashMap<String, Object>()); } else { settings.getConfiguration().loadConfiguration(injections); } return settings; }
/** * Get all the {@code PropertiesLoader} defined for the * {@code ConfigurationHolder} from outside. * * @return the list with all the {@code PropertiesLoader} * * @see PropertiesLoaderSupport */ public List<PropertiesLoaderSupport> getProperties() { return properties; }
/** * Sets the list with teh {@code PropertiesLoader} defined from outside. * * @param properties * the list with all the {@code PropertiesLoader} * * @see PropertiesLoaderSupport */ public void setProperties(final List<PropertiesLoaderSupport> properties) { this.properties = properties; }
/** * Gets all the other {@code PropertyHolder} instances used by {@code this}. * * @return the other {@code PropertyHolder} instances */ public List<PropertiesLoaderSupport> getOtherPropertyHolder() { return Collections.unmodifiableList(propertyHolders); }