| <!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 (1.8.0_74) on Wed Feb 24 01:07:22 CET 2016 --> |
| <title>ResourceDependency</title> |
| <meta name="date" content="2016-02-24"> |
| <link rel="stylesheet" type="text/css" href="../../../../../../stylesheet.css" title="Style"> |
| <script type="text/javascript" src="../../../../../../script.js"></script> |
| </head> |
| <body> |
| <script type="text/javascript"><!-- |
| try { |
| if (location.href.indexOf('is-external=true') == -1) { |
| parent.document.title="ResourceDependency"; |
| } |
| } |
| catch(err) { |
| } |
| //--> |
| </script> |
| <noscript> |
| <div>JavaScript is disabled on your browser.</div> |
| </noscript> |
| <!-- ========= START OF TOP NAVBAR ======= --> |
| <div class="topNav"><a name="navbar.top"> |
| <!-- --> |
| </a> |
| <div class="skipNav"><a href="#skip.navbar.top" title="Skip navigation links">Skip navigation links</a></div> |
| <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/ResourceAdapterService.html" title="annotation in org.apache.felix.dm.annotation.api"><span class="typeNameLink">Prev Class</span></a></li> |
| <li><a href="../../../../../../org/apache/felix/dm/annotation/api/ServiceDependency.html" title="annotation in org.apache.felix.dm.annotation.api"><span class="typeNameLink">Next Class</span></a></li> |
| </ul> |
| <ul class="navList"> |
| <li><a href="../../../../../../index.html?org/apache/felix/dm/annotation/api/ResourceDependency.html" target="_top">Frames</a></li> |
| <li><a href="ResourceDependency.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>Field | </li> |
| <li>Required | </li> |
| <li><a href="#annotation.type.optional.element.summary">Optional</a></li> |
| </ul> |
| <ul class="subNavList"> |
| <li>Detail: </li> |
| <li>Field | </li> |
| <li><a href="#annotation.type.element.detail">Element</a></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 ResourceDependency" class="title">Annotation Type ResourceDependency</h2> |
| </div> |
| <div class="contentContainer"> |
| <div class="description"> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <hr> |
| <br> |
| <pre>@Retention(value=CLASS) |
| @Target(value={METHOD,FIELD}) |
| public @interface <span class="memberNameLabel">ResourceDependency</span></pre> |
| <div class="block">Annotates a method of field as a Resource Dependency. A resource dependency allows you to |
| depend on a resource. Resources are an abstraction that is introduced by the dependency manager, represented as a URL. |
| They can be implemented to serve resources embedded in bundles, somewhere on a file system or in |
| an http content repository server, or database. <p> A resource is a URL and you can use a filter condition based on |
| protocol, host, port, and path. |
| |
| <h3>Usage Examples</h3> |
| Here, the "VideoPlayer" component plays any provided MKV video resources |
| <blockquote> |
| <pre> |
| |
| @Component |
| public class VideoPlayer { |
| @ResourceDependency(required=false, filter="(path=/videos/*.mkv)") |
| void playResource(URL video) { ... } |
| } |
| </pre> |
| </blockquote> |
| |
| And here is an example of a VideoProvider, which provides some videos using a web URL. |
| Notice that Resource providers need to depend on the DependencyManager API: |
| |
| <blockquote> |
| <pre> |
| import java.net.MalformedURLException; |
| import java.net.URL; |
| import java.util.HashMap; |
| import java.util.Map; |
| |
| import org.apache.felix.dm.ResourceHandler; |
| import org.apache.felix.dm.ResourceUtil; |
| import org.apache.felix.dm.annotation.api.Component; |
| import org.apache.felix.dm.annotation.api.Init; |
| import org.apache.felix.dm.annotation.api.ServiceDependency; |
| import org.osgi.framework.BundleContext; |
| import org.osgi.framework.Filter; |
| import org.osgi.framework.InvalidSyntaxException; |
| |
| @Component |
| public class VideoProvider |
| { |
| // Injected by reflection |
| private volatile BundleContext context; |
| // List of known resource handlers |
| private Map<ResourceHandler, Filter> m_handlers = new HashMap<ResourceHandler, Filter>(); |
| // List of known video resources |
| private URL[] m_videos; |
| |
| @Init |
| void init() throws MalformedURLException |
| { |
| m_videos = new URL[] { |
| new URL("http://localhost:8080/videos/video1.mkv"), |
| new URL("http://localhost:8080/videos/video2.mkv"), |
| }; |
| } |
| |
| // Track resource handlers |
| @ServiceDependency(required = false) |
| public void add(Map<String, String> serviceProperties, ResourceHandler handler) throws InvalidSyntaxException |
| { |
| String filterString = serviceProperties.get("filter"); |
| filterString = (filterString != null) ? filterString : "(path=*)"; |
| Filter filter = context.createFilter(filterString); |
| synchronized (this) |
| { |
| m_handlers.put(handler, filter); |
| } |
| for (URL video : m_videos) |
| { |
| if (filter.match(ResourceUtil.createProperties(video))) |
| { |
| handler.added(video); |
| } |
| } |
| } |
| } |
| </pre> |
| </blockquote></div> |
| </li> |
| </ul> |
| </div> |
| <div class="summary"> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <!-- =========== ANNOTATION TYPE OPTIONAL MEMBER SUMMARY =========== --> |
| <ul class="blockList"> |
| <li class="blockList"><a name="annotation.type.optional.element.summary"> |
| <!-- --> |
| </a> |
| <h3>Optional Element Summary</h3> |
| <table class="memberSummary" border="0" cellpadding="3" cellspacing="0" summary="Optional Element Summary table, listing optional elements, and an explanation"> |
| <caption><span>Optional Elements</span><span class="tabEnd"> </span></caption> |
| <tr> |
| <th class="colFirst" scope="col">Modifier and Type</th> |
| <th class="colLast" scope="col">Optional Element and Description</th> |
| </tr> |
| <tr class="altColor"> |
| <td class="colFirst"><code>java.lang.String</code></td> |
| <td class="colLast"><code><span class="memberNameLink"><a href="../../../../../../org/apache/felix/dm/annotation/api/ResourceDependency.html#added--">added</a></span></code> |
| <div class="block">Returns the callback method to be invoked when the service is available.</div> |
| </td> |
| </tr> |
| <tr class="rowColor"> |
| <td class="colFirst"><code>java.lang.String</code></td> |
| <td class="colLast"><code><span class="memberNameLink"><a href="../../../../../../org/apache/felix/dm/annotation/api/ResourceDependency.html#changed--">changed</a></span></code> |
| <div class="block">Returns the callback method to be invoked when the service properties have changed.</div> |
| </td> |
| </tr> |
| <tr class="altColor"> |
| <td class="colFirst"><code>java.lang.String</code></td> |
| <td class="colLast"><code><span class="memberNameLink"><a href="../../../../../../org/apache/felix/dm/annotation/api/ResourceDependency.html#filter--">filter</a></span></code> |
| <div class="block">Returns the Service dependency OSGi filter.</div> |
| </td> |
| </tr> |
| <tr class="rowColor"> |
| <td class="colFirst"><code>java.lang.String</code></td> |
| <td class="colLast"><code><span class="memberNameLink"><a href="../../../../../../org/apache/felix/dm/annotation/api/ResourceDependency.html#name--">name</a></span></code> |
| <div class="block">The name used when dynamically configuring this dependency from the init method.</div> |
| </td> |
| </tr> |
| <tr class="altColor"> |
| <td class="colFirst"><code>boolean</code></td> |
| <td class="colLast"><code><span class="memberNameLink"><a href="../../../../../../org/apache/felix/dm/annotation/api/ResourceDependency.html#propagate--">propagate</a></span></code> |
| <div class="block">Specifies if the resource URL properties must be propagated.</div> |
| </td> |
| </tr> |
| <tr class="rowColor"> |
| <td class="colFirst"><code>java.lang.String</code></td> |
| <td class="colLast"><code><span class="memberNameLink"><a href="../../../../../../org/apache/felix/dm/annotation/api/ResourceDependency.html#removed--">removed</a></span></code> |
| <div class="block">Returns the callback method to invoke when the service is lost.</div> |
| </td> |
| </tr> |
| <tr class="altColor"> |
| <td class="colFirst"><code>boolean</code></td> |
| <td class="colLast"><code><span class="memberNameLink"><a href="../../../../../../org/apache/felix/dm/annotation/api/ResourceDependency.html#required--">required</a></span></code> |
| <div class="block">Returns whether the Service dependency is required or not.</div> |
| </td> |
| </tr> |
| </table> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| </div> |
| <div class="details"> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <!-- ============ ANNOTATION TYPE MEMBER DETAIL =========== --> |
| <ul class="blockList"> |
| <li class="blockList"><a name="annotation.type.element.detail"> |
| <!-- --> |
| </a> |
| <h3>Element Detail</h3> |
| <a name="added--"> |
| <!-- --> |
| </a> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <h4>added</h4> |
| <pre>public abstract java.lang.String added</pre> |
| <div class="block">Returns the callback method to be invoked when the service is available. This attribute is only meaningful when |
| the annotation is applied on a class field.</div> |
| <dl> |
| <dt><span class="returnLabel">Returns:</span></dt> |
| <dd>the add callback</dd> |
| </dl> |
| <dl> |
| <dt>Default:</dt> |
| <dd>""</dd> |
| </dl> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| <ul class="blockList"> |
| <li class="blockList"><a name="changed--"> |
| <!-- --> |
| </a> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <h4>changed</h4> |
| <pre>public abstract java.lang.String changed</pre> |
| <div class="block">Returns the callback method to be invoked when the service properties have changed.</div> |
| <dl> |
| <dt><span class="returnLabel">Returns:</span></dt> |
| <dd>the change callback</dd> |
| </dl> |
| <dl> |
| <dt>Default:</dt> |
| <dd>""</dd> |
| </dl> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| <ul class="blockList"> |
| <li class="blockList"><a name="removed--"> |
| <!-- --> |
| </a> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <h4>removed</h4> |
| <pre>public abstract java.lang.String removed</pre> |
| <div class="block">Returns the callback method to invoke when the service is lost.</div> |
| <dl> |
| <dt><span class="returnLabel">Returns:</span></dt> |
| <dd>the remove callback</dd> |
| </dl> |
| <dl> |
| <dt>Default:</dt> |
| <dd>""</dd> |
| </dl> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| <ul class="blockList"> |
| <li class="blockList"><a name="required--"> |
| <!-- --> |
| </a> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <h4>required</h4> |
| <pre>public abstract boolean required</pre> |
| <div class="block">Returns whether the Service dependency is required or not.</div> |
| <dl> |
| <dt><span class="returnLabel">Returns:</span></dt> |
| <dd>the required flag</dd> |
| </dl> |
| <dl> |
| <dt>Default:</dt> |
| <dd>true</dd> |
| </dl> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| <ul class="blockList"> |
| <li class="blockList"><a name="filter--"> |
| <!-- --> |
| </a> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <h4>filter</h4> |
| <pre>public abstract java.lang.String filter</pre> |
| <div class="block">Returns the Service dependency OSGi filter.</div> |
| <dl> |
| <dt><span class="returnLabel">Returns:</span></dt> |
| <dd>the filter</dd> |
| </dl> |
| <dl> |
| <dt>Default:</dt> |
| <dd>""</dd> |
| </dl> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| <ul class="blockList"> |
| <li class="blockList"><a name="propagate--"> |
| <!-- --> |
| </a> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <h4>propagate</h4> |
| <pre>public abstract boolean propagate</pre> |
| <div class="block">Specifies if the resource URL properties must be propagated. If set to true, then the URL properties |
| ("protocol"/"host"/"port"/"path") will be propagated to the service properties of the component which |
| is using this dependency.</div> |
| <dl> |
| <dt><span class="returnLabel">Returns:</span></dt> |
| <dd>the propagate flag</dd> |
| </dl> |
| <dl> |
| <dt>Default:</dt> |
| <dd>false</dd> |
| </dl> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| <ul class="blockList"> |
| <li class="blockList"><a name="name--"> |
| <!-- --> |
| </a> |
| <ul class="blockListLast"> |
| <li class="blockList"> |
| <h4>name</h4> |
| <pre>public abstract java.lang.String name</pre> |
| <div class="block">The name used when dynamically configuring this dependency from the init method. |
| Specifying this attribute allows to dynamically configure the dependency |
| <code>filter</code> and <code>required</code> flag from the Service's init method. |
| All unnamed dependencies will be injected before the init() method; so from the init() method, you can |
| then pick up whatever information needed from already injected (unnamed) dependencies, and configure dynamically |
| your named dependencies, which will then be calculated once the init() method returns. |
| |
| <p> See <a href="../../../../../../org/apache/felix/dm/annotation/api/Init.html" title="annotation in org.apache.felix.dm.annotation.api"><code>Init</code></a> annotation for an example usage of a dependency dynamically configured from the init method.</div> |
| <dl> |
| <dt><span class="returnLabel">Returns:</span></dt> |
| <dd>the dependency name</dd> |
| </dl> |
| <dl> |
| <dt>Default:</dt> |
| <dd>""</dd> |
| </dl> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| </div> |
| </div> |
| <!-- ========= END OF CLASS DATA ========= --> |
| <!-- ======= START OF BOTTOM NAVBAR ====== --> |
| <div class="bottomNav"><a name="navbar.bottom"> |
| <!-- --> |
| </a> |
| <div class="skipNav"><a href="#skip.navbar.bottom" title="Skip navigation links">Skip navigation links</a></div> |
| <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/ResourceAdapterService.html" title="annotation in org.apache.felix.dm.annotation.api"><span class="typeNameLink">Prev Class</span></a></li> |
| <li><a href="../../../../../../org/apache/felix/dm/annotation/api/ServiceDependency.html" title="annotation in org.apache.felix.dm.annotation.api"><span class="typeNameLink">Next Class</span></a></li> |
| </ul> |
| <ul class="navList"> |
| <li><a href="../../../../../../index.html?org/apache/felix/dm/annotation/api/ResourceDependency.html" target="_top">Frames</a></li> |
| <li><a href="ResourceDependency.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>Field | </li> |
| <li>Required | </li> |
| <li><a href="#annotation.type.optional.element.summary">Optional</a></li> |
| </ul> |
| <ul class="subNavList"> |
| <li>Detail: </li> |
| <li>Field | </li> |
| <li><a href="#annotation.type.element.detail">Element</a></li> |
| </ul> |
| </div> |
| <a name="skip.navbar.bottom"> |
| <!-- --> |
| </a></div> |
| <!-- ======== END OF BOTTOM NAVBAR ======= --> |
| </body> |
| </html> |