/** * Obtains the {@code FileHandler} from this builder's parameters. If no * {@code FileBasedBuilderParametersImpl} object is found in this builder's * parameters, a new one is created now and stored. This makes it possible * to change the location of the associated file even if no parameters * object was provided. * * @return the {@code FileHandler} from initialization parameters */ private FileHandler fetchFileHandlerFromParameters() { FileBasedBuilderParametersImpl fileParams = FileBasedBuilderParametersImpl.fromParameters(getParameters(), false); if (fileParams == null) { fileParams = new FileBasedBuilderParametersImpl(); addParameters(fileParams.getParameters()); } return fileParams.getFileHandler(); }
/** * {@inheritDoc} This implementation takes some properties defined in this * class into account. */ @Override public void inheritFrom(final Map<String, ?> source) { super.inheritFrom(source); final FileBasedBuilderParametersImpl srcParams = fromParameters(source); if (srcParams != null) { setFileSystem(srcParams.getFileHandler().getFileSystem()); setLocationStrategy( srcParams.getFileHandler().getLocationStrategy()); if (srcParams.getFileHandler().getEncoding() != null) { setEncoding(srcParams.getFileHandler().getEncoding()); } if (srcParams.getReloadingDetectorFactory() != null) { setReloadingDetectorFactory( srcParams.getReloadingDetectorFactory()); } if (srcParams.getReloadingRefreshDelay() != null) { setReloadingRefreshDelay(srcParams.getReloadingRefreshDelay()); } } }
/** * {@inheritDoc} This implementation copies some more properties defined by * this class. */ @Override public void inheritFrom(final Map<String, ?> source) { super.inheritFrom(source); copyPropertiesFrom(source, PROP_EXPRESSION_ENGINE); }
/** * Creates a new {@code FileBasedBuilderParametersImpl} object from the * content of the given map. While {@code fromParameters()} expects that an * object already exists and is stored in the given map, this method creates * a new instance based on the content of the map. The map can contain * properties of a {@code FileHandler} and some additional settings which * are stored directly in the newly created object. If the map is * <b>null</b>, an uninitialized instance is returned. * * @param map the map with properties (must not be <b>null</b>) * @return the newly created instance * @throws ClassCastException if the map contains invalid data */ public static FileBasedBuilderParametersImpl fromMap(final Map<String, ?> map) { final FileBasedBuilderParametersImpl params = new FileBasedBuilderParametersImpl(FileHandler.fromMap(map)); if (map != null) { params.setReloadingRefreshDelay((Long) map.get(PROP_REFRESH_DELAY)); params.setReloadingDetectorFactory((ReloadingDetectorFactory) map .get(PROP_DETECTOR_FACTORY)); } return params; }
@Override public FileBasedBuilderParametersImpl setFile(final File file) { getFileHandler().setFile(file); return this; }
/** * Looks up an instance of this class in the specified parameters map. This * is equivalent to {@code fromParameters(params, false};} * * @param params the map with parameters (must not be <b>null</b> * @return the instance obtained from the map or <b>null</b> * @throws IllegalArgumentException if the map is <b>null</b> */ public static FileBasedBuilderParametersImpl fromParameters( final Map<String, ?> params) { return fromParameters(params, false); }
/** * Creates a new instance of a parameters object for file-based * configuration properties. * * @return the new parameters object */ public FileBasedBuilderParameters fileBased() { return createParametersProxy(new FileBasedBuilderParametersImpl(), FileBasedBuilderParameters.class); }
/** * Returns a {@code ReloadingDetectorFactory} either from the passed in * parameters or a default factory. * * @param params the current parameters object * @return the {@code ReloadingDetectorFactory} to be used */ private static ReloadingDetectorFactory fetchDetectorFactory( final FileBasedBuilderParametersImpl params) { final ReloadingDetectorFactory factory = params.getReloadingDetectorFactory(); return (factory != null) ? factory : DEFAULT_DETECTOR_FACTORY; } }
@Override public ReloadingDetector createReloadingDetector(final FileHandler handler, final FileBasedBuilderParametersImpl params) throws ConfigurationException { final Long refreshDelay = params.getReloadingRefreshDelay(); final FileHandlerReloadingDetector fileHandlerReloadingDetector = (refreshDelay != null) ? new FileHandlerReloadingDetector( handler, refreshDelay) : new FileHandlerReloadingDetector( handler); fileHandlerReloadingDetector.refresh(); return fileHandlerReloadingDetector; } }
@Override public FileBasedBuilderParametersImpl setBasePath(final String path) { getFileHandler().setBasePath(path); return this; }
/** * {@inheritDoc} This implementation also takes care that a new * {@code ReloadingDetector} for the new current {@code FileHandler} is * created. Also, the reloading controller's reloading state has to be * reset; after the creation of a new result object changes in the * underlying configuration source have to be monitored again. */ @Override protected void initFileHandler(final FileHandler handler) throws ConfigurationException { super.initFileHandler(handler); resultReloadingDetector = createReloadingDetector(handler, FileBasedBuilderParametersImpl.fromParameters( getParameters(), true)); }
/** * Looks up an instance of this class in the specified parameters map and * optionally creates a new one if none is found. This method can be used to * obtain an instance of this class which has been stored in a parameters * map. It is compatible with the {@code getParameters()} method. * * @param params the map with parameters (must not be <b>null</b> * @param createIfMissing determines the behavior if no instance is found in * the map; if <b>true</b>, a new instance with default settings is * created; if <b>false</b>, <b>null</b> is returned * @return the instance obtained from the map or <b>null</b> * @throws IllegalArgumentException if the map is <b>null</b> */ public static FileBasedBuilderParametersImpl fromParameters( final Map<String, ?> params, final boolean createIfMissing) { if (params == null) { throw new IllegalArgumentException( "Parameters map must not be null!"); } FileBasedBuilderParametersImpl instance = (FileBasedBuilderParametersImpl) params.get(PARAM_KEY); if (instance == null && createIfMissing) { instance = new FileBasedBuilderParametersImpl(); } return instance; }
@Override public FileBasedBuilderParametersImpl setFileSystem(final FileSystem fs) { getFileHandler().setFileSystem(fs); return this; }
FileBasedBuilderParametersImpl.fromParameters(params); if (fileParams != null)
/** * {@inheritDoc} This implementation takes some more properties into account * that are defined in this class. */ @Override public void inheritFrom(final Map<String, ?> source) { super.inheritFrom(source); copyPropertiesFrom(source, PROP_INCLUDES_ALLOWED, PROP_IO_FACTORY); }
@Override public FileBasedBuilderParametersImpl setURL(final URL url) { getFileHandler().setURL(url); return this; }
@Override public FileBasedBuilderParametersImpl setFileName(final String name) { getFileHandler().setFileName(name); return this; }
@Override public FileBasedBuilderParametersImpl setLocationStrategy( final FileLocationStrategy strategy) { getFileHandler().setLocationStrategy(strategy); return this; }
@Override public FileBasedBuilderParametersImpl setPath(final String path) { getFileHandler().setPath(path); return this; }
@Override public FileBasedBuilderParametersImpl setEncoding(final String enc) { getFileHandler().setEncoding(enc); return this; }