@Retention(value=CLASS)
@Target(value=METHOD)
public @interface Init
name
attribute) are already injected, and optional dependencies on class fields
are also already injected (possibly with NullObjects).
The purpose of the @Init method is to either declare more dynamic dependencies using the DM API, or to
return a Map used to dynamically configure dependencies that are annotated using a name
attribute.
After the init method returns, the added or configured dependencies are then tracked, and when all dynamic
dependencies are injected, then the start method (annotated with @Start) is then invoked.
@Component public class PersistenceImpl implements Persistence { // Injected before init. @ServiceDependency LogService log; // Injected before init. @ConfigurationDependency void updated(Dictionary conf) { if (conf != null) { _xmlConfiguration = parseXmlConfiguration(conf.get("xmlConfiguration")); } } // Parsed xml configuration, where we'll get our storage service filter and required dependency flag. XmlConfiguration _xmlConfiguration; // Injected after init (dependency filter is defined dynamically from our init method). @ServiceDependency(name="storage") Storage storage; // Dynamically configure the dependency declared with a "storage" name. @Init Mapinit() { log.log(LogService.LOG_WARNING, "init: storage type=" + storageType + ", storageRequired=" + storageRequired); Map props = new HashMap<>(); props.put("storage.required", Boolean.toString(_xmlConfiguration.isStorageRequired())) props.put("storage.filter", "(type=" + _xmlConfiguration.getStorageType() + ")"); return props; } // All dependencies injected, including dynamic dependencies defined from init method. @Start void start() { log.log(LogService.LOG_WARNING, "start"); }