1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type" /> 5 <title>How Resources are Created</title> 6 <meta name="generator" 7 content="amaya 8.1a, see http://www.w3.org/Amaya/" /> 8 <link href="styles.css" rel="stylesheet" type="text/css" /> 9 </head> 10 <body> 11 <h1>How Resources are Created 12 </h1> 13 <p>In the <code>MyApplication</code> 14 <a href="resources.html">example</a> (and in many applications), 15 the only 16 thing we need to 17 consider is 18 what our code does, not how objects are created from the <code>MyResource</code> 19 class and how the <code>respond</code> 20 method is invoked. However, the mechanisms behind all these things are 21 not magic - the <a href="deploying.html">adapter 22 code</a> is responsible for all of 23 this. Let us 24 turn the diagram of components on its side and investigate what happens 25 when a request is sent to the application from a user:</p> 26 <table class="layers" 27 style="width: 80%; text-align: left; margin-left: auto; margin-right: auto;" 28 border="0" cellpadding="5" cellspacing="0"> 29 <tbody> 30 <tr> 31 <th 32 style="border-width: 1px 1px 0px; text-align: center; vertical-align: middle; background-color: rgb(192, 192, 192); width: 30%; border-top-style: solid; border-left-style: solid;">Server 33 environment</th> 34 <th 35 style="border-width: 1px; text-align: center; vertical-align: middle; border-left-style: solid; border-top-style: solid; width: 30%; background-color: rgb(102, 203, 255);">Adapter 36 </th> 37 <th 38 style="text-align: center; vertical-align: middle; border-top-style: solid; border-left-style: solid; border-right-style: solid; border-top-width: 1px; border-left-width: 1px; border-right-width: 1px; background-color: rgb(193, 255, 102); width: 40%;">Application 39 </th> 40 </tr> 41 <tr> 42 <td 43 style="background-color: rgb(192, 192, 192); border-left-style: solid; border-left-width: 1px;" 44 align="undefined" valign="undefined"><span class="method">The request 45 is received and sent to 46 the adapter... </span></td> 47 <td 48 style="background-color: rgb(102, 203, 255); border-left-style: solid; border-left-width: 1px;" 49 align="undefined" valign="undefined"><span class="method">The adapter 50 creates a resource object 51 in the application... </span></td> 52 <td 53 style="background-color: rgb(193, 255, 102); border-left-style: solid; border-right-style: solid; border-left-width: 1px; border-right-width: 1px;" 54 align="undefined" valign="undefined"><span class="method">A resource 55 object is 56 created and initialised. </span></td> 57 </tr> 58 <tr> 59 <td 60 style="background-color: rgb(192, 192, 192); border-left-style: solid; border-bottom-style: solid; border-left-width: 1px; border-right-width: 1px; border-bottom-width: 1px;"><br /> 61 </td> 62 <td 63 style="background-color: rgb(102, 203, 255); border-left-style: solid; border-bottom-style: solid; border-left-width: 1px; border-bottom-width: 1px;" 64 align="undefined" valign="undefined"><span class="method">The adapter 65 calls the <code>respond</code> method on the new resource...</span></td> 66 <td 67 style="background-color: rgb(193, 255, 102); border-left-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-width: 1px; border-right-width: 1px; border-bottom-width: 1px;" 68 align="undefined" valign="undefined"><span class="method">The code 69 within the resource's <code>respond</code> method is executed. </span></td> 70 </tr> 71 </tbody> 72 </table> 73 <h2>The Role of the Adapter</h2> 74 <p>So it is the responsibility of the adapter to create at least one 75 resource object so that the application code may be executed when a 76 request is received from a user. This is described in the <a 77 href="deploying.html">deployment documentation</a>.</p> 78 <h2>Creating Many Resources</h2> 79 <p>In more 80 complicated applications, there may 81 be a 82 need to create a number of resource objects and possibly to do so 83 dynamically within an application itself, but this is not usually 84 interesting or relevant to think about when writing your first 85 application - see <a href="paths-filesystem.html">"Treating the Path 86 Like 87 a Filesystem"</a> for a 88 discussion of creating new resource objects both in the adapter code 89 and dynamically within applications.</p> 90 </body> 91 </html>