Preface

This book focuses on getting things done with AspectJ. Aspect-Oriented Software Development (AOSD) is a new branding for some old ideas incorporating an object-oriented twist. This rather complex definition really sums up what is a neat approach to solving some traditional object orientation’s problems.

While this book does not get into too much detail on the theory behind aspect orientation, a brief overview is provided to give you a useful foundation to support the code recipes that form the rest of the book. The code recipes will walk you through how to get your system set up for aspect oriented development, building your first small programs, and eventually applying aspect orientation to complex real-world problems.

This book aims to be one of those useful books that sit on your desk and regularly get called upon to “just show me how to do that.” You should be able to jump directly to the recipes you need as and when you need them in keeping with the “no fluff, just stuff” approach that is synonymous with the O’Reilly Cookbook series. With this in mind, the topics covered in this book include:

  • A brief overview of aspect orientation and AspectJ

  • Setting up, getting to grips with, and running AspectJ programs in a range of build and target environments

  • A practical examination of each of the AspectJ extensions to the Java© language

  • Applying AspectJ to real-world software development problems that benefit from an aspect-oriented approach

Audience

While it will probably suffice to say that this book is for any person interested in learning about AspectJ and aspect orientation, this book will most benefit people who are fairly experienced with object-oriented design, particularly when implemented in Java. Anyone that is open to a fresh approach to solving some of the problems that traditional object orientation suffers from should find something in this book that encourages them to try AspectJ in their own applications.

About This Book

This book covers the following subjects:

  • An overview of the elements of aspect orientation using AspectJ, pointcuts, join points, and advice

  • Setting up your environment and getting started with AspectJ development

  • Running AspectJ based software in various environments

  • Deploying your AspectJ applications to varying target environments

  • How to use the various forms of pointcut supported by AspectJ

  • How to use the various forms of advice available in AspectJ

  • Controlling how aspects are created and destroyed

  • Changing the static structure of your software and support tools using AspectJ

  • Enhancing existing object-oriented design pattern implementations using AspectJ

  • Applying aspects to real-world problems within component, system, and enterprise domains

Rarely is a cookbook read from cover to cover, but an overview of each section’s focus is useful in order to understand each chapter’s place and what it is building towards. This cookbook is organized into four broad sections, as shown in Figure P-1.

What each set of chapters within this book intends to show
Figure P-1. What each set of chapters within this book intends to show

Chapter 1 through Chapter 3 provide a set of recipes to get you started with the tools and environments that support development using AspectJ. These chapters cover how to use command-line tools, Eclipse, even ANT to develop your aspect-oriented applications, and finish up by showing you how to deploy to diverse target environments such as Java Servlets, Java Server Pages, and web services.

Chapter 4 through Chapter 16 provide in-depth syntactical examinations of the AspectJ language. These chapters aim to give you a useful and exhaustive reference for how to use the different constructs that the AspectJ language adds to Java.

Chapter 17 through Chapter 23 are where AspectJ really gets to showcase its advantages over traditional object-oriented software implementations. In these chapters, Aspects are used to enhance and improve the design of software solutions ranging from design pattern implementations to enterprise applications. Chapter 23 brings this book to a close by introducing some of the aspect-oriented design patterns that are gradually being discovered as tools, such as AspectJ, bringing aspect orientation into the mainstream of software development.

Now that you know what this book is about, it should be explained what this book is not about. As mentioned before, this book is not a theoretical examination of AspectJ. The code is kept at the fore throughout to make sure that every area has a practical focus. There are many great articles online and gradually appearing in the press that examine the more theoretical concerns of AO, so this book does not attempt to deal with these.

This book is also not claiming to be AspectJ in a nutshell. AspectJ is in a very stable state for such a young implementation, but even now extensions to the language and the technologies are being considered, so it is possible that some areas of this book may age faster than others. In an attempt to ensure that this book has the longest life possible, only the most stable areas that were incorporated at the time of writing were included.

Assumptions This Book Makes

The following assumptions are made about your knowledge and experience with the supporting tool, languages, and concepts that accompany aspect-oriented development:

  • That you have a reasonably advanced knowledge of the Java language

  • That you have an existing Java Source Development Kit (SDK) on your system, at a minimum JSDK 1.2 and preferably 1.4+

  • That you have some understanding and experience of Java Server Pages, Java Servlet, and Web Services (specifically Apache Axis) programming

  • That you have some knowledge of UML (useful but not essential to understanding the diagrams)

Conventions Used in This Book

The following typographical conventions are used in this book:

Plain text

Indicates menu titles, menu options, menu buttons, and keyboard accelerators (such as Alt and Ctrl).

Italic

Indicates new terms, URLs, email addresses, filenames, file extensions, pathnames, directories, and Unix utilities.

Constant width

Indicates commands, options, switches, variables, attributes, keys, functions, types, classes, namespaces, methods, modules, properties, parameters, values, objects, events, event handlers, XML tags, HTML tags, macros, the contents of files, or the output from commands.

Constant width bold

Shows commands or other text that should be typed literally by the user.

Constant width italic

Shows text that should be replaced with user-supplied values.

Tip

This icon signifies a tip, suggestion, or general note.

Warning

This icon indicates a warning or caution.

Using the Code Examples

This book is here to help you get your job done. In general, you may use the code in this book in your programs and documentation. You do not need to contact us for permission unless you’re reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from O’Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product’s documentation does require permission.

We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: "AspectJ Cookbook by Russ Miles. Copyright 2005 O’Reilly Media, Inc., 0-596-00654-3.”

If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at .

We’d Like to Hear from You

We at O’Reilly have done everything to insure that the recipes within this book are tested and verified to the best of the author’s ability. However, AspectJ is a fast moving technology and it may be that some features of the supporting toolsets or of the language itself have changed, or that we have simply made mistakes. If so, please address comments and questions concerning this book to the publisher:

O’Reilly Media, Inc.
1005 Gravenstein Highway North
Sebastopol, CA 95472
(800) 998-9938 (in the United States or Canada)
(707) 829-0515 (international or local)
(707) 829-0104 (fax)

We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at:

http://www.oreilly.com/catalog/aspectjckbk

To comment or ask technical questions about this book, send email to:

For more information about our books, conferences, Resource Centers, and the O’Reilly Network, see our web site at:

http://www.oreilly.com

Safari Books Online

image with no caption

When you see a Safari® icon in your favorite technology book, that means the book is available online through Safari Books Online.

Safari offers a solution that’s better than e-Books. It’s a virtual library that lets you easily search thousands of top tech books, cut and paste code samples, download chapters, and find quick answers when you need the most accurate, current information. Try it free at http://safaribooksonline.com.

Acknowledgments

Never has so much been owed to so few...or something like that anyway. This book was written by one person but supported by more than I can possibly remember to mention here, so I’ll apologize up front if anyone’s missed out; I’ve not forgotten you. It’s just that I was trying (but failed) to avoid an Oscar speech.

Here is where I get an opportunity to thank the people that kept me focused and supported me through the writing of my first book. First and foremost in all things has to be my family. Thanks to Mum and Dad, who have seen me through the hardest of times with limitless smiles, warmth, and understanding. Thanks to Bobs, Rich, Ad, and even Aimee, who have always been there to keep me on the straight and narrow. You all helped me get this project complete and keep my feet on the ground when I needed it most, and for that I cannot ever thank you enough, but I’ll have fun trying.

Thanks to my editor Brett McLaughlin and all at O’Reilly who saw me through my complete naïveté over the proposal and writing process and for working so hard to get this book out. A heartfelt thanks to Rob Romano for putting up with my “there will only be a small number of figures” optimism at the beginning of the project. Honestly, Rob, I really did think there would only be a few!

Thanks to the true heroes of AspectJ, the AspectJ community. In particular thanks go to Adrian Colyer, George Harley, Matthew Webster, Mik Kersten, and Wes Isberg for making AspectJ such a great implementation. To all involved on the aTrack project headed up by Ron Bodkin for providing so many interesting and useful presentations and such an impressive test bed for many of the concepts expressed in the recipes in this cookbook, and to Ramnivas Laddad for his expert and friendly advice.

Thanks to my team of dedicated, and patient, proofreaders. To Laura Paterson for being so supportive in the very early days when this book was just something I really wanted to do. Without your help and expertise I doubt this project would have gotten past the propsal stage. Also, thanks to Andy (Tiger) Winter, Rob Wilson, and Grant Tarrant-Fisher for being on the receiving end of my enthusiasm on aspect orientation and not going completely nuts. Together, you all make up the best bunch of people I’ve ever had the pleasure to work with.

Thanks to all in the Oxford University software engineering programme that gave each and every recipe the thorough critique it needed; especially Ganesh Sitamplan for the language input, Peet for the beginners touch, and Jeremy Gibbons for getting the whole process rolling.

Thanks go to my friends who all knew when to be there and when to leave me alone during the long days and nights as I worked and re-worked this book, and that takes real skill from some of the best people I’ve been fortunate enough to meet. A huge thank you goes to Jo Westcott, Sam and Martin, Jason, and Kerry. Special thanks to Jason for asking, when first told of my aim to write a book, if the book would be made into a film (I truly hope not!).

Finally, I’d like to thank Kim. You have meant so much to me in the past year and you have contributed more than anyone else to this book. Despite my best efforts to completely ruin your grammar skills, you have stuck with me and been the best of friends as well as so much more than that. Thanks alone will never be enough for all the happiness you bring me, and it’s a debt I look forward to repaying for many years to come.

Last but not least, a quick catch-all to thank everyone who has helped me out while writing this book. I haven’t forgotten your help and I know I owe you all a beer or two!

Get AspectJ Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.