An Illustration of these Techniques
3. A Pseudo-Constructor Example
This is because it is
independent of what happens to the pages – when created it is tied to the JAVA virtual machine, through
the static variables, and then never destroyed. This demonstrates that we have moved a stage further in
establishing persistence. Since the frame is only created once, there are none of the stability problems that
were previously associated with the Abstract Windows Toolkit. Transition between pages is essentially
instantaneous; whenever access to the underlying HTML is desired, then the very small source applet is
simply reloaded on that page. It provides the link to ShopPanel, from the underlying HTML.
Incidentally, if you look closely, you will notice that ShopPanel this time is not an abstract class. A pseudo-
constructor for an abstract class must follow a very specific initialization procedure in order to work. It
turns out that if the same sequence is followed within a normal class - using the same static variables and
static methods – then this also leads to an object that ‘lives forever.’ However, a normal class can contain
a constructor, and thus it can do more things. We have come further.
The two methods for creating persistence (reloading and pseudo-constructors) cooperate beautifully. Our
shopping cart, for instance, is created once, and then never destroyed. Applet reload gives it continuing
access to the underlying HTML, through Javascript and LiveConnect, and through the applet lifecycle,
which can pass current context information to the persistent class. Creation of the shopping cart can occur
on any of the pages that are being reloaded – one simply sets a boolean variable ‘firstTime’ to true in the
initialization statements in ShopPanel, and when the frame is created, one resets it to false. The change in
the variable is remembered at a reload; the frame is created only when ‘firstTime’ is true.
The material that we have covered thus far is extracted from a patent that covers HTML memory and
pseudo-constructors (Patent Pending acquired Sept. 13, 1999 and January 7, 2000), and the application of
these techniques to a shopping cart and a database cache. My goal is to sell the shopping cart. Obviously,
there will need to be discussion at some point as to what portion of these techniques can become public
domain, and what core needs to be restricted to maintain cart functionality.
Now for some fun. Once one has a program that can ‘live forever,’ then it is
possible to do some interesting things. For instance, one can break into the
JavaScript interpreter on various pages. To demonstrate this, I’ve extended
the shopping cart to use JSObjects. If the JSObject class is new to you, you
might wish to look at http://vdrea.da.ru/tech/jscript-dg/ch19_06.htm. The
basic difference in the shopping cart code is that I now jump to various
pages through the use of (JSObject) JavaScript win.call(“open”,args[]),
rather than through the use of applet.getAppletContext().showDocument(). I
also use win.eval(“status=’message’”).
As you will see, anything that goes
‘off site’ is a bit brittle, and probably not suitable for final version
software. Also, on some versions of Netscape, you will also see that data is
no longer being added up from page to page rather, a new cart is formed
for each page - the very fact that we use the word MAYSCRIPT forces a reload
rather than a reactivation of the applet. Since we are now talking about
breaking security limits, I’ve also changed the style of my presentation.
Next ->
Lane Friesen
lanelise@dowco.com
New on the Java Boutique:
New Review:
Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling
API boasts simplicity, ease-of-integration, a well-rounded feature
set, and it's free!
New Applet:
Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA
sequences into three useful formats.
Elsewhere on internet.com:
WebDeveloper Java
Lots of Java information on webdeveloper.com
WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.
ScriptSearch Java
Hundreds of free Java code files to download.
jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.
|