| <!DOCTYPE html> |
| <!-- |
| | Generated by Apache Maven Doxia Site Renderer 1.8.1 from src/site/asciidoc/index.adoc |
| | Rendered using Apache Maven Fluido Skin 1.7 |
| --> |
| <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
| <head> |
| <meta charset="UTF-8" /> |
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> |
| <meta http-equiv="Content-Language" content="en" /> |
| <title>Spring Registry Component – </title> |
| <link rel="stylesheet" href="./css/apache-maven-fluido-1.7.min.css" /> |
| <link rel="stylesheet" href="./css/site.css" /> |
| <link rel="stylesheet" href="./css/print.css" media="print" /> |
| <script type="text/javascript" src="./js/apache-maven-fluido-1.7.min.js"></script> |
| <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css"> |
| |
| <link rel="stylesheet" href="../css/site.css"> |
| <!-- Google Analytics --> |
| <script type="text/javascript"> |
| var _gaq = _gaq || []; |
| _gaq.push(['_setAccount', 'UA-140879-5']); |
| _gaq.push(['_trackPageview']); |
| (function() { |
| var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; |
| ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; |
| var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); |
| })(); |
| </script> |
| </head> |
| <body class="topBarEnabled"> |
| <a href="https://github.com/apache/archiva-components"> |
| <img style="position: absolute; top: 0; right: 0; border: 0; z-index: 10000;" |
| src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" |
| alt="Fork me on GitHub"> |
| </a> |
| <div id="topbar" class="navbar navbar-fixed-top "> |
| <div class="navbar-inner"> |
| <div class="container"><div class="nav-collapse"> |
| <ul class="nav"> |
| <li class="dropdown"> |
| <a href="#" class="dropdown-toggle" data-toggle="dropdown">Modules <b class="caret"></b></a> |
| <ul class="dropdown-menu"> |
| <li><a href="archiva-components-spring-registry-api/index.html" title="Archiva Components :: Spring Registry Api">Archiva Components :: Spring Registry Api</a></li> |
| <li><a href="archiva-components-spring-registry-commons/index.html" title="Archiva Components :: Spring Registry Commons">Archiva Components :: Spring Registry Commons</a></li> |
| </ul> |
| </li> |
| <li class="dropdown"> |
| <a href="#" class="dropdown-toggle" data-toggle="dropdown">Project Documentation <b class="caret"></b></a> |
| <ul class="dropdown-menu"> |
| <li class="dropdown-submenu"> |
| <a href="project-info.html" title="Project Information">Project Information</a> |
| <ul class="dropdown-menu"> |
| <li><a href="index.html" title="About">About</a></li> |
| </ul> |
| </li> |
| <li class="dropdown-submenu"> |
| <a href="project-reports.html" title="Project Reports">Project Reports</a> |
| <ul class="dropdown-menu"> |
| <li><a href="apidocs/index.html" title="Javadoc">Javadoc</a></li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| <form id="search-form" action="https://www.google.com/search" method="get" class="navbar-search pull-right" > |
| <input value="http://archiva.apache.org/components" name="sitesearch" type="hidden"/> |
| <input class="search-query" name="q" id="query" type="text" /> |
| </form> |
| <script type="text/javascript">asyncJs( 'https://cse.google.com/brand?form=search-form' )</script> |
| <ul class="nav pull-right"> |
| <li class="dropdown"> |
| <a href="#" class="dropdown-toggle" data-toggle="dropdown">External Links <b class="caret"></b></a> |
| <ul class="dropdown-menu"> |
| <li><a href="../../index.html" title="Archiva">Archiva</a></li> |
| </ul> |
| </li> |
| </ul> |
| </div> |
| </div> |
| </div> |
| </div> |
| <div class="container"> |
| <div id="banner"> |
| <div class="pull-left"><a href="http://archiva.apache.org/index.html" id="bannerLeft"><img src="http://archiva.apache.org/images/archiva.png" alt="Apache Archiva"/></a></div> |
| <div class="pull-right"><a href="http://www.apache.org/" id="bannerRight"><img src="http://www.apache.org/images/asf_logo_wide_2016.png" alt="Apache Software Foundation"/></a></div> |
| <div class="clear"><hr/></div> |
| </div> |
| |
| <div id="breadcrumbs"> |
| <ul class="breadcrumb"> |
| <li class=""><a href="../../index.html" title="Archiva">Archiva</a><span class="divider">/</span></li> |
| <li class=""><a href="../index.html" title="Archiva Components">Archiva Components</a><span class="divider">/</span></li> |
| <li class=""><a href="index.html" title="Spring Registry">Spring Registry</a><span class="divider">/</span></li> |
| <li class="active "></li> |
| </ul> |
| </div> |
| <div id="bodyColumn" > |
| <h1>Spring Registry Component</h1> |
| <div class="sect1"> |
| <h2 id="about">About</h2> |
| <div class="sectionbody"> |
| <div class="paragraph"> |
| <p>The Spring registry is a single source of external configuration for Spring components and applications. |
| It can be used by components to source configuration, knowing that it can be used from within applications |
| without the information being hard coded into the component.</p> |
| </div> |
| <div class="paragraph"> |
| <p>To facilitate a variety of providers, <a href="http://jakarta.apache.org/commons/configuration/">Commons Configuration</a> |
| is used to implement the backing storage.</p> |
| </div> |
| <div class="paragraph"> |
| <p>This relies on a pull-based (or lookup) mechanism - the applications request specific pieces of configuration at |
| the time they need them, and it is retrieved from the registry.</p> |
| </div> |
| <div class="paragraph"> |
| <p>The registry is configurable so that configuration can be placed in any location desired, and is shared container |
| wide. A registry using the same file as other running VMs should operate correctly.</p> |
| </div> |
| <div class="admonitionblock note"> |
| <table> |
| <tr> |
| <td class="icon"> |
| <i class="fa icon-note" title="Note"></i> |
| </td> |
| <td class="content"> |
| <div class="paragraph"> |
| <p>Inside the application server, this means that the scope is application wide as each application has it’s |
| own container. It may be feasible to provide a single registry for the whole server, but this has not yet been |
| tested. This would only be necessary if the server was to dictate configuration locations that the registry was |
| not already configured to use. Of course, such additional locations could be added to the application registry |
| instances programmatically as well.</p> |
| </div> |
| </td> |
| </tr> |
| </table> |
| </div> |
| <div class="sect2"> |
| <h3 id="example_configuration">Example Configuration</h3> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre><component> |
| <role>org.apache.archiva.components.registry.Registry</role> |
| <implementation>org.apache.archiva.components.registry.CommonsConfigurationRegistry</implementation> |
| <role-hint>commons-configuration</role-hint> |
| <configuration> |
| <properties> |
| <system/> |
| <jndi prefix="java:comp/env" config-optional="true"/> |
| <xml fileName="${user.home}/.m2/archiva.xml" config-optional="true" config-name="org.apache.maven.archiva" |
| config-at="org.apache.maven.archiva" config-forceCreate="true"/> |
| <properties fileName="${user.home}/.m2/security.properties" config-optional="true" |
| config-at="org.codehaus.plexus.security"/> |
| </properties> |
| </configuration> |
| </component></pre> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p>The configuration inside the outer <code>properties</code> element is equivalent to the |
| <a href="http://jakarta.apache.org/commons/configuration/howto_configurationbuilder.html#Using_DefaultConfigurationBuilder">builder syntax</a> |
| for Commons Configuration. This maps to similar concepts in the registry.</p> |
| </div> |
| <div class="paragraph"> |
| <p>In this example, the precedence is to first look in the system properties, then JNDI, then the given XML file, and |
| finally the given properties file.</p> |
| </div> |
| <div class="paragraph"> |
| <p>Registries can have 'sections', which are declared as partitioned areas of the registry. This is done using the |
| <code>config-name</code> attribute in Commons Configuration. While the sections behave normally as a part of the global |
| registry, they can easily be retrieved independently. This is particularly useful for write-back operations so the |
| file the section is stored in can be saved when the registry is modified.</p> |
| </div> |
| <div class="paragraph"> |
| <p>Each configuration source can be configured with a given mount-point in the registry using the <code>config-at</code> |
| attribute. This will cause all of the properties to be stored with the given prefix.</p> |
| </div> |
| </div> |
| <div class="sect2"> |
| <h3 id="using_the_registry">Using the Registry</h3> |
| <div class="paragraph"> |
| <p>The registry can be used as a simple directory, for example:</p> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre>int value = registry.getInt( "test.property" ); |
| String text = registry.getString( "text.data" ); |
| boolean enabled = registry.getBoolean( "system.enabled", true );</pre> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p>The first parameter is always a key. The registry is hierachical, so in the key, a <code>.</code> (period) represents a |
| nested configuration, and can be traversed to any level.</p> |
| </div> |
| <div class="paragraph"> |
| <p>The second parameter specifies a default value. If it is not given, then <code>null</code> is returned for strings if the |
| key is not found in the registry, and an exception is thrown for integers and booleans under the same circumstances.</p> |
| </div> |
| </div> |
| <div class="sect2"> |
| <h3 id="subsets_and_sections">Subsets and Sections</h3> |
| <div class="paragraph"> |
| <p>There are two ways to work with a portion of the registry at a time: subsets and sections.</p> |
| </div> |
| <div class="paragraph"> |
| <p>Sections were encountered earlier - and while they return a subset it may span a number of different base prefixes, |
| depending on whether <code>config-at</code> was specified on the section or not. Even so, if it is a subset of the |
| hierachy, some elements of the hierachy at the same level might not be returned because they come from a different |
| section.</p> |
| </div> |
| <div class="paragraph"> |
| <p>On the other hand, subsets are reductions of the registry to keys descending from a given prefix.</p> |
| </div> |
| <div class="paragraph"> |
| <p>Once a subset (or section) is obtained, it behaves the same as the registry as a whole, however it will have fewer |
| values, and looking up values will not have the prefix as a part of the key.</p> |
| </div> |
| <div class="paragraph"> |
| <p>For example:</p> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre>String value = registry.getString( "org.codehaus.plexus.registry.value" ); |
| Registry subset = registry.getSubset( "org.codehaus.plexus.registry" ); |
| value = subset.getString( "value" ); // this will equal the earlier value retrieved</pre> |
| </div> |
| </div> |
| </div> |
| <div class="sect2"> |
| <h3 id="lists_and_maps">Lists and Maps</h3> |
| <div class="paragraph"> |
| <p>It is also possible to retrieve subsets of the registry as collections.</p> |
| </div> |
| <div class="ulist"> |
| <ul> |
| <li> |
| <p><code>getProperties(key)</code>: Maps and properties are straightforward - the subset is converted into key/value pairs |
| and returned as a map.</p> |
| </li> |
| <li> |
| <p><code>getSubsetList(key)</code>: For lists of complex types that will still contain more than one key/value pair, |
| this method can be used to retrieve them as a list of subset registries.</p> |
| </li> |
| <li> |
| <p><code>getList(key)</code>: For lists of simple types, this method can be used to get a list of value objects.</p> |
| </li> |
| </ul> |
| </div> |
| </div> |
| <div class="sect2"> |
| <h3 id="using_models">Using Models</h3> |
| <div class="paragraph"> |
| <p>To simplify the translation of configuration into reusable beans and to produce a self-documenting system, Modello |
| can be used to generate registry I/O classes. The appropriate goals in the plugin are <code>registry-reader</code> and |
| <code>registry-writer</code>.</p> |
| </div> |
| </div> |
| <div class="sect2"> |
| <h3 id="saving_changes">Saving Changes</h3> |
| <div class="paragraph"> |
| <p>Saving changes to a registry is quite simple:</p> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre>registry.save();</pre> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p>Note that the registry must be a file-based section (saving the entire registry will not succeed). It will be saved |
| to the same location that it was loaded from.</p> |
| </div> |
| </div> |
| <div class="sect2"> |
| <h3 id="adding_change_listeners">Adding Change Listeners</h3> |
| <div class="paragraph"> |
| <p>~~TODO</p> |
| </div> |
| </div> |
| </div> |
| </div> |
| </div> |
| </div> |
| <hr/> |
| <footer> |
| <div class="container"> |
| <div class="row"> |
| <p>Copyright ©2006–2019 |
| <a href="http://www.apache.org/">The Apache Software Foundation</a>. |
| All rights reserved.</p> |
| </div> |
| <p id="poweredBy" class="pull-right"><a href="http://maven.apache.org/" title="Built by Maven" class="poweredBy"><img class="builtBy" alt="Built by Maven" src="./images/logos/maven-feather.png" /></a> |
| </p> |
| <div id="ohloh" class="pull-right"> |
| <script type="text/javascript" src="https://www.ohloh.net/p/6670/widgets/project_thin_badge.js"></script> |
| </div> |
| </div> |
| </footer> |
| </body> |
| </html> |