| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
| <!-- NewPage --> |
| <html lang="en"> |
| <head> |
| <!-- Generated by javadoc (version 1.7.0_67) on Tue Mar 24 21:21:23 CET 2015 --> |
| <title>Init</title> |
| <meta name="date" content="2015-03-24"> |
| <link rel="stylesheet" type="text/css" href="../../../../../../stylesheet.css" title="Style"> |
| </head> |
| <body> |
| <script type="text/javascript"><!-- |
| if (location.href.indexOf('is-external=true') == -1) { |
| parent.document.title="Init"; |
| } |
| //--> |
| </script> |
| <noscript> |
| <div>JavaScript is disabled on your browser.</div> |
| </noscript> |
| <!-- ========= START OF TOP NAVBAR ======= --> |
| <div class="topNav"><a name="navbar_top"> |
| <!-- --> |
| </a><a href="#skip-navbar_top" title="Skip navigation links"></a><a name="navbar_top_firstrow"> |
| <!-- --> |
| </a> |
| <ul class="navList" title="Navigation"> |
| <li><a href="../../../../../../org/apache/felix/dm/annotation/api/package-summary.html">Package</a></li> |
| <li class="navBarCell1Rev">Class</li> |
| <li><a href="package-tree.html">Tree</a></li> |
| <li><a href="../../../../../../deprecated-list.html">Deprecated</a></li> |
| <li><a href="../../../../../../index-all.html">Index</a></li> |
| <li><a href="../../../../../../help-doc.html">Help</a></li> |
| </ul> |
| </div> |
| <div class="subNav"> |
| <ul class="navList"> |
| <li><a href="../../../../../../org/apache/felix/dm/annotation/api/FactoryConfigurationAdapterService.html" title="annotation in org.apache.felix.dm.annotation.api"><span class="strong">Prev Class</span></a></li> |
| <li><a href="../../../../../../org/apache/felix/dm/annotation/api/Inject.html" title="annotation in org.apache.felix.dm.annotation.api"><span class="strong">Next Class</span></a></li> |
| </ul> |
| <ul class="navList"> |
| <li><a href="../../../../../../index.html?org/apache/felix/dm/annotation/api/Init.html" target="_top">Frames</a></li> |
| <li><a href="Init.html" target="_top">No Frames</a></li> |
| </ul> |
| <ul class="navList" id="allclasses_navbar_top"> |
| <li><a href="../../../../../../allclasses-noframe.html">All Classes</a></li> |
| </ul> |
| <div> |
| <script type="text/javascript"><!-- |
| allClassesLink = document.getElementById("allclasses_navbar_top"); |
| if(window==top) { |
| allClassesLink.style.display = "block"; |
| } |
| else { |
| allClassesLink.style.display = "none"; |
| } |
| //--> |
| </script> |
| </div> |
| <div> |
| <ul class="subNavList"> |
| <li>Summary: </li> |
| <li>Required | </li> |
| <li>Optional</li> |
| </ul> |
| <ul class="subNavList"> |
| <li>Detail: </li> |
| <li>Element</li> |
| </ul> |
| </div> |
| <a name="skip-navbar_top"> |
| <!-- --> |
| </a></div> |
| <!-- ========= END OF TOP NAVBAR ========= --> |
| <!-- ======== START OF CLASS DATA ======== --> |
| <div class="header"> |
| <div class="subTitle">org.apache.felix.dm.annotation.api</div> |
| <h2 title="Annotation Type Init" class="title">Annotation Type Init</h2> |
| </div> |
| <div class="contentContainer"> |
| <div class="description"> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <hr> |
| <br> |
| <pre>@Retention(value=CLASS) |
| @Target(value=METHOD) |
| public @interface <span class="strong">Init</span></pre> |
| <div class="block">Annotates a method used to configure dynamic dependencies. |
| When this method is invoked, all required dependencies (except the ones declared with a <code>name</code> |
| attribute) are already injected, and optional dependencies on class fields |
| are also already injected (possibly with NullObjects).<p> |
| |
| 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 <code>name</code> 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. |
| |
| <h3>Usage Examples</h3> |
| In this sample, the "PersistenceImpl" component dynamically configures the "storage" dependency from the "init" method. |
| The dependency "required" flag and filter string are derived from an xml configuration that is already injected before the init |
| method. |
| |
| <blockquote> |
| <pre> |
| |
| @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 |
| Map<String, String> init() { |
| log.log(LogService.LOG_WARNING, "init: storage type=" + storageType + ", storageRequired=" + storageRequired); |
| Map<String, String> 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"); |
| }</div> |
| </li> |
| </ul> |
| </div> |
| </div> |
| <!-- ========= END OF CLASS DATA ========= --> |
| <!-- ======= START OF BOTTOM NAVBAR ====== --> |
| <div class="bottomNav"><a name="navbar_bottom"> |
| <!-- --> |
| </a><a href="#skip-navbar_bottom" title="Skip navigation links"></a><a name="navbar_bottom_firstrow"> |
| <!-- --> |
| </a> |
| <ul class="navList" title="Navigation"> |
| <li><a href="../../../../../../org/apache/felix/dm/annotation/api/package-summary.html">Package</a></li> |
| <li class="navBarCell1Rev">Class</li> |
| <li><a href="package-tree.html">Tree</a></li> |
| <li><a href="../../../../../../deprecated-list.html">Deprecated</a></li> |
| <li><a href="../../../../../../index-all.html">Index</a></li> |
| <li><a href="../../../../../../help-doc.html">Help</a></li> |
| </ul> |
| </div> |
| <div class="subNav"> |
| <ul class="navList"> |
| <li><a href="../../../../../../org/apache/felix/dm/annotation/api/FactoryConfigurationAdapterService.html" title="annotation in org.apache.felix.dm.annotation.api"><span class="strong">Prev Class</span></a></li> |
| <li><a href="../../../../../../org/apache/felix/dm/annotation/api/Inject.html" title="annotation in org.apache.felix.dm.annotation.api"><span class="strong">Next Class</span></a></li> |
| </ul> |
| <ul class="navList"> |
| <li><a href="../../../../../../index.html?org/apache/felix/dm/annotation/api/Init.html" target="_top">Frames</a></li> |
| <li><a href="Init.html" target="_top">No Frames</a></li> |
| </ul> |
| <ul class="navList" id="allclasses_navbar_bottom"> |
| <li><a href="../../../../../../allclasses-noframe.html">All Classes</a></li> |
| </ul> |
| <div> |
| <script type="text/javascript"><!-- |
| allClassesLink = document.getElementById("allclasses_navbar_bottom"); |
| if(window==top) { |
| allClassesLink.style.display = "block"; |
| } |
| else { |
| allClassesLink.style.display = "none"; |
| } |
| //--> |
| </script> |
| </div> |
| <div> |
| <ul class="subNavList"> |
| <li>Summary: </li> |
| <li>Required | </li> |
| <li>Optional</li> |
| </ul> |
| <ul class="subNavList"> |
| <li>Detail: </li> |
| <li>Element</li> |
| </ul> |
| </div> |
| <a name="skip-navbar_bottom"> |
| <!-- --> |
| </a></div> |
| <!-- ======== END OF BOTTOM NAVBAR ======= --> |
| </body> |
| </html> |