Ira R. Forman, Nate Forman9781932394184, 1-932394-18-4
Table of contents :
Java Reflection in Action……Page 1
contents……Page 8
preface……Page 14
acknowledgments……Page 16
about this book……Page 18
about the title……Page 21
about the cover illustration……Page 22
A few basics……Page 24
1.1 Reflection’s value proposition……Page 26
1.2 Enter George the programmer……Page 27
1.2.1 Choosing reflection……Page 28
1.2.2 Programming a reflective solution……Page 29
1.3 Examining running programs……Page 31
1.4 Finding a method at runtime……Page 33
1.5 Representing types with class objects……Page 35
1.5.2 Representing interfaces……Page 36
1.6 Understanding method objects……Page 37
1.6.1 Using dynamic invocation……Page 38
1.6.2 Using primitives with dynamic invocation……Page 39
1.6.3 Avoiding invocation pitfalls……Page 40
1.7 Diagramming for reflection……Page 42
1.8 Navigating the inheritance hierarchy……Page 43
1.8.1 Introspecting the inheritance hierarchy……Page 45
1.8.2 Exposing some surprises……Page 46
1.8.3 Another reflective circularity……Page 47
1.9 Summary……Page 49
Accessing fields reflectively……Page 50
2.1 Serializing objects……Page 51
2.1.1 Serializing to XML……Page 52
2.1.3 Designing serialization with reflection……Page 53
2.2 Finding fields at runtime……Page 54
2.3 Understanding field objects……Page 56
2.4 Getting and setting field values……Page 57
2.5 Examining modifiers……Page 58
2.5.1 Introducing Member……Page 59
2.5.3 Introspecting for instance variables……Page 60
2.6 Accessing nonpublic members……Page 61
2.7 Working with arrays……Page 63
2.8 Serialization: putting it all together……Page 64
2.8.2 Serializing instance variables……Page 66
2.9 Using reflective serialization……Page 68
2.10 Summary……Page 71
Dynamic loading and reflective construction……Page 72
3.1 George’s deployment problem……Page 73
3.1.1 Designing with patterns……Page 74
3.1.2 Programming a reflective solution……Page 75
3.1.4 Combining benefits of delegation and reflection……Page 77
3.2.1 Basics of forName……Page 78
3.2.3 Primitives and forName……Page 79
3.3.2 Using constructor objects……Page 80
3.3.3 Constructing arrays reflectively……Page 82
3.4 Designing for dynamic loading……Page 83
3.4.1 Disadvantages of reflective construction with arguments……Page 84
3.4.2 Initializing through an interface……Page 85
3.5 Implementing deserialization……Page 86
3.5.1 Initiating deserialization……Page 87
3.5.2 Constructing the instances……Page 88
3.5.3 Restoring the object structure……Page 89
3.6.1 No interaction with readObject or writeObject……Page 92
3.6.4 No handling of illegal XML characters……Page 93
3.7 Summary……Page 94
Using Java’s dynamic proxy……Page 96
4.1 Working with proxies……Page 97
4.2 George’s tracing problem……Page 99
4.3 Exploring Proxy……Page 100
4.3.1 Understanding invocation handlers……Page 102
4.3.2 Handling the methods of Object……Page 103
4.4 Implementing a tracing proxy……Page 104
4.5 A note on factories……Page 107
4.6.1 Structuring invocation handlers for chaining……Page 109
4.6.2 Implementing a synchronized proxy……Page 111
4.6.3 Chaining the two proxies……Page 112
4.7.1 Examining stubs……Page 113
4.7.2 Design for stubbing with Proxy……Page 114
4.7.3 Implementation of stubbing with Proxy……Page 116
4.8 Generating SOAP remote proxies……Page 122
4.9 Pitfalls of using Proxy……Page 126
4.10 Summary……Page 128
Call stack introspection……Page 130
5.1 George’s logging problem……Page 131
5.2 Performing call stack introspection……Page 134
5.3 Logging with call stack introspection……Page 135
5.4 Pitfalls……Page 137
5.5 Class invariant checking……Page 138
5.6 Summary……Page 143
Using the class loader……Page 144
6.1 George’s test problem……Page 145
6.2.1 Understanding the delegation model……Page 146
6.2.2 Programming a simple class loader……Page 150
6.2.3 Reinitializing static fields: a solution……Page 151
6.3 Multiple namespaces……Page 153
6.4.1 Designing for replacement……Page 155
6.4.2 Implementing replacement……Page 157
6.4.3 Simplifying assumptions……Page 160
6.5 Additional considerations……Page 161
6.5.2 Don’t reinvent the wheel……Page 162
6.5.4 When not to invent a specialized class loader……Page 163
6.5.5 Additional examples……Page 164
6.6 Summary……Page 165
Reflective code generation……Page 166
7.1 Generating HelloWorld.java……Page 168
7.2 Class-to-class transformation framework……Page 170
7.2.1 C2C……Page 171
7.2.2 Args……Page 175
7.2.3 C2CConstructor……Page 177
7.2.4 C2CTransformation……Page 180
7.3 Example: extent management……Page 182
7.4 C2IdentitySubclassOfC and its subclasses……Page 191
7.5 UQueue……Page 193
7.6 Using the framework……Page 196
7.7 Relation to Aspect-Oriented Programming……Page 198
7.8 Summary……Page 199
Design patterns……Page 202
8.1 Singleton……Page 204
8.2 Decorator class-to-class transformations……Page 210
8.3 Proxy (again)……Page 220
8.5 Problematic issues in writing class-to-class transformations……Page 224
8.6 Summary……Page 227
Evaluating performance……Page 230
9.1 Categorizing performance impact……Page 232
9.2 Using microbenchmarks……Page 233
9.3 Benchmarking two ways to use Proxy……Page 237
9.4 Understanding Amdahl’s Law……Page 241
9.5 Applying Amdahl’s Law……Page 244
9.6 Summary……Page 246
Reflecting on the future……Page 248
10.1 Looking forward: Java 1.5……Page 249
10.1.1 JSR 14-Generics……Page 250
10.1.2 JSR 175-Annotation Facility……Page 252
10.1.3 JSR 201-Language extensions……Page 257
10.1.4 Impact of Java 1.5 on reflective code……Page 258
10.2.3 Smalltalk……Page 259
10.3 Looking forward: Aspect-Oriented Programming……Page 260
10.4 Looking forward: your career……Page 261
Reflection and metaobject protocols……Page 264
A.1 Reflection……Page 265
A.2 Reflective object-oriented programming……Page 267
A.3 Inheritance……Page 269
A.4 Metaobject protocols……Page 271
A.5 Metaclasses……Page 272
A.6 Class-to-class transformations……Page 274
Handling compilation errors in the “Hello world!” program……Page 276
UML……Page 279
glossary……Page 281
references……Page 283
index……Page 290
Reviews
There are no reviews yet.