15.01.2015 Views

4th International Conference on Principles and Practices ... - MADOC

4th International Conference on Principles and Practices ... - MADOC

4th International Conference on Principles and Practices ... - MADOC

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

missing object references in the decoding process, a Java source<br />

interpreter can be applied. In fact, the interpreters of any scripting<br />

language that can interact with Java virtual machine are suitable for<br />

this task. The BeanShell Scripting Language [3], DynamicJava<br />

pure Java source interpreter [8] <strong>and</strong> Jyth<strong>on</strong> [13] are examples.<br />

Note that if a script-embedded XML text is used for argument<br />

passing of Web services or remote procedure calls, classes defined<br />

in the script do not need to be compiled <strong>and</strong> deployed in the<br />

classpath at both the client side <strong>and</strong> the server side. This makes<br />

applicati<strong>on</strong>s more dynamic <strong>and</strong> flexible at runtime.<br />

Every object written by the XMLEncoder uses a st<strong>and</strong>ard XML<br />

schema. According to the schema, when an object graph c<strong>on</strong>tains<br />

cycles or multiple references to the same object, a name, i.e., an<br />

identifier is given to the object so that it can be referred to later. An<br />

identifier is created using the id attribute, which binds a name to an<br />

object instance. A reference is made to a named instance by using<br />

an idref attribute in an element with the tag. In other<br />

words, the XMLEncoder has its own name space.<br />

However, users cannot know which identifier will be assigned to a<br />

given object instance before the object instance is written by the<br />

writeObject() method of the XMLEncoder. Hence, users cannot<br />

write scripts to access the object instance in advance. Moreover, a<br />

Java source interpreter has its own name space to maintain its object<br />

pool. So, our mechanism provides a name mapping table to link the<br />

two name spaces.<br />

For example, when an object instance of the javax.swing.JFrame<br />

class is written, our mechanism first looks for the name of the<br />

instance in the name spaces of the XMLEncoder <strong>and</strong> the Java<br />

interpreter <strong>and</strong> appends a Hashtable to map the two name spaces. It<br />

then writes the script for the XML text, as shown in Figure 1. In this<br />

way, users may write the following Java codes to persist a<br />

javax.swing.JFrame instance referred by the variable f0:<br />

… f0 = new JFrame(); …<br />

encoder.getInterpreter().defineVariable<br />

("frame1", f0);<br />

encoder.writeObject(f0, script); ….<br />

Thus, users do not need to know the assigned identifier of an object<br />

instance before they write scripts.<br />

3.2 Provisi<strong>on</strong> of a script-running capability for<br />

the XMLDecoder<br />

The st<strong>and</strong>ard XMLDecoder class is used in the same way as the<br />

ObjectInputStream. When being instantiated, the XMLDecoder<br />

simply reads the XML documents created by the XMLEncoder, <strong>and</strong><br />

parses the XML text to rec<strong>on</strong>struct the whole object tree. The API<br />

document of the XMLDecoder describes that the readObject()<br />

method can be used to read the next object from the underlying<br />

input stream; however the descripti<strong>on</strong> is not very precise. After<br />

carefully reviewing the source code of the XMLDecoder class<br />

provided in J2SE 1.4 or 1.5, we found that the readObject() method<br />

just dequeues an object for a method call. Therefore, after the<br />

c<strong>on</strong>structor of the XMLDecoder class has been called <strong>and</strong> returned,<br />

all object instances of the whole object tree have already been<br />

created <strong>and</strong> initialized. That is, if users write the Java code<br />

Object f = decoder.readObject();<br />

to read an object, this method just returns a created object instance<br />

from the fr<strong>on</strong>t of the queue.<br />

Note that, in the decoding process, a PersistenceDelegate cannot be<br />

used because it is designed to c<strong>on</strong>trol all aspects of an object’s<br />

persistence for the XMLEncoder in the encoding process. In<br />

additi<strong>on</strong>, since the XMLDecoder parses the whole XML text<br />

immediately after its c<strong>on</strong>structor has been called, all additi<strong>on</strong>al<br />

embedded methods, such as the linkLocalPool <strong>and</strong> runScript<br />

methods depicted in Figure 1, will be executed during the<br />

c<strong>on</strong>structor’s running time. This, however, may cause a problem in<br />

that, when a user wants to read an object instance from the<br />

XMLDecoder, the decoding process actually runs the<br />

corresp<strong>on</strong>ding script for the object beforeh<strong>and</strong>.<br />

To deal with this problem, our mechanism prohibits script-running<br />

during decoding <strong>and</strong> records the object-script map in a hash table<br />

for the Java source interpreter to enable script-running. Therefore,<br />

the corresp<strong>on</strong>ding script is <strong>on</strong>ly executed when an object instance is<br />

read by the user. In additi<strong>on</strong>, the proposed mechanism also<br />

establishes <strong>and</strong> maintains an object pool when decoding. As shown<br />

in Figure 1, this is d<strong>on</strong>e when the linkLocalPool method is<br />

executed.<br />

…<br />

<br />

…<br />

<br />

<br />

<br />

frame1<br />

<br />

<br />

<br />

<br />

<br />

<br />

//&lt;SCRIPT LANGUAGE=&quot;Java&quot;&gt;<br />

//&lt;!---------------------------------<br />

import java.awt.*;<br />

import java.awt.event.*;<br />

import javax.swing.*;<br />

frame1.addWindowListener(new WindowAdapter(){<br />

public void windowIc<strong>on</strong>ified(WindowEvent e){<br />

// do something<br />

} });<br />

//----------------------------------&gt;<br />

//&lt;/SCRIPT&gt;<br />

<br />

….<br />

Figure 1. Linking object pool.<br />

Mapping of<br />

Name Spaces<br />

3.3 Provisi<strong>on</strong> of a cache pool for the<br />

XMLDecoder<br />

The decoding process may take too l<strong>on</strong>g to instantiate certain<br />

heavyweight objects, but providing a caching system for Java<br />

applicati<strong>on</strong>s is usually a feasible way to speed up the process. In<br />

additi<strong>on</strong>, for some special applicati<strong>on</strong>s, a certain class may be<br />

implemented as a Singlet<strong>on</strong> design pattern. Nevertheless, the<br />

current XMLEncoder/XMLDecoder paradigm cannot ensure that<br />

an object will remain a true Singlet<strong>on</strong>, i.e., two or more distinct<br />

objects will not be allowed during the decoding process. To deal<br />

with these problems, our mechanism supports an opti<strong>on</strong>al cache<br />

pool to allow the XMLDecoder not to instantiate a new object, but<br />

96

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!