1#!../../src/xotclsh 2# $Id: Counter2.xotcl,v 1.3 2005/09/09 21:09:01 neumann Exp $ 3array set opts {-pkgdir .}; array set opts $argv 4lappend auto_path $opts(-pkgdir) 5 6package require XOTcl 1; namespace import -force xotcl::* 7 8package require xotcl::actiweb::htmlPlace 9package require xotcl::actiweb::pageTemplate 10 11HtmlPlace ::receiver -port 8091 -allowExit exit 12 13### 14### The counter class is an agent implementing the business logic 15### 16Class Counter -superclass Agent -parameter {{count 1}} 17 18Counter instproc init args { ;### Constructor 19 next ;### Call superclass constructor 20 my persistent count ;### make count variable persistent 21} 22Counter instproc increment {} { ;### increment method 23 my incr count 24} 25### Create two counter instances c1/c2 26Counter c1 27Counter c2 28 29### 30### Define a specialization of web object as a facade to the counters 31### The Page Template Mixin defines the HTML appearance 32### 33 34### Define an HTML Page Template 35Class WebCounter -superclass WebObject \ 36 -instmixin PageTemplateHtml -parameter {counter} 37 38WebCounter instproc init args { 39 next 40 [my set place] exportObjs [self] ;### export the web counter object 41 my exportProcs increment ;### export counter's increment method 42} 43WebCounter instproc increment {} { ;### A method that decorates increment with HTML appearence 44 my instvar counter ;### import var that stores shielded web agent 45 $counter [self proc] ;### call the actual method on the web agent 46 my default ;### update HTML page 47} 48WebCounter instproc default {} { ;### Method for updating HTML page 49 my instvar count counter ;### importiere var that stores shielded web agent 50 $counter instvar count ;### importiere count var 51 # 52 # and create web-page with counter content 53 # 54 my simplePage [self] "Html-Facade for $counter using a page template" \ 55 "The value in $counter is $count.<p> 56 <A HREF='[my selfAction increment]'>Increment Counter</a><p>" 57} 58# 59# create two web-facade instances; one for each counter 60# 61WebCounter web-c1 -counter c1 62WebCounter web-c2 -counter c2 63 64### Start event loop and handle connections 65receiver startEventLoop 66