blob: e51b211318a7d62c94f8427a645948117ce0deb7 [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Apache Wink : 7 Apache Wink Representations</title>
<link rel="stylesheet" href="styles/site.css" type="text/css" />
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<table class="pagecontent" border="0" cellpadding="0" cellspacing="0" width="100%" bgcolor="#ffffff">
<tr>
<td valign="top" class="pagebody">
<div class="pageheader">
<span class="pagetitle">
Apache Wink : 7 Apache Wink Representations
</span>
</div>
<div class="pagesubheading">
This page last changed on Oct 14, 2009 by <font color="#0050B2">michael</font>.
</div>
<h1><a name="7ApacheWinkRepresentations-ApacheWinkRepresentations"></a>Apache Wink Representations</h1>
<p>In addition to the JAX-RS standard representations Apache Wink provides an expanded set of representations that can be used by an application to expose resources in a rich set of representations. The following section provides information about the representations that are supported by Apache Wink.</p>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'><h3><a name="7ApacheWinkRepresentations-Contents"></a>Contents </h3></th>
</tr>
<tr>
<td class='confluenceTd'> <a href="7.1 JSON.html" title="7.1 JSON">7.1 Json </a> </td>
</tr>
<tr>
<td class='confluenceTd'> <a href="7.2 APP.html" title="7.2 APP">7.2 APP </a> </td>
</tr>
<tr>
<td class='confluenceTd'> <a href="7.3 Atom.html" title="7.3 Atom">7.3 Atom </a> </td>
</tr>
<tr>
<td class='confluenceTd'> <a href="7.4 RSS.html" title="7.4 RSS">7.4 RSS</a> </td>
</tr>
<tr>
<td class='confluenceTd'> <a href="7.5 HTML.html" title="7.5 HTML">7.5 HTML </a> </td>
</tr>
<tr>
<td class='confluenceTd'> <a href="7.6 CSV.html" title="7.6 CSV">7.6 CSV </a> </td>
</tr>
<tr>
<td class='confluenceTd'> <a href="7.7 OpenSearch.html" title="7.7 OpenSearch">7.7 OpenSearch </a> </td>
</tr>
<tr>
<td class='confluenceTd'> <a href="7.8 MultiPart.html" title="7.8 MultiPart">7.8 MultiPart</a> </td>
</tr>
</tbody></table>
<h3><a name="7ApacheWinkRepresentations-ApacheWinkRepresentationsRequestFlow"></a>Apache Wink Representations Request Flow</h3>
<p>The following diagram illustrates the client request flow for a resource.</p>
<h3><a name="7ApacheWinkRepresentations-"></a></h3>
<p><img src="attachments/2851061/4751375.jpg" align="absmiddle" border="0"/></p>
<p>A resource is an abstract entity and as such can not be transmitted between peers. When a client is required to send or receive a resource it must use a representation of that resource. The resource representation is a specific formatting of the resource data. The diagram illustrates that a request for a resource is in fact a request for a specific representation of that resource. </p>
<p>Apache Wink implements resource representations through the use of providers for java objects as defined by the JAX-RS specification.</p>
<h3><a name="7ApacheWinkRepresentations-ApacheWinkProviders"></a>Apache Wink Providers</h3>
<h3><a name="7ApacheWinkRepresentations-"></a></h3>
<p>In addition to JAX-RS standard providers (<b>refer to section 4.2 of the JAX-RS specification</b>), Apache Wink provides a set of complementary providers. The purpose of these providers is to provide mapping services between various representations for example Atom, APP, OpenSearch, CSV, JSON and HTML, and their associated Java data models.</p>
<p>The Apache Wink providers are pre-registered and delivered with the Apache Wink runtime along with the JAX-RS standard providers.</p>
<p>Apache Wink provides an additional method for defining the life cycle of a provider via the use of the @Scope annotation and a way to define the providers priorities.</p>
<h2><a name="7ApacheWinkRepresentations-"></a></h2>
<h4><a name="7ApacheWinkRepresentations-Scoping"></a>Scoping</h4>
<p>The JAX-RS specification defines by default, that a singleton instance of each provider class is instantiated for each JAX-RS application. Apache Wink fully supports this requirement and in addition provides a "Prototype" lifecycle, which is an instance per-request lifecycle.<br/>
Prototype means that a new instance of a provider class is instantiated for each request. The @Scope annotation (section‎0) is used on a provider class to specify its lifecycle. The lifecycle of a provider that does not specify the @Scope annotation defaults to the singleton lifecycle.</p>
<h4><a name="7ApacheWinkRepresentations-PrototypeExample"></a>Prototype Example</h4>
<p>The following example shows how to define a provider with a prototype lifecycle.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">@Scope(ScopeType.PROTOTYPE)
@Provider
public class MyProvider implements MessageBodyReader<span class="code-tag">&lt;String&gt;</span>{
...
}
</pre>
</div></div>
<h4><a name="7ApacheWinkRepresentations-SingletonExample1"></a>Singleton Example 1</h4>
<p>The following example shows how to define a provider with a singleton lifecycle.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">@Scope(ScopeType.SINGELTON)
@Provider
public class MyProvider implements MessageBodyReader<span class="code-tag">&lt;String&gt;</span>{
...
}
</pre>
</div></div>
<h4><a name="7ApacheWinkRepresentations-SingletonExample2"></a>Singleton Example 2</h4>
<p>The following example shows that when the @Scope annotation is not used, the provider will be a singleton, as per the JAX-RS specification.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">@Provider
public class MyProvider implements MessageBodyReader<span class="code-tag">&lt;String&gt;</span>{
...
}
</pre>
</div></div>
<h3><a name="7ApacheWinkRepresentations-Priority"></a>Priority</h3>
<p>Apache Wink provides a method for setting a priority for a provider.</p>
<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="images/icons/emoticons/information.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Reference</b><br />For more information on Provider Priorities refer to section <a href="5.1 Registration and Configuration.html#5.1RegistrationandConfiguration-ProviderPriorities">5.1 Registration and Configuration</a>.</td></tr></table></div>
<br/>
<div class="tabletitle">
<a name="attachments">Attachments:</a>
</div>
<div class="greybox" align="left">
<img src="images/icons/bullet_blue.gif" height="8" width="8" alt=""/>
<a href="attachments/2851061/4751374.jpg">Apache Wink Representations Diagram.jpg</a> (image/jpeg)
<br/>
<img src="images/icons/bullet_blue.gif" height="8" width="8" alt=""/>
<a href="attachments/2851061/4751375.jpg">Apache Wink Representations Diagram2.jpg</a> (image/jpeg)
<br/>
</div>
</td>
</tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td height="12" background="http://cwiki.apache.org/confluence/images/border/border_bottom.gif"><img src="images/border/spacer.gif" width="1" height="1" border="0"/></td>
</tr>
<tr>
<td align="center"><font color="grey">Document generated by Confluence on Nov 11, 2009 06:57</font></td>
</tr>
</table>
</body>
</html>