Chapter 10. XML Deployment DescriptorsContents:
What Is an XML Deployment Descriptor?
10.1. What Is an XML Deployment Descriptor?One of the biggest changes between EJB 1.0 and 1.1 is the introduction of XML deployment descriptors. In EJB 1.0, deployment descriptors were serialized Java objects; you wrote a program that set up an appropriate DeploymentDescriptor, and then serialized that object. This approach was clumsy at best, even for experienced developers. XML deployment descriptors are much easier to edit, even without special tools for editing XML files. An XML deployment descriptor is simple enough that it's easy to create a descriptor using nothing more than your favorite text editor, be it Notepad, Emacs, or vi. This chapter discusses what goes into an XML deployment descriptor; it teaches you how to write deployment descriptors for your beans. Keep in mind that you may never need to write a deployment descriptor by hand; most vendors of integrated development tools and EJB servers will provide tools for creating the descriptor automatically. Even if you have such a tool available, however, you should be familiar enough with deployment descriptors to be able to read them on your own. This chapter doesn't attempt to teach you how to read or write correct XML. There are many books on the subject; a good quick reference is XML Pocket Reference by Bob Eckstein (O'Reilly). Very briefly, XML looks like HTML, but with different tag names and different attributes inside the tags. You won't see <h1> and <p> inside a deployment descriptor; you'll see tags like <ejb-jar>. But otherwise, if you expect an XML document to look like HTML, you're most of the way toward reading it. The tag names and attribute names for an XML document are defined by a special document called a DTD (Document Type Definition). Therefore, for XML deployment descriptors, there is a DTD that defines the tags and attributes that can be used in the document; the DTD for EJB 1.1 deployment descriptors is available online at http://java.sun.com/j2ee/dtds/ejb-jar_1_1.dtd. There are a few other important differences between XML and HTML. XML is much more strict; many things that are acceptable in HTML are errors in XML. This shouldn't make a difference if you're just reading a deployment descriptor, but if you're writing one, you have to be careful. Two differences are particularly important: XML is case sensitive. You can't mix upper- and lowercase in your tag names. HTML doesn't care about the difference between <h1> and <H1>, but XML does. All of the tags and attributes used in deployment descriptors are lower case. In addition, XML will not forgive you if you don't supply closing tags. In HTML, it was okay to write <p>...<p>, without ever putting in </p> to end the paragraph. XML never allows you to be sloppy. Whenever you have a tag, there must always be a closing tag. And that's about it. These few paragraphs don't even qualify as a quick introduction to XML, but the basic ideas are very simple, and that's really all you should need to get going. Copyright © 2001 O'Reilly & Associates. All rights reserved. |
|