blob: 5eec196f1bf685669fb8a9d1775410e1092107a3 [file] [log] [blame]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8"/>
<title>Apache Tamaya - Extension: Resolver</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<meta name="description" content=""/>
<meta name="author" content=""/>
<meta name="keywords" content=""/>
<meta name="generator" content="'JBake '+'${version}"/>
<!-- Le styles -->
<link href="../../css/bootstrap.min.css" rel="stylesheet"/>
<link href="../../css/asciidoctor.css" rel="stylesheet"/>
<link href="../../css/base.css" rel="stylesheet"/>
<link href="../../css/prettify.css" rel="stylesheet"/>
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="../../js/html5shiv.min.js"></script>
<![endif]-->
<!-- Fav and touch icons from ASF -->
<link rel="shortcut icon" href="../../favicon.ico"/>
<link rel="apple-touch-icon" sizes="57x57" href="../../favicons/apple-touch-icon-57x57.png"/>
<link rel="apple-touch-icon" sizes="60x60" href="../../favicons/apple-touch-icon-60x60.png"/>
<link rel="apple-touch-icon" sizes="72x72" href="../../favicons/apple-touch-icon-72x72.png"/>
<link rel="apple-touch-icon" sizes="76x76" href="../../favicons/apple-touch-icon-76x76.png"/>
<link rel="apple-touch-icon" sizes="114x114" href="../../favicons/apple-touch-icon-114x114.png"/>
<link rel="apple-touch-icon" sizes="120x120" href="../../favicons/apple-touch-icon-120x120.png"/>
<link rel="apple-touch-icon" sizes="144x144" href="../../favicons/apple-touch-icon-144x144.png"/>
<link rel="apple-touch-icon" sizes="152x152" href="../../favicons/apple-touch-icon-152x152.png"/>
<link rel="apple-touch-icon" sizes="180x180" href="../../favicons/apple-touch-icon-180x180.png"/>
<link rel="icon" type="image/png" href="../../favicons/favicon-32x32.png" sizes="32x32"/>
<link rel="icon" type="image/png" href="../../favicons/favicon-194x194.png" sizes="194x194"/>
<link rel="icon" type="image/png" href="../../favicons/favicon-96x96.png" sizes="96x96"/>
<link rel="icon" type="image/png" href="../../favicons/android-chrome-192x192.png" sizes="192x192"/>
<link rel="icon" type="image/png" href="../../favicons/favicon-16x16.png" sizes="16x16"/>
<link rel="manifest" href="../../favicons/manifest.json"/>
<link rel="shortcut icon" href="../../favicons/favicon.ico"/>
<meta name="msapplication-TileColor" content="#603cba"/>
<meta name="msapplication-TileImage" content="../../favicons/mstile-144x144.png"/>
<meta name="msapplication-config" content="../../favicons/browserconfig.xml"/>
<meta name="theme-color" content="#303284"/>
</head>
<body onload="prettyPrint()">
<div id="wrap">
<div>
<!-- Fixed navbar -->
<div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="../../index.html">Apache Tamaya (incubating)</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a href="../../start.html">Tamaya in 5 minutes</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Documentation <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="../../documentation/usecases.html">Use Cases and Requirements</a></li>
<li><a href="../../documentation/quickstart.html">Quickstart</a></li>
<li><a href="../../documentation/api.html">API</a></li>
<li><a href="../../documentation/core.html">Core</a></li>
<li><a href="../../documentation/extensions.html">Extension Guide</a></li>
<li class="divider"></li>
<li><a href="../../apidocs/stable/index.html">Javadoc 0.3-incubating (release/stable)</a></li>
<li><a href="../../apidocs/development/index.html">Javadoc 0.4-incubating-SNAPSHOT (development)</a></li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Development <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="../../development/source.html">Sources</a></li>
<li><a href="../../development/community.html">Community</a></li>
<li><a href="../../development/team.html">Project Team</a></li>
<li><a target="_blank" href="https://builds.apache.org/view/S-Z/view/Tamaya/">CI / ASF Jenkins</a></li>
<li><a target="_blank" href="https://issues.apache.org/jira/browse/TAMAYA">Issues / ASF Jira</a></li>
<li><a href="../../devguide.html">Development Guide</a></li>
<li><a href="../../release-guide.html">Release Guide</a></li>
<li class="divider"></li>
<li><a href="../../development/possible-contributions.html">Possible Contributions</a></li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Releases <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="../../download.html">Download</a></li>
<li><a href="../../history.html">Release History</a></li>
</ul>
</li>
<!-- Example:
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li class="divider"></li>
<li class="dropdown-header">Nav header</li>
<li><a href="#">Separated link</a></li>
<li><a href="#">One more separated link</a></li>
</ul>
</li>
-->
<li><a href="../../sitemap.xml">Sitemap</a></li>
<li><a href="../../feed.xml">Subscribe</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
</div>
<div class="container">
<div class="page-header">
<h1>Apache Tamaya - Extension: Resolver</h1>
</div>
<p><em>2018-09-06</em></p>
<p><div class="sect1">
<h2 id="Resolver">Tamaya Resolver (Extension Module)</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Tamaya <em>Resolver</em> is an extension module. Refer to the <a href="../extensions.html">extensions documentation</a> for further details.</p>
</div>
<div class="sect2">
<h3 id="_what_functionality_this_module_provides">What functionality this module provides ?</h3>
<div class="paragraph">
<p>Tamaya <em>Resolver</em> is an extension module. Refer to the <a href="../extensions.html">extensions documentation</a> for further details about modules.</p>
</div>
<div class="paragraph">
<p>Tamaya Resolver provides a extendible dynamic resolution mechanism. It allows to use UNIX-styled (${...} placeholder expressions in your configuration values. The resolver hereby supports transitive resolution and also prevents cycles to loop endlessly.</p>
</div>
</div>
<div class="sect2">
<h3 id="_compatibility">Compatibility</h3>
<div class="paragraph">
<p>The module is based on Java 8, so it can be used with Java 8 and beyond.</p>
</div>
</div>
<div class="sect2">
<h3 id="_installation">Installation</h3>
<div class="paragraph">
<p>To benefit from dynamic value resolution you only must add the corresponding dependency to your module:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-xml" data-lang="xml">&lt;dependency&gt;
&lt;groupId&gt;org.apache.tamaya.ext&lt;/groupId&gt;
&lt;artifactId&gt;tamaya-resolver&lt;/artifactId&gt;
&lt;version&gt;0.4-incubating-SNAPSHOT&lt;/version&gt;
&lt;/dependency&gt;</code></pre>
</div>
</div>
<div class="paragraph">
<p>The module automatically registers an according Filter that is automatically called, whenever a value is accessed.</p>
</div>
</div>
<div class="sect2">
<h3 id="_available_resolvers">Available Resolvers</h3>
<div class="paragraph">
<p>Currently the module defines the following resolvers:</p>
</div>
<table class="tableblock frame-all grid-all spread">
<caption class="title">
Table 1. Available Resolvers
</caption>
<colgroup>
<col style="width: 25%;">
<col style="width: 50%;">
<col style="width: 25%;">
</colgroup>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><em>Expression</em></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><em>Description</em></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><em>Example</em></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">conf:&lt;configKey&gt;</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Reads another configKey and replaces the expression with the value found.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">conf-ref=${conf:anotherConf.entryKey}</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">resource:&lt;resourceRef&gt;</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Reads a resource from the current classpath and replaces the expression with the given text content.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">cp-ref=${resource:Testresource.txt}</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">file:&lt;fileRef&gt;</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Reads a resource from the current classpath and replaces the expression with the given text content.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">file-ref=${file:c:\myFile.txt}</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">url:&lt;url&gt;</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Reads an URL and replaces the expression with the given text content.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">url-ref=${url:http://www.google.com}</p></td>
</tr>
</tbody>
</table>
</div>
<div class="sect2">
<h3 id="_spi_implementing_your_own_resolvers">SPI: Implementing your own Resolvers</h3>
<div class="paragraph">
<p>The module also provides a small SPI for adding your own resolver implementations. Basically the first and most important thing to do is implementing the ExpressionResolver interface:</p>
</div>
<div class="listingblock">
<div class="title">
Implementing a Custom Resolver
</div>
<div class="content">
<pre class="prettyprint highlight"><code class="language-java" data-lang="java">public class PwdDecrypter implements ExpressionResolver {
@Override
public String getResolverPrefix() {
return "decrypt:";
}
@Override
public String evaluate(String expression) {
return decrypt(expression);
}
private String decrypt(String s) {
...
}
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>Basically that is all you must do, after having registered the class with the ServiceLoader it will be found and loaded by the implementation. With that all expressions that start with the given prefix are passed to the resolver, so all the following expressions will be sent to the implementation:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-listing" data-lang="listing">blabla ${decrypt:myname}
blabla ${decrypt:myname} foo blabla ${decrypt:myname}</code></pre>
</div>
</div>
<div class="paragraph">
<p>Hereby evaluation is repeated until no further change of values could be detetced. In case of a endless loop the evaluation is broken after a (configurable) number of cycles.</p>
</div>
<div class="paragraph">
<p>Under the hood instances of ExpressionResolver are managed by an implementation of the ExpressionEvaluator interface:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-java" data-lang="java">public interface ExpressionEvaluator {
/**
* Evaluates the current expression.
* @param key the key, not null.
* @param value the value to be filtered/evaluated.
* @return the filtered/evaluated value, including null.
*/
String evaluateExpression(String key, String value);
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>Implementing and registering this interface gives you full control, but in most cases you should be fine with the default implementation in place.</p>
</div>
</div>
</div>
</div></p>
<hr />
</div>
</div>
<div>
<div id="push"></div>
<div id="footer">
<div class="container">
<p class="muted credit">&copy; 2014-<span>2018</span> Apache Software Foundation | Mixed with <a href="http://getbootstrap.com/">Bootstrap v3.1.1</a>
| Baked with <a href="http://jbake.org">JBake <span>v2.6.1</span></a>
at <span>2018-11-02</span> |
<a class="twitter-follow-button" data-show-count="false" href="https://twitter.com/tamayaconf">Follow @tamayaconf</a><script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>
</p>
<p>
<b>Disclaimer</b>
Apache Tamaya (incubating) is an effort undergoing
incubation at
The Apache Software Foundation (ASF), sponsored by
the name of Apache Incubator. Incubation is required of
all newly accepted projects until a further review indicates
that the infrastructure, communications, and decision making
process have stabilized in a manner consistent with other
successful ASF projects. While incubation status is not
necessarily a reflection of the completeness or stability of
the code, it does indicate that the project has yet to
be fully endorsed by the ASF.<br />
Apache, Apache Tamaya, and the Apache Tamaya logo are registered trademarks or trademarks of The Apache Software Foundation in the U.S. and/or other countries.<br />
<a href="https://incubator.apache.org/guides/website.html" style="border:0px;" target="_target">
<img class="incubator-logo" src="../../logos/apache-incubator.png" style="height: 50px;"/>
</a>
</p>
</div>
</div>
<!-- Le javascript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="../../js/jquery-1.11.1.min.js"></script>
<script src="../../js/bootstrap.min.js"></script>
<script src="../../js/prettify.js"></script>
</div>
</body>
</html>