| <!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_191) on Wed Dec 26 11:25:31 CET 2018 --> |
| <title>PropertyType</title> |
| <meta name="date" content="2018-12-26"> |
| <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="PropertyType"; |
| } |
| } |
| 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/Property.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/Registered.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/PropertyType.html" target="_top">Frames</a></li> |
| <li><a href="PropertyType.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>Optional</li> |
| </ul> |
| <ul class="subNavList"> |
| <li>Detail: </li> |
| <li>Field | </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 PropertyType" class="title">Annotation Type PropertyType</h2> |
| </div> |
| <div class="contentContainer"> |
| <div class="description"> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <hr> |
| <br> |
| <pre>@Retention(value=CLASS) |
| @Target(value=ANNOTATION_TYPE) |
| public @interface <span class="memberNameLabel">PropertyType</span></pre> |
| <div class="block">When defining component service properties, one way to achieve this is to apply the <a href="../../../../../../org/apache/felix/dm/annotation/api/Property.html" title="annotation in org.apache.felix.dm.annotation.api"><code>Property</code></a> annotation on your component class name. |
| Now, you can also define your own component property type interfaces and apply them directly on your components (instead of the |
| <a href="../../../../../../org/apache/felix/dm/annotation/api/Property.html" title="annotation in org.apache.felix.dm.annotation.api"><code>Property</code></a> annotation). The PropertyType annotation is closely similar to standard OSGi r7 declarative service @ComponentPropertyType |
| (which is also supported by dependency manager annotations). |
| |
| <h3>Usage Examples</h3> |
| |
| Let’s assume your write an OSGi r7 jax rs servlet context which needs the two following service properties: |
| |
| <p><ul> |
| <li> osgi.http.whiteboard.context.name |
| <li> osgi.http.whiteboard.context.path |
| </ul> |
| |
| <p> Then you can first define your own annotation (but you could also reuse the default annotations provided by the jaxrs whiteboard r7 api): |
| (notice that in the annotation, you can define default service property values): |
| |
| <blockquote> |
| <pre> |
| @PropertyType |
| @interface ServletContext { |
| String osgi_http_whiteboard_context_name() default AppServletContext.NAME; |
| String osgi_http_whiteboard_context_path(); |
| } |
| </pre> |
| </blockquote> |
| |
| In the above, the underscore is mapped to ".". |
| Then you can apply the above annotation on top of your component like this: |
| |
| <blockquote> |
| <pre> |
| @Component |
| @ServletContext(osgi_http_whiteboard_context_path="/game") |
| public class AppServletContext extends ServletContextHelper { |
| } |
| </pre> |
| </blockquote> |
| |
| You can also use configuration admin service in order to override the default service properties: |
| |
| <blockquote> |
| <pre> |
| @Component |
| @ServletContext(osgi_http_whiteboard_context_path="/game") |
| public class AppServletContext extends ServletContextHelper { |
| @ConfigurationDependency(propagate=true, pid="my.pid") |
| void updated(ServletContext cnf) { |
| // if some properties are not present in the configuration, then the ones used in the annotation will be used. |
| // The configuration admin properties, if defined, will override the default configurations defined in the annotations |
| } |
| } |
| </pre> |
| </blockquote> |
| |
| You can also define multiple property type annotations, and possibly single valued annotation. In this case, you can use |
| the standard R7 PREFIX_ constants in order to specify the property prefix, and the property name will be derived from the |
| single valued annotation (using camel case convention): |
| |
| <blockquote> |
| <pre> |
| @PropertyType |
| @interface ContextName { // will map to "osgi.http.whiteboard.context.name" property name |
| String PREFIX="osgi.http.whiteboard."; |
| String value(); |
| } |
| |
| @PropertyType |
| @interface ContextPath { // will map to "osgi.http.whiteboard.context.path" property name |
| String PREFIX="osgi.http.whiteboard."; |
| String value(); |
| } |
| |
| @Component |
| @ContextName(AppServletContext.NAME) |
| @ContextPath("/game") |
| public class AppServletContext extends ServletContextHelper { |
| } |
| </pre> |
| </blockquote> |
| |
| Same example as above, but also using configuration admin service in order to override default service properties: Here, as in OSGi r7 declarative service, |
| you can define a callback method which accepts as arguments all (or some of) the defined property types: |
| |
| <blockquote> |
| <pre> |
| @Component |
| @ContextName(AppServletContext.NAME) |
| @ContextPath("/game") |
| public class AppServletContext extends ServletContextHelper { |
| @ConfigurationDependency(propagate=true, pid="my.pid") |
| void updated(ContextName ctxName, ContextPath ctxPath) { |
| // if some properties are not present in the configuration, then the ones used in the annotation will be used. |
| // The configuration admin properties, if defined, will override the default configurations defined in the annotations |
| } |
| } |
| </pre> |
| </blockquote> |
| |
| The following is the same example as above, but this time the configuration callback can also define a Dictionary in the first argument |
| (in case you want to also get the raw configuration dictionary: |
| |
| <blockquote> |
| <pre> |
| @Component |
| @ContextName(AppServletContext.NAME) |
| @ContextPath("/game") |
| public class AppServletContext extends ServletContextHelper { |
| @ConfigurationDependency(propagate=true, pid="my.pid") |
| void updated(Dictionary<String, Object> rawConfig, ContextName ctxName) { |
| // if some properties are not present in the configuration, then the ones used in the annotation will be used. |
| // The configuration admin properties, if defined, will override the default configurations defined in the annotations |
| } |
| } |
| </pre> |
| </blockquote></div> |
| </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/Property.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/Registered.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/PropertyType.html" target="_top">Frames</a></li> |
| <li><a href="PropertyType.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>Optional</li> |
| </ul> |
| <ul class="subNavList"> |
| <li>Detail: </li> |
| <li>Field | </li> |
| <li>Element</li> |
| </ul> |
| </div> |
| <a name="skip.navbar.bottom"> |
| <!-- --> |
| </a></div> |
| <!-- ======== END OF BOTTOM NAVBAR ======= --> |
| </body> |
| </html> |