Java Reference
In-Depth Information
CDI Model.java
public
public class
class Model
Model {
public
public @Produces @MyModel String getModelData ( InjectionPoint ip )
throws
throws IOException {
ResourceBundle props = ResourceBundle . getBundle ( "messages" );
return
return props . getString (
ip . getMember (). getDeclaringClass (). getSimpleName () + "." +
ip . getMember (). getName ());
}
}
See Also
Spring DI, Java EE CDI, and Guice all provide powerful “dependency injection.” Spring's is
more widely used; Java EE's is more powerful. All work standalone and inside web applica-
tions, with minor variations; in the EE, Spring provides special support for web apps, and in
EE containers, CDI is already set up so the first statement in the CDIMain statement is not
needed in an EE app. There are many books on Spring. One book specifically treats Weld:
JBoss Weld CDI for Java Platform by Ken Finnegan (O'Reilly).
Program: Plotter
Not because it is very sophisticated, but because it is simple, this program serves as an ex-
ample of some of the things we've covered in this chapter, and also, in its subclasses,
provides a springboard for other discussions. This class describes a series of old-fashioned
(i.e., common in the 1970s and 1980s) pen plotters. A pen plotter, in case you've never seen
one, is a device that moves a pen around a piece of paper and draws things. It can lift the pen
off the paper or lower it, and it can draw lines, letters, and so on. Before the rise of laser
printers and ink-jet printers, pen plotters were the dominant means of preparing charts of all
sorts, as well as presentation slides (this was, ah, well before the rise of programs like Har-
vard Presents and Microsoft PowerPoint). Today, few, if any, companies still manufacture
pen plotters, but I use them here because they are simple enough to be well understood from
this brief description. Today's “3-D Printers” may be thought of as representing a resurgence
of the pen plotter with just one additional axis of motion. And a fancier pen.
Search WWH ::




Custom Search