/** * {@inheritDoc} This method is overridden to adapt the return type. */ @Override public MultiFileConfigurationBuilder<T> configure(final BuilderParameters... params) { super.configure(params); return this; }
/** * Creates the new, uninitialized result object. This is the first step of * the process of producing a result object for this builder. This * implementation uses the {@link BeanHelper} class to create a new object * based on the {@link BeanDeclaration} returned by * {@link #getResultDeclaration()}. Note: This method is invoked in a * synchronized block. * * @return the newly created, yet uninitialized result object * @throws ConfigurationException if an exception occurs */ protected T createResultInstance() throws ConfigurationException { final Object bean = fetchBeanHelper().createBean(getResultDeclaration()); checkResultInstance(bean); return getResultClass().cast(bean); }
/** * Copies all {@code EventListener} objects registered at this builder to * the specified target configuration builder. This method is intended to be * used by derived classes which support inheritance of their properties to * other builder objects. * * @param target the target configuration builder (must not be <b>null</b>) * @throws NullPointerException if the target builder is <b>null</b> */ protected synchronized void copyEventListeners( final BasicConfigurationBuilder<?> target) { copyEventListeners(target, eventListeners); }
/** * Returns the {@code BeanDeclaration} that is used to create and initialize * result objects. The declaration is created on first access (by invoking * {@link #createResultDeclaration(Map)}) based on the current * initialization parameters. * * @return the {@code BeanDeclaration} for dynamically creating a result * object * @throws ConfigurationException if an error occurs */ protected final synchronized BeanDeclaration getResultDeclaration() throws ConfigurationException { if (resultDeclaration == null) { resultDeclaration = createResultDeclaration(getFilteredParameters()); } return resultDeclaration; }
final T resObj = createResultInstance(); initResultInstance(resObj); if (!isAllowFailOnInit())
@Override public String toString() { PropertiesConfiguration cfg = null; try { if (isOpen()) { cfg = config.getConfiguration(); } } catch (ConfigurationException exc) { } return super.toString() + "{url: " + getName() + ", delay: " + refDelay + ", config: " + cfg + "}"; }
/** * {@inheritDoc} This implementation ensures that the listener is also * removed from managed configuration builders if necessary. */ @Override public synchronized <E extends Event> boolean removeEventListener( final EventType<E> eventType, final EventListener<? super E> l) { final boolean result = super.removeEventListener(eventType, l); if (isEventTypeForManagedBuilders(eventType)) { for (final FileBasedConfigurationBuilder<T> b : getManagedBuilders() .values()) { b.removeEventListener(eventType, l); } configurationListeners.removeEventListener(eventType, l); } return result; }
/** * {@inheritDoc} This implementation ensures that the listener is also added * to managed configuration builders if necessary. Listeners for the builder-related * event types are excluded because otherwise they would be triggered by the * internally used configuration builders. */ @Override public synchronized <E extends Event> void addEventListener( final EventType<E> eventType, final EventListener<? super E> l) { super.addEventListener(eventType, l); if (isEventTypeForManagedBuilders(eventType)) { for (final FileBasedConfigurationBuilder<T> b : getManagedBuilders() .values()) { b.addEventListener(eventType, l); } configurationListeners.addEventListener(eventType, l); } }
public T getConfiguration() throws ConfigurationException fireBuilderEvent(new ConfigurationBuilderEvent(this, ConfigurationBuilderEvent.CONFIGURATION_REQUEST)); if (resObj == null) result = resObj = createResult(); created = true; fireBuilderEvent(new ConfigurationBuilderResultCreatedEvent(this, ConfigurationBuilderResultCreatedEvent.RESULT_CREATED, resObj));
/** * {@inheritDoc} This implementation evaluates the {@code result} property * of the definition configuration. It creates a combined bean declaration * with both the properties specified in the definition file and the * properties defined as initialization parameters. */ @Override protected BeanDeclaration createResultDeclaration(final Map<String, Object> params) throws ConfigurationException { final BeanDeclaration paramsDecl = super.createResultDeclaration(params); final XMLBeanDeclaration resultDecl = new XMLBeanDeclaration(getDefinitionConfiguration(), KEY_RESULT, true, CombinedConfiguration.class.getName()); return new CombinedBeanDeclaration(resultDecl, paramsDecl); }
private BasicConfigurationBuilder<? extends Configuration> createConfiguration() { BasicConfigurationBuilder<? extends Configuration> builder; switch (configurationType) { case XML: builder = new FileBasedConfigurationBuilder<>(XMLConfiguration.class); break; case SYSTEM: builder = new BasicConfigurationBuilder<>(SystemConfiguration.class); break; default: builder = new FileBasedConfigurationBuilder<>(PropertiesConfiguration.class); } return builder; }
@Override public Object get(String key) { try { return isOpen() ? config.getConfiguration().getProperty(key) : null; } catch (ConfigurationException exc) { throw new ConfigurationRuntimeException("Failed to get configuration property", exc); } }
@Override public void removeRepositoryListener(TokenRepositoryListener listener) { if (configName == null || !isOpen()) { return; } EventListener<?>[] pListeners = LISTEN_MAP.get(listener); if (pListeners != null) { LISTEN_MAP.remove(listener); config.removeEventListener(ConfigurationEvent.ANY, (TokenConfigurationListener) pListeners[0]); config.removeEventListener(ConfigurationErrorEvent.ANY, (TokenConfigurationErrorListener) pListeners[1]); } }
private void addListenersToOpened() { if (isOpen()) { for (Map.Entry<TokenRepositoryListener, EventListener<?>[]> le : LISTEN_MAP.entrySet()) { EventListener<?>[] pListeners = le.getValue(); if (pListeners != null) { config.addEventListener(ConfigurationEvent.ANY, (TokenConfigurationListener) pListeners[0]); config.addEventListener(ConfigurationErrorEvent.ANY, (TokenConfigurationErrorListener) pListeners[1]); } } } }
@Override public void remove(String key) { if (isOpen()) { try { config.getConfiguration().clearProperty(key); } catch (ConfigurationException exc) { throw new ConfigurationRuntimeException("Failed to remove configuration property", exc); } } }
/** * {@inheritDoc} This method is overridden to adapt the return type. */ @Override public CombinedConfigurationBuilder configure(final BuilderParameters... params) { super.configure(params); return this; }
private void removeListenersFromClosed() { if (isOpen()) { for (Map.Entry<TokenRepositoryListener, EventListener<?>[]> le : LISTEN_MAP.entrySet()) { EventListener<?>[] pListeners = le.getValue(); if (pListeners != null) { config.removeEventListener(ConfigurationEvent.ANY, (TokenConfigurationListener) pListeners[0]); config.removeEventListener(ConfigurationErrorEvent.ANY, (TokenConfigurationErrorListener) pListeners[1]); } } } }
@Override public void addRepositoryListener(TokenRepositoryListener listener) { if (configName == null || !isOpen()) { return; } TokenConfigurationListener cfListener = new TokenConfigurationListener(listener, logger); TokenConfigurationErrorListener cfErrListener = new TokenConfigurationErrorListener(listener, logger); EventListener<?>[] pListeners = new EventListener[2]; pListeners[0] = cfListener; pListeners[1] = cfErrListener; LISTEN_MAP.put(listener, pListeners); config.addEventListener(ConfigurationEvent.ANY, cfListener); config.addEventListener(ConfigurationErrorEvent.ANY, cfErrListener); }
@Override public Iterator<? extends Object> getKeys() { try { return isOpen() ? config.getConfiguration().getKeys() : null; } catch (ConfigurationException exc) { throw new ConfigurationRuntimeException("Failed to get configuration properties key set", exc); } }
/** * {@inheritDoc} This method is overridden here to change the result type. */ @Override public FileBasedConfigurationBuilder<T> configure( final BuilderParameters... params) { super.configure(params); return this; }