| 1 | /* |
| 2 | * Copyright (c) 2012-2015, Luigi R. Viggiano |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * This software is distributable under the BSD license. |
| 6 | * See the terms of the BSD license in the documentation provided with this software. |
| 7 | */ |
| 8 | |
| 9 | package org.aeonbits.owner; |
| 10 | |
| 11 | import org.aeonbits.owner.loaders.Loader; |
| 12 | |
| 13 | import java.util.Map; |
| 14 | import java.util.Properties; |
| 15 | |
| 16 | /** |
| 17 | * Interface for factory implementation used to instantiate {@link Config} instances. |
| 18 | * |
| 19 | * @author Luigi R. Viggiano |
| 20 | * @since 1.0.5 |
| 21 | */ |
| 22 | public interface Factory { |
| 23 | |
| 24 | /** |
| 25 | * Creates a {@link Config} instance from the specified interface |
| 26 | * |
| 27 | * @param clazz the interface extending from {@link Config} that you want to instantiate. |
| 28 | * @param imports additional variables to be used to resolve the properties. |
| 29 | * @param <T> type of the interface. |
| 30 | * @return an object implementing the given interface, which maps methods to property values. |
| 31 | * @since 1.0.5 |
| 32 | */ |
| 33 | <T extends Config> T create(Class<? extends T> clazz, Map<?, ?>... imports); |
| 34 | |
| 35 | /** |
| 36 | * Returns the value for a given property. |
| 37 | * |
| 38 | * @param key the key for the property |
| 39 | * @return the value for the property, or <code>null</code> if the property is not set. |
| 40 | * @since 1.0.5 |
| 41 | */ |
| 42 | String getProperty(String key); |
| 43 | |
| 44 | /** |
| 45 | * Set a property in the ConfigFactory. Those properties will be used to expand variables specified in the `@Source` |
| 46 | * annotation, or by the ConfigFactory to configure its own behavior. |
| 47 | * |
| 48 | * @param key the key for the property. |
| 49 | * @param value the value for the property. |
| 50 | * @return the old value. |
| 51 | * @since 1.0.5 |
| 52 | */ |
| 53 | String setProperty(String key, String value); |
| 54 | |
| 55 | /** |
| 56 | * Clears the value for the property having the given key. This means, that the given property is removed. |
| 57 | * |
| 58 | * @param key the key for the property to remove. |
| 59 | * @return the old value for the given key, or <code>null</code> if the property was not set. |
| 60 | * @since 1.0.5 |
| 61 | */ |
| 62 | String clearProperty(String key); |
| 63 | |
| 64 | /** |
| 65 | * Those properties will be used to expand variables specified in the `@Source` annotation, or by the ConfigFactory |
| 66 | * to configure its own behavior. |
| 67 | * |
| 68 | * @return the properties in the ConfigFactory |
| 69 | * @since 1.0.5 |
| 70 | */ |
| 71 | Properties getProperties(); |
| 72 | |
| 73 | /** |
| 74 | * Those properties will be used to expand variables specified in the `@Source` annotation, or by the ConfigFactory |
| 75 | * to configure its own behavior. |
| 76 | * |
| 77 | * @param properties the properties to set in the config Factory. |
| 78 | * @since 1.0.5 |
| 79 | */ |
| 80 | void setProperties(Properties properties); |
| 81 | |
| 82 | /** |
| 83 | * Registers a loader to enables additional file formats. |
| 84 | * |
| 85 | * @param loader the loader to register. |
| 86 | * @throws NullPointerException if specified loader is <code>null</code>. |
| 87 | * @since 1.0.5 |
| 88 | */ |
| 89 | void registerLoader(Loader loader); |
| 90 | |
| 91 | /** |
| 92 | * Sets a converter for the given type. Setting a converter via this method will override any default converters |
| 93 | * but not {@link Config.ConverterClass} annotations. |
| 94 | * |
| 95 | * @param type the type for which to set a converter. |
| 96 | * @param converter the converter class to use for the specified type. |
| 97 | * @since 1.0.10 |
| 98 | */ |
| 99 | void setTypeConverter(Class<?> type, Class<? extends Converter<?>> converter); |
| 100 | |
| 101 | /** |
| 102 | * Removes a converter for the given type. |
| 103 | * @param type the type for which to remove the converter. |
| 104 | * @since 1.0.10 |
| 105 | */ |
| 106 | void removeTypeConverter(Class<?> type); |
| 107 | } |