PPPJ'06 presentation - Aranea

namibiancurrishInternet και Εφαρμογές Web

12 Νοε 2013 (πριν από 3 χρόνια και 7 μήνες)

92 εμφανίσεις

Aranea


Web Framework
Construction

and
Integration

Kit

Jevgeni Kabanov

University of Tartu,
Webmedia, Ltd.,

Estonia

Oleg M
ürk

Chalmers University of
Technology,

Sweden

PPPJ 2006

2

Outline


Introduction


Hello World! In Aranea


Framework construction


Framework integration


Further work

PPPJ 2006

3

Introducing Aranea


An Open
-
Source project available at
http://www.araneaframework.org


A component object model styled
after a variant of Hierarchical MVC
pattern


Reusable components, which can be
assembled into an MVC framework


Note that we are only examining the
Controller

part of MVC!

PPPJ 2006

4

Web is


Procedural (Client calls server)


Synchronized (One window


one
request)


Decomposable into pages


Client is mostly stateless (Current
state with result, cookies)


In general web is based around a
concept of a page, which is combining
data, behavior and presentation

PPPJ 2006

5

GUI applications are


Often stateful


Mostly synchronized (one window


one thread)


Decomposable into components


Comfortable to represent using OO
concepts


Model
-
View
-
Controller pattern
suggest to keep data, presentation
and behavior separately

PPPJ 2006

6

Enter MVC Web Frameworks


Request
-
based: Struts, Spring MVC


Page
-
based: JSF, Wicket, Tapestry


Continuation/flow
-
based: RIFE,
Spring WebFlow


AJAX
-
based: Echo2, GWT





OO
-
based: Wicket, Aranea

PPPJ 2006

7

A Sea of Frameworks


Do we really need all those
approaches?


They play out well for different
requirements


Can we combine them?


We’ll try to do just that



We’ll also hint how to make the existing
frameworks work together…

PPPJ 2006

8

Hello World!

NameWidget

name.jsp

Reads the
name

from
requests and passes it to
HelloWidget

HelloWidget

hello.jsp

Renders the “Hello ${name}!”
greeting, where
name

is given
by the caller.

Note that we need two widgets only for demonstration purposes

PPPJ 2006

9

NameWidget

public

class

NameWidget
extends

BaseUIWidget {


//Called on “hello” event


public

void

handleEventHello() {




却物湧n湡n攠㴠
//reads “name” from request parameters


(String) getInputData().getGlobalData().get("name");




getFlowCtx().replace(
new

HelloWidget(name),
null
);


}

}

<ui:systemForm method="GET">


Insert your name:


<input type=“text“ name="name"/><br/><br/>




<ui:eventButton labelId="#Say hello" eventId="hello"/>

</ui:systemForm>

name.jsp:

PPPJ 2006

10

HelloWidget

public

class

HelloWidget
extends

BaseUIWidget {




private

String name;
//Widget state is in its fields




public

HelloWidget(String name) {




this
.name = name;
//We could pass any Java object here


}




public

String getName() {


return

this
.name;


}

}



Hello <c:out value="${widget.name}"/>!

hello.jsp:

PPPJ 2006

11

Hello World! reexamined

NameWidget

name.jsp

handleEventHello()

HelloWidget

hello.jsp

getFlowCtx().replace(
new
HelloWidget(name));

Note that we can pass any Java object to the widget constructor,

enabling e.g. polymorphism

PPPJ 2006

12

Framework construction


Components are
assembled in a chain


Only 3 component
kinds (components,
services & widgets)


Some components
may contain more
than one child


Servlet
: only
dispatches the HTTP
call to adaptor

PPPJ 2006

13

Component

interface

Component {


void

init(Environment env);


void

destroy();

}

PPPJ 2006

14

Service


Services correspond to the procedural
unsynchronized HTTP model


Unlike servlets no binding or
configuration specified

interface

Service
extends

Component {


void

action(


Path path,
//Routing destination for Composite case


InputData input,
//Request abstraction


OutputData output);
//Response abstraction

}

PPPJ 2006

15

SynchronizingFilterService


Synchronizes the underlying calls


In reality childService is handled by the
base class (BaseFilterService)

public

class

SynchronizingFilterService
extends

BaseService {


protected

Service childService;


public

void

setChildService(Service childService) {


this
.childService = childService;


}


synchronized

void

action(



Path path, InputData input, OutputData output) {


childService.action(path, input, output);


}

}

PPPJ 2006

16

Environment


Environment allows parents to let
children access their features

interface

Environment {


Object getEntry(Object key);

}

L10nContext locCtx = (L10nContext)


getEnvironment().getEntry(L10nContext.
class
);

String message = locCtx.localize("message.key");

Usage example:

PPPJ 2006

17

LocalizationFilterService


Provides localization features

public

class

LocalizationFilterService


extends

BaseFilterService
implements

L10nContext {


public

void

init(Environment env) {


childService.init(


new

StandardEnvironment(env, L10nContext.
class
,
this
);


}



public

String localize(String key) {


//Look up a ResourceBundle and return the message


}

}

PPPJ 2006

18

SessionRouterService


Routes the action() to a service
associated with the HTTP session


Creates new services using a service
factory (assigned via setter)

public

class

SessionRouterService
extends

BaseService {


void

action(Path p, InputData input, OutputData output) {


HttpSession sess = …
//Lookup logic


if

(sess.get(SERVICE_KEY) ==
null
)


createService(sess);
//Build service using factory


((Service) sess.get(SERVICE_KEY)).action(p, input, output);


}

}

PPPJ 2006

19

Half of a framework


Service adaptor
:
creates Input
-

&
OutputData


Session router
:
saves service chain
under itself in session


Synchronizing filter
:
protects session state
from concurrent
modification


HTTP filter
: sets
headers

PPPJ 2006

20

Widget


Widget corresponds to a stateful
synchronized GUI model


Most applications are built from
widgets

interface

Widget extends Service {


//Calls must be made in the same order:


void

update(InputData data);
//Sent to all widgets


void

event(Path path, InputData input);
//Routed to one widget


void

process();
//Preparing to render



void

render(OutputData output); //May be called several times

}

PPPJ 2006

21

Flows


Flows are pages which preserve
nested state and can return values

PPPJ 2006

22

Flows examined


Flow container is a widget that contains a
stack of widgets representing flows


Being a usual widget flow container can be
used at an arbitrary place in framework or
application

public

interface

FlowContext {


void

start(Widget flow, Handler handler);


void

replace(Widget flow)


void

finish(Object result);


void

cancel();

}

PPPJ 2006

23

And the final touch


Widget adapter
:
calls update(),
event(), process()
and render() for
each action() call


Widget container
:
creates Path for
event routing


Flow container
:
provides
FlowContext and a
widget stack

PPPJ 2006

24

Other configurations


We can assemble a system to bind
stateless services to URLs like Struts
actions


We can also assemble a system that
will bind stateful widgets to URLs like
Wicket pages


In fact it is easy to simulate all of the
mentioned approaches

PPPJ 2006

25

Integration


To integrate third
-
party components in
Aranea we wrap them in a service or widget
and simulate their API


To integrate Aranea in a third
-
party
framework we just simulate component API
and Environment


We also can use Aranea as glue among
framework components


This is possible thanks to well
-
defined and
tiny core API

PPPJ 2006

26

Summary


A HMVC component model


A modular web framework supporting
all common GUI approaches


A platform for web framework
development and research


An Object
-
Oriented web framework
with support for first
-
class flows


A web framework integration platform

PPPJ 2006

27

Further work


Remote integration
: a service protocol
with Environment over Web Services


Weaver
: templating framework compatible
with JSP tags, Wicket markup, JSF
components, Facelets, …


Blocking continuation support


Integration with Wicket, JSF, Struts, Spring
MVC & WebFlow, Echo2, GWT …


Aranea for rich client (Eclipse RCP)

PPPJ 2006

28

Questions?

Thank you!

www.araneaframework.org