/** * Creates a new instance of a parameters object for basic configuration * properties. * * @return the new parameters object */ public BasicBuilderParameters basic() { return new BasicBuilderParameters(); }
/** * Obtains the {@code BeanHelper} object from the specified map with * parameters. This method can be used to obtain an instance from a * parameters map that has been set via the {@code setBeanHelper()} method. * If no such instance is found, result is <b>null</b>. * * @param params the map with parameters (must not be <b>null</b>) * @return the {@code BeanHelper} stored in this map or <b>null</b> * @throws IllegalArgumentException if the map is <b>null</b> */ public static BeanHelper fetchBeanHelper(final Map<String, Object> params) { checkParameters(params); return (BeanHelper) params.get(PROP_BEAN_HELPER); }
/** * Inherits properties from the specified map. This can be used for instance * to reuse parameters from one builder in another builder - also in * parent-child relations in which a parent builder creates child builders. * The purpose of this method is to let a concrete implementation decide * which properties can be inherited. Because parameters are basically * organized as a map it would be possible to simply copy over all * properties from the source object. However, this is not appropriate in * all cases. For instance, some properties - like a * {@code ConfigurationInterpolator} - are tightly connected to a * configuration and cannot be reused in a different context. For other * properties, e.g. a file name, it does not make sense to copy it. * Therefore, an implementation has to be explicit in the properties it * wants to take over. * * @param source the source properties to inherit from * @throws IllegalArgumentException if the source map is <b>null</b> */ public void inheritFrom(final Map<String, ?> source) { if (source == null) { throw new IllegalArgumentException( "Source properties must not be null!"); } copyPropertiesFrom(source, PROP_BEAN_HELPER, PROP_CONFIGURATION_DECODER, PROP_CONVERSION_HANDLER, PROP_LIST_DELIMITER_HANDLER, PROP_LOGGER, PROP_SYNCHRONIZER, PROP_THROW_EXCEPTION_ON_MISSING); }
/** * Tests whether the passed in map with parameters contains a valid * collection with default lookups. This method works like * {@link #fetchAndCheckPrefixLookups(Map)}, but tests the default lookups * collection. * * @param params the map with parameters * @return the collection with default lookups (may be <b>null</b>) * @throws IllegalArgumentException if invalid data is found */ private static Collection<? extends Lookup> fetchAndCheckDefaultLookups( final Map<String, Object> params) { final Collection<?> col = fetchParameter(params, PROP_DEFAULT_LOOKUPS, Collection.class); if (col == null) { return null; } for (final Object o : col) { if (!(o instanceof Lookup)) { throw new IllegalArgumentException( "Collection with default lookups contains invalid data: " + col); } } return fetchDefaultLookups(params); }
/** * Creates defensive copies for collection structures when constructing the * map with parameters. It should not be possible to modify this object's * internal state when having access to the parameters map. * * @param params the map with parameters to be passed to the caller */ private static void createDefensiveCopies(final HashMap<String, Object> params) { final Map<String, ? extends Lookup> prefixLookups = fetchPrefixLookups(params); if (prefixLookups != null) { params.put(PROP_PREFIX_LOOKUPS, new HashMap<>( prefixLookups)); } final Collection<? extends Lookup> defLookups = fetchDefaultLookups(params); if (defLookups != null) { params.put(PROP_DEFAULT_LOOKUPS, new ArrayList<>(defLookups)); } }
/** * Obtains a specification for a {@link ConfigurationInterpolator} from the * specified map with parameters. All properties related to interpolation * are evaluated and added to the specification object. * * @param params the map with parameters (must not be <b>null</b>) * @return an {@code InterpolatorSpecification} object constructed with data * from the map * @throws IllegalArgumentException if the map is <b>null</b> or contains * invalid data */ public static InterpolatorSpecification fetchInterpolatorSpecification( final Map<String, Object> params) { checkParameters(params); return new InterpolatorSpecification.Builder() .withInterpolator( fetchParameter(params, PROP_INTERPOLATOR, ConfigurationInterpolator.class)) .withParentInterpolator( fetchParameter(params, PROP_PARENT_INTERPOLATOR, ConfigurationInterpolator.class)) .withPrefixLookups(fetchAndCheckPrefixLookups(params)) .withDefaultLookups(fetchAndCheckDefaultLookups(params)) .create(); }
/** * {@inheritDoc} This implementation also creates a copy of the * {@code FileHandler}. */ @Override public FileBasedBuilderParametersImpl clone() { final FileBasedBuilderParametersImpl copy = (FileBasedBuilderParametersImpl) super.clone(); copy.fileHandler = new FileHandler(fileHandler.getContent(), fileHandler); return copy; } }
/** * Obtains the {@code BeanHelper} object to be used when dealing with bean * declarations. This method checks whether this builder was configured with * a specific {@code BeanHelper} instance. If so, this instance is used. * Otherwise, the default {@code BeanHelper} is returned. * * @return the {@code BeanHelper} to be used */ protected final BeanHelper fetchBeanHelper() { final BeanHelper helper = BasicBuilderParameters.fetchBeanHelper(getParameters()); return (helper != null) ? helper : BeanHelper.INSTANCE; }
/** * {@inheritDoc} This implementation returns a copy of the internal * parameters map with the values set so far. Collection structures * (e.g. for lookup objects) are stored as defensive copies, so the * original data cannot be modified. */ @Override public Map<String, Object> getParameters() { final HashMap<String, Object> result = new HashMap<>(properties); if (result.containsKey(PROP_INTERPOLATOR)) { // A custom ConfigurationInterpolator overrides lookups result.remove(PROP_PREFIX_LOOKUPS); result.remove(PROP_DEFAULT_LOOKUPS); result.remove(PROP_PARENT_INTERPOLATOR); } createDefensiveCopies(result); return result; }
/** * Creates the {@code ConfigurationInterpolator} to be used by this * instance. This method is called when a file name is to be constructed, * but no current {@code ConfigurationInterpolator} instance is available. * It obtains an instance from this builder's parameters. If no properties * of the {@code ConfigurationInterpolator} are specified in the parameters, * a default instance without lookups is returned (which is probably not * very helpful). * * @return the {@code ConfigurationInterpolator} to be used */ protected ConfigurationInterpolator createInterpolator() { final InterpolatorSpecification spec = BasicBuilderParameters .fetchInterpolatorSpecification(getParameters()); return ConfigurationInterpolator.fromSpecification(spec); }
/** * {@inheritDoc} This implementation also clones the parameters object for * the definition builder if possible. */ @Override public CombinedBuilderParametersImpl clone() { final CombinedBuilderParametersImpl copy = (CombinedBuilderParametersImpl) super.clone(); copy.setDefinitionBuilderParameters((BuilderParameters) ConfigurationUtils .cloneIfPossible(getDefinitionBuilderParameters())); return copy; } }
/** * {@inheritDoc} This implementation also tries to clone the parameters * object for managed builders if possible. */ @Override public MultiFileBuilderParametersImpl clone() { final MultiFileBuilderParametersImpl copy = (MultiFileBuilderParametersImpl) super.clone(); copy.setManagedBuilderParameters((BuilderParameters) ConfigurationUtils .cloneIfPossible(getManagedBuilderParameters())); return copy; } }