/** * Merges this object with the given parameters object. This method adds all * property values defined by the passed in parameters object to the * internal storage which are not already in. So properties already defined * in this object take precedence. Property names starting with the reserved * parameter prefix are ignored. * * @param p the object whose properties should be merged (must not be * <b>null</b>) * @throws IllegalArgumentException if the passed in object is <b>null</b> */ public void merge(final BuilderParameters p) { if (p == null) { throw new IllegalArgumentException( "Parameters to merge must not be null!"); } for (final Map.Entry<String, Object> e : p.getParameters().entrySet()) { if (!properties.containsKey(e.getKey()) && !e.getKey().startsWith(RESERVED_PARAMETER_PREFIX)) { storeProperty(e.getKey(), e.getValue()); } } }
/** * Appends the content of the specified {@code BuilderParameters} objects to * the current initialization parameters. Calling this method multiple times * will create a union of the parameters provided. * * @param params an arbitrary number of objects with builder parameters * @return a reference to this builder for method chaining * @throws NullPointerException if a <b>null</b> array is passed */ public BasicConfigurationBuilder<T> configure(final BuilderParameters... params) { final Map<String, Object> newParams = new HashMap<>(); for (final BuilderParameters p : params) { newParams.putAll(p.getParameters()); handleEventListenerProviders(p); } return setParameters(newParams); }
/** * Creates a map with parameters for a new managed configuration builder. * This method merges the basic parameters set for this builder with the * specific parameters object for managed builders (if provided). * * @param params the parameters of this builder * @param multiParams the parameters object for this builder * @return the parameters for a new managed builder */ private static Map<String, Object> createManagedBuilderParameters( final Map<String, Object> params, final MultiFileBuilderParametersImpl multiParams) { final Map<String, Object> newParams = new HashMap<>(params); newParams.remove(KEY_INTERPOLATOR); final BuilderParameters managedBuilderParameters = multiParams.getManagedBuilderParameters(); if (managedBuilderParameters != null) { // clone parameters as they are applied to multiple builders final BuilderParameters copy = (BuilderParameters) ConfigurationUtils .cloneIfPossible(managedBuilderParameters); newParams.putAll(copy.getParameters()); } return newParams; }
/** * {@inheritDoc} This implementation uses * {@code PropertyUtils.copyProperties()} to copy all defined properties * from the source object onto the passed in parameters object. Both the map * with properties (obtained via the {@code getParameters()} method of the * source parameters object) and other properties of the source object are * copied. * * @throws ConfigurationRuntimeException if an exception occurs * @see BuilderParameters#getParameters() */ @Override public void initializeDefaults(final Object parameters) { try { BeanHelper.copyProperties(parameters, getSource() .getParameters()); BeanHelper.copyProperties(parameters, getSource()); } catch (final Exception e) { // Handle all reflection-related exceptions the same way throw new ConfigurationRuntimeException(e); } } }