Lorenz: Visitor Beans: An AspectOriented Pattern - PowerPoint PPT Presentation

About This Presentation
Title:

Lorenz: Visitor Beans: An AspectOriented Pattern

Description:

Lorenz: Visitor Beans: An Aspect-Oriented Pattern ... First release: each bean a single Java object. Future releases: beans that are implemented as a set of ... – PowerPoint PPT presentation

Number of Views:62
Avg rating:3.0/5.0
Slides: 23
Provided by: karllie
Category:

less

Transcript and Presenter's Notes

Title: Lorenz: Visitor Beans: An AspectOriented Pattern


1
Lorenz Visitor BeansAn Aspect-Oriented Pattern
  • Aspect-oriented pattern describes a solution to
    a tangling problem in a particular context.

2
AOP control of tangling
  • Demeter/Java controls the following tangling
    problems
  • structure/behavior,
  • navigation/behavior,
  • behavior/behavior,
  • object construction/structure,
  • synchronization/behavior,
  • remote invocation/behavior.

3
Java Bean a Java class
  • Provides methods and events
  • Requires listens to events from other beans
  • pcs.firePropertyChange("n", old, new)

4
Java Beans
  • Software Component Model for Java
  • Introspection what methods and events are
    available. Builder tool can inspect a bean.
  • Support for customization
  • Events for communication between beans

5
Java Beans
  • Three most important features
  • set of properties it exposes
  • set of methods it allows other beans to call
  • set of events it fires
  • event listeners can be associated with event
    source
  • when the event source detects something, it will
    call an appropriate method on the event listener
    object

6
Java Beans
  • Design-time versus run-time. A bean must be
    capable of running in a
  • design environment design information,
    customization (code can be large wizard style
    customization)
  • run-time environment

7
Clear separationdesign-time and run-time aspects
  • Design-time interfaces can be supported in a
    separate class from the run-time interfaces
  • It is possible to deploy a bean at run-time
    without needing to download all its design time
    code

8
Links to remote state
  • Java bean runs in same address space as their
    container
  • Network access mechanisms available
  • Java RMI
  • Java IDL CORBA
  • JDBC Java data base API

9
Alternate type views
  • First release each bean a single Java object
  • Future releases beans that are implemented as a
    set of cooperating objects.
  • Type view represents a view of a bean as a given
    type
  • In future releases different type views of a
    bean may be implemented by different Java objects.

10
Events
Source
Listener
11
Goal
  • Enable discovery of the events that a particular
    class may generate
  • Enable the discovery of the events a class may
    observe
  • Common event registration mechanism for dynamic
    manipulation of relationship between sources and
    listeners

12
Design patternsused with a different meaning
  • The standard design pattern for EventListener
    registration (multicast event source)
  • public void add(
    listener)
  • public void remove (
    listener)
  • should be synchronized methods

13
Java Beans preferred format
  • public PropertyType get()
    // simple getter method
  • public void set(PropertyType var)
    // simple setter method
  • public PropertyType get(int index)
    // indexed getter method
  • public void set(int index,
    PropertyType var) // setter method
  • public PropertyType get()
    // indexed getter method
  • public void set(PropertyType
    var) // indexed setter method

14
Defining events and listeners
  • public class ContainerEventObject extends
    EventObject
  • public interface ContainerListener extends
    EventListener
  • void handleContainerEvent(Conta
    inerEventObject ceo)

15
Listeners for Container bean
  • private Vector containerListeners new Vector()
  • public synchronized void addContainerListener(Cont
    ainerListener l)
  • containerListeners.addElement(l)
  • public synchronized void removeContainerListener(C
    ontainerListener l)
  • containerListeners.removeElement(l)

16
Broadcasting event
  • public void broadcastContainerEvent()
  • Vector l
  • ContainerEventObject ceo new
    ContainerEventObject(this)
  • synchronized(this)
  • l (Vector)containerListeners.clone()
  • for (int i 0 i
  • ContainerListener cl (ContainerListener)
    l.elementAt(i)
  • cl.handleContainerEvent(ceo)

17
Visitor Bean
  • Accept methods use reflection to define a
    traversal visitor!
  • Visit methods Instead of sending a visitor to
    visit an element, the element is fired to the
    visitor as part of an event.

18
In class Visitor
  • public void visit_dispatch(Object o)
  • Class formal new Class1
  • formal0 o.getClass()
  • try
  • Method m getClass().getMethod(visit,
    formal)
  • Object actual new Object1
  • actual0 o
  • m.invoke(this, actual)
  • catch (Exception e)

19
Visit events
  • Visitors report their actions via events
  • event objects may contain visited objects
  • visitors may register as event listeners to other
    visitors
  • Events are typed registration is typesafe

20
VisitEvent
  • Package visitor.beans.event
  • import java.util.EventObject
  • public class VisitEvent extends EventObject
  • protected VisitEvent(Object source, int type,
    Object visited, Object data)
  • super(source)
  • fieldType type
  • fieldVisited visited
  • fieldData data
  • private transient int fieldType 0

21
Visitor kinds
  • Traversal visitors
  • manipulate the visitee part and pass data without
    looking at it
  • Computational visitors
  • pass the visitee untouched and manipulate only
    the data

22
Adaptive Bean visitor style
strategy
in
Local adaptive beans
out
nodes edges enter exit
terminate node edge
Traversal status events (contain objects
traversed)
Write a Comment
User Comments (0)
About PowerShow.com