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