AspectJ Syntax Basics.

Slides:



Advertisements
Similar presentations
AspectWerkz 2 - and the road to AspectJ 5 Jonas Bonér Senior Software Engineer BEA Systems.
Advertisements

OO Programming in Java Objectives for today: Overriding the toString() method Polymorphism & Dynamic Binding Interfaces Packages and Class Path.
Chapter 13 - Inheritance. Goals To learn about inheritance To learn about inheritance To understand how to inherit and override superclass methods To.
Secure Systems Research Group - FAU Aspect Oriented Programming Carlos Oviedo Secure Systems Research Group.
Inheritance Part I. Lecture Objectives To learn about inheritance To understand how to inherit and override superclass methods To be able to invoke superclass.
Introduction to Object-Oriented Programming CS 21a: Introduction to Computing I First Semester,
Overview of AspectJ Aspect Oriented Software Development Seminar Technion presented by Oren Mishali.
Road Map Introduction to object oriented programming. Classes
AspectWerkz Dynamic AOP For Java David Rabinowitz.
Terms and Rules Professor Evan Korth New York University (All rights reserved)
CS 2511 Fall  Abstraction Abstract class Interfaces  Encapsulation Access Specifiers Data Hiding  Inheritance  Polymorphism.
Inheritance using Java
Programming Languages and Paradigms Object-Oriented Programming.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009.
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
1 Identifiers  Identifiers are the words a programmer uses in a program  An identifier can be made up of letters, digits, the underscore character (
Java Language and SW Dev’t
Spring core v3.x Prepared by: Nhan Le. History v3.0 Spring Expression Language Java based bean metadata v3.1 Cache Abstraction Bean Definition Profile.
Session 2: AspectJ Mark Stobbe September 13,
COP INTERMEDIATE JAVA Designing Classes. Class Template or blueprint for creating objects. Their definition includes the list of properties (fields)
Polymorphism, Inheritance Pt. 1 COMP 401, Fall 2014 Lecture 7 9/9/2014.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
1 Chapter 8 – Classes and Object: A Deeper Look Outline 1 Introduction 2 Implementing a Time Abstract Data Type with a Class 3 Class Scope 4 Controlling.
A Survey on Java Modeling Languages Gergely Kovásznai,Eszterházy Károly College Wolfgang Schreiner,Johannes Kepler University Gábor Kusper,Eszterházy Károly.
1 final (the keyword, not the exam). 2 Motivation Suppose we’ve defined an Employee class, and we don’t want someone to come along and muck it up  E.g.,
Introduction to Java Java Translation Program Structure
Features of AOP languages AOP languages have the following main elements: –a join point model (JPM) wrt base PL –a specification language for expressing.
Understanding class definitions
Inter-Type Declarations in AspectJ Awais Rashid Steffen Zschaler © Awais Rashid, Steffen Zschaler 2009.
AspectJ – AOP for Java Tom Janofsky. Instructor at Penn State Abington Consultant with Chariot Solutions JUG Member.
Course Progress Lecture 1 –Java data binding: Basket example: UML class diagram -> class dictionary without tokens-> language design -> class dictionary.
Demeter Aspects We study techniques for the emerging area of Aspect-Oriented Software Development and focus on the following areas:  Aspectual Collaborations.
Applying Translucid Contracts for Modular Reasoning about Aspect and Object Oriented Events Mehdi Bagherzadeh Gary T. Leavens Robert Dyer Foundations of.
Aspect Oriented Development Alex Beatty.  Purpose  Cross-cutting Concerns  Join Points, Pointcuts, and Advices  Weaving  Invasive vs. Non-Invasive.
Object Oriented Programming
1 COSC2007 Data Structures II Chapter 9 Class Relationships.
Copyright by Scott GrissomCh 2 Class Definition Slide 1 Class Structure public class BankAccount{ fields constructor(s) methods } Sample Code Ticket Machine.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Comparison of Different AOP Approaches Presented by: Xiaojing Wang.
Generating Aspect Code from Models OOPSLA 2002 Workshop on Generative Techniques in the Context of the MDA November 5 th, 2002 Seattle, WA This work is.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
CSC450 Software Engineering Devon M. Simmonds University of North Carolina, Wilmington 1.
FEN 2014UCN Teknologi/act2learn1 Object-Oriented Programming “ The Three Pillars of OOP”: Encapsulation Inheritance Polymorphism The Substitution Principle.
Object Oriented Programming and Data Abstraction Rowan University Earl Huff.
SCoPE: an AspectJ Compiler for Supporting User-Defined Analysis-Based Pointcuts Tomoyuki Aotani Hidehiko Masuhara
AOP with AspectJ Awais Rashid, Steffen Zschaler © Awais Rashid, Steffen Zschaler 2009.
1 Karel – Chapter 6 Instructions That Repeat Note: Original slides provided by and modified for Mr. Smith’s AP Computer Science.
Features of AOP languages AOP languages have the following main elements: –a join point model (JPM) wrt base PL –a specification language for expressing.
Comp1004: Building Better Objects I Methods. Coming up Methods and Parameters – Why Parameterise? – Call by value, call by reference Return Types – Methods.
Polymorphism and access control. RHS – SOC 2 What is polymorphism? In general: the ability of some concept to take on different forms In Java: the ability.
Conclusão Parte 1 – Qualidade de Software por Construção Alessandro Garcia © Alessandro Garcia, 2016 Departamento de Informática.
Modern Programming Tools And Techniques-I
Review Session.
Polymorphism Lec
public class BankAccount{
CLASS DEFINITION (> 1 CONSTRUCTOR)
Understanding class definitions
null, true, and false are also reserved.
Interface.
Polymorphism and access control
Aspect Oriented Programming
Recap Week 2 and 3.
Understanding class definitions
JAVA CLASSES.
CIS 199 Final Review.
C++ Programming CLASS This pointer Static Class Friend Class
Chap 2. Identifiers, Keywords, and Types
Chapter 13 Abstract Classes and Interfaces Part 01
Presentation transcript:

AspectJ Syntax Basics

Identify Join Points 1 public class Bit { 2 bool value; 3 void Set() { 4 value = true; 5 } 6 void Clear() { 7 value = false; 8 } 9 void Toggle { 10 if(Get()) Set(); 11 else clear(); 12 } 13 void Get() { 14 return value; 15 } 16 }

Pointcuts Named pointcut AllCall(): call( * *(..)); Anonymous before(): call( * *(..)) { … }

Named Pointcut Syntax [access specifier] pointcut pointcut- name([args]): pointcut definition

Why Named Pointcuts? Pointcut Reuse Separation of two specifications: Where additional behavior is to be applied? What is the additional behavior? Late Binding of Design Decisions

Pointcut Reuse & Separation public pointcut StringArg(String s): execution( * *(..)) && args(s); around(String s): StringArg(s) { /* Omit execution if null argument */ } /* Omit execution if not valid XML */ }

Late Binding abstract aspect Lock { pointcut CriticalSections(); before(): CriticalSections() { /* Acquire lock */ } after(): CriticalSections() { /* Release lock */

Late Binding … aspect BufferLock extends Lock { pointcut CriticalSections(): call(* * Buffer.Write(..)); }

Poincut composition pointcut1 && pointcut2 pointcut1 || pointcut2

Signatures Type Signatures Method Signatures Field Signatures

Example Type Signature javax..*Model+ Any sub-type of a given type Any number of characters including period Any number of characters excluding the period

Exercise 1 Write down the type signature to pick out only the sub-types of all the types in the javax package or its direct and indirect subpackages that have a name ending in Model.

Example Method Signature * javax..*.add*Listener(EventListener+)

Example Field Signature !public static * banking..*.*

Cflow and Cflowbelow Cflow (Pointcut) - Captures all join points in the control flow of the join points matched by the specified pointcut, including the join points themselves. Cflowbelow(Pointcut) – Excludes the matching join points, matches everything below.

cflow( execution Account.debit(..)) 1 void debit(int amount) { 2 if( this.getBalance() > amount) { 3 this.setBalance( this.getBalance() – amount); 4 } 5 int getBalance() { 6 return db.Query(name, “balance”); 7 } 8 int setBalance(int balance) { 9 db.Update(name, “balance”, balance); 10 }

Lexical Pointcuts within( type pattern ) withincode( method or constructor pattern)

Identify matches within(Bit) 1 public class Bit { 2 bool value; 3 void Set() { 4 value = true; 5 } 6 void Clear() { 7 value = false; 8 } 9 void Toggle { 10 if(Get()) Set(); 11 else clear(); 12 } 13 void Get() { 14 return value; 15 } 16 }

withincode(* * Bit.*et(..)) 1 public class Bit { 2 bool value; 3 void Set() { 4 value = true; 5 } 6 void Clear() { 7 value = false; 8 } 9 void Toggle { 10 if(Get()) Set(); 11 else clear(); 12 } 13 bool Get() { 14 return value; 15 } 16 }