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