Tellurium Tutorial Series: Tellurium UiDslParser - What is the "ui."

3 views
Skip to first unread message

John.Ji...@gmail.com

unread,
Oct 6, 2008, 10:54:45 PM10/6/08
to tellurium-users
Very often, you will see the "ui." symbol when you define Tellurium UI
modules, for instance, look at the following famous Google start page
UI module

ui.Container(uid: "google_start_page", clocator: [tag: "td"],
group: "true"){
InputBox(uid: "searchbox", clocator: [title: "Google
Search"])
SubmitButton(uid: "googlesearch", clocator: [name: "btnG",
value: "Google Search"])
SubmitButton(uid: "Imfeelinglucky", clocator: [value: "I'm
Feeling Lucky"])
}

If you have ever read the Tellurium core code, you will find the
following line in the BaseDslContext class,

UiDslParser ui = new UiDslParser()

That is to say, the ui is actually an instance of UiDslParser. On the
above UI module, you actually call the method "Container" on
UiDslParser with a map of attributes, plus a Closure with nested code.

{
InputBox(uid: "searchbox", clocator: [title: "Google
Search"])
SubmitButton(uid: "googlesearch", clocator: [name: "btnG",
value: "Google Search"])
SubmitButton(uid: "Imfeelinglucky", clocator: [value: "I'm
Feeling Lucky"])
}

Look at what the UiDslParser actually does from the source code

class UiDslParser extends BuilderSupport{

def registry = [:]

def UiObjectBuilderRegistry builderRegistry = new
UiObjectBuilderRegistry()

protected Object createNode(Object name) {
}

....
}

That is to say, the UiDslParser extends the Groovy BuilderSupport
class and works as a parser for what ever you passed in starting from
"Container(uid: "google_start_page", clocator: [tag: "td"], group:
"true")" for the above example.

You may notice that the BuilderSupport class needs to handle couple
call back methods such as,

protected Object createNode(Object name)
protected Object createNode(Object name, Object value)
protected Object createNode(Object name, Map map)
protected Object createNode(Object name, Map map, Object value)
protected void nodeCompleted(Object parent, Object node)
protected void setParent(Object parent, Object child)

If you are familiar with XML parser, you will see that this is really
similar with XML PUSH style parser. You need to define call back
methods and the parser will parse the message to the end
automatically.

The above callback methods are doing the similar thing, i.e., to
create a UI object when it sees the name like "Container", "InputBox",
and "SubmitButton". The different createNode methods are used for
different use cases. I would not go over the details here. If you are
interested, please see the UiDslParser class and the Groovy doc for
BuilderSupport class.

Basically, what the UiDslParser does is to get the object name such as
"Container" and then look at the UI builder registry to find the
builder for that object, then use the builder to build that UI object.
The UI builder registry is a hash map and you can find the Container
builder by the object name "Container".

Also the UiDslParser will keep the parse results, i.e., UI objects in
a registry so that you can refer them by UID like
"google_start_page.searchbox", The object link is handled by the
setParent method.
Reply all
Reply to author
Forward
0 new messages