1. Trang chủ
  2. » Công Nghệ Thông Tin

Teach Yourself J2EE in 21 Days phần 1 pdf

108 430 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 108
Dung lượng 677,73 KB

Nội dung

201 West 103rd St., Indianapolis, Indiana, 46290 USA Martin Bond Dan Haywood Debbie Law Andy Longshaw Peter Roxburgh J2EE in 21 Days Teach Yourself 00 0672323842 FM 3/20/02 9:31 AM Page i Sams Teach Yourself J2EE in 21 Days Copyright  2002 by Sams Publishing All rights reserved. No part of this book shall be reproduced, stored in a retrieval system, or transmitted by any means, electronic, mechanical, photo- copying, recording, or otherwise, without written permission from the publish- er. No patent liability is assumed with respect to the use of the information contained herein. Although every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions. Nor is any liability assumed for damages resulting from the use of the information contained herein. International Standard Book Number: 0-672-32384-2 Library of Congress Catalog Card Number: 2001098579 Printed in the United States of America First Printing: April, 2002 03020100 4321 Trademarks All terms mentioned in this book that are known to be trademarks or service marks have been appropriately capitalized. Sams Publishing cannot attest to the accuracy of this information. Use of a term in this book should not be regarded as affecting the validity of any trademark or service mark. Warning and Disclaimer Every effort has been made to make this book as complete and as accurate as possible, but no warranty or fitness is implied. The information provided is on an “as is” basis. The authors and the publisher shall have neither liability nor responsibility to any person or entity with respect to any loss or damages aris- ing from the information contained in this book. EXECUTIVE EDITOR Michael Stephens MANAGING EDITOR Matt Purcell ACQUISITIONS EDITOR Todd Green DEVELOPMENT EDITOR Michael Watson PROJECT EDITOR Christina Smith COPY EDITOR Pat Kinyon INDEXERS Tom Dinse Erika Millen PROOFREADER Melissa Lynch TECHNICAL EDITOR Harold Finz, Steve Heckler, Farooq Karim, and Ari Krupnikov TEAM COORDINATOR Pamalee Nelson INTERIOR DESIGNER Gary Adair COVER DESIGNER Aren Howell PRODUCTION Cheryl Lynch Michelle Mitchell 00 0672323842 FM 3/20/02 9:31 AM Page ii Contents at a Glance Introduction 1 WEEK 1 Introducing J2EE and EJBs 7 Day 1 The Challenge of N-Tier Development 9 2 The J2EE Platform and Roles 27 3 Naming and Directory Services 81 4 Introduction to EJBs 125 5 Session EJBs 165 6 Entity EJBs 211 7 CMP and EJB QL 271 WEEK 2 Developing J2EE Applications 333 Day 8 Transactions and Persistence 335 9 Java Message Service 395 10 Message-Driven Beans 429 11 JavaMail 461 12 Servlets 501 13 JavaServer Pages 555 14 JSP Tag Libraries 603 WEEK 3 Integrating J2EE into the Enterprise 651 Day 15 Security 653 16 Integrating XML with J2EE 701 17 Transforming XML Documents 741 18 Patterns 787 19 Integrating with External Resources 827 20 Using RPC-Style Web Services with J2EE 869 21 Web Service Registries and Message-Style Web Services 923 Appendixes Appendix A An Introduction to UML 965 B SQL Reference 977 C An Overview of XML 987 D The Java Community Process 999 Glossary 1003 Index 1025 00 0672323842 FM 3/20/02 9:31 AM Page iii Contents Introduction 1 WEEK 1 Introducing J2EE and EJBs 7 DAY 1 The Challenge of N-Tier Development 9 Monolithic Development 10 Consequences of Monolithic Applications 10 The Move into the Second Tier 11 Consequences of the 2-Tier Design 12 Complexity Simplified by Modularity 14 Component Technology 15 Benefits of Modularity 16 Benefits of the 3-Tier Scenario 16 A Model for Enterprise Computing 17 Lifecycle 18 Persistence 18 Naming 18 Transaction 19 Java 2 Enterprise Edition (J2EE) 20 Components and Containers 20 J2EE Standard Services 21 J2EE Blueprints 23 J2EE Compatibility Test Suite 24 The Future of J2EE 25 Summary 25 Q&A 25 Exercises 26 D AY 2 The J2EE Platform and Roles 27 Revisiting the J2EE Platform 28 Using Sun Microsystems’ J2EE SDK 28 Installing J2EE SDK 1.3 29 Starting the J2EE Reference Implementation (RI) 32 Troubleshooting J2EE and Cloudscape 34 Closing Down J2EE RI and Cloudscape 37 Optional Software Used in this Book 37 Understanding Tiers and Components 38 The Business Tier 39 The Presentation Tier 44 00 0672323842 FM 3/20/02 9:31 AM Page iv Components: Web-Centric 45 The Client Tier 49 Standalone Client 52 Understanding Containers 55 Understanding the Services Containers Supply to Components 56 Hypertext Transfer Protocol (HTTP) 57 HTTP over Secure Sockets Layer (HTTPS) 57 Java Database Connectivity (JDBC) 57 Java Transaction API (JTA) 58 Java Authentication and Authorization Service (JAAS) 58 Java API for XML Parsing (JAXP) 58 Java Naming and Directory Interface (JNDI) 59 JavaBeans Activation Framework (JAF) 59 JavaMail 60 Java Message Service (JMS) 60 Java Interface Definition Language (Java IDL) 60 Remote Method Invocation over Internet Inter-Orb Protocol (RMI-IIOP) 61 Connector Architecture 62 Introducing Platform Roles 62 J2EE Product Provider 63 Application Component Provider 63 Application Assembler 63 Application Deployer 64 Systems Administrator 64 Tool Provider 65 Future of J2EE tools 65 Packaging and Deploying J2EE Applications 66 J2EE applications 67 Breaking Modules down into Components 68 Summary 70 Q&A 70 Exercises—Case Study 71 The Job Agency 72 Using the Agency Case Study 73 Practice Makes Perfect 75 The Case Study Directory on the CD-ROM 76 Installing the Case Study Database 76 D AY 3 Naming and Directory Services 81 Naming and Directory Services 82 Why Use a Naming Service? 82 What is JNDI? 83 00 0672323842 FM 3/20/02 9:31 AM Page v Common Naming Services 83 Naming Conventions 84 Using JNDI 85 Using Sun Microsystems’ J2EE Reference Implementation 85 Obtaining an Initial Context 86 Initial Context Naming Exceptions 86 Defining the JNDI Service 87 JNDI Properties Files 88 Application Properties 89 Applet Parameters 90 Hard-Coded Properties 90 Binding JNDI Objects 90 Binding Objects 91 Binding Problems 91 Name Persistence 92 Rebinding Objects 92 Unbinding Objects 92 Renaming Objects 93 JNDI Name Lookup 93 Changing Contexts 94 Narrowing RMI-IIOP Objects 95 Contexts 96 Listing Contexts 96 Creating and Destroying Contexts 98 More on JNDI Names 100 Special Characters 100 Composite and Compound Names 100 URLs 101 Attributes 102 Overview of LDAP X.500 Names 102 Obtaining an LDAP Server 103 Using OpenLDAP 104 Configuring JNDI to use LDAP 106 Testing the LDAP Server 107 Obtaining a Directory Context 108 Reading Attributes 108 Searching for Objects 109 Manipulating Attributes 112 More on Objects 114 Loading Classes from a Code Base 114 Defining a Code Base 114 References 117 vi Sams Teach Yourself J2EE in 21 Days 00 0672323842 FM 3/20/02 9:31 AM Page vi Contents vii What Else Can JNDI Do? 120 JNDI Events 120 Security 121 Summary 122 Q&A 123 Exercise 124 D AY 4 Introduction to EJBs 125 What Is an EJB? 126 Beans, Clients, Containers, and Servers 126 The EJB Landscape 127 Discovering EJBs 127 Types of EJB 128 Common Uses of EJBs 128 Why Use EJBs? 129 Hiding Complexity 130 Separation of Business Logic from UI and Data Access 130 Container Services 131 What’s in an EJB? 132 The Business Interface 132 The Business Logic 134 Factory Information 140 Bean Metadata 141 How Do I Create an EJB? 142 The Creation Mechanism 142 Caveats on Code Creation 143 Create the Deployable Component 143 How Do I Deploy an EJB? 147 Plugging into the Container 147 Performing the Deployment 148 How Do I Use an EJB? 148 Discovery 148 Retrieval and Use 149 Disposing of the EJB 150 Running the Client 150 Deploying and Using an EJB in the J2EE Reference Implementation 151 Opening the Case Study EAR File 152 Examining the Case Study Application 154 Deploying the Case Study Application 156 Testing the Case Study Application 158 Troubleshooting the Case Study Application 160 00 0672323842 FM 3/20/02 9:31 AM Page vii Summary 161 Q&A 161 Exercises 162 D AY 5 Session EJBs 165 Overview 165 The javax.ejb Package for Session Beans 167 Stateless Session Bean Lifecycle 168 Specifying a Stateless Session Bean 172 Implementing a Stateless Session Bean 175 Implementing javax.ejb.SessionBean 175 Implementing the Home Interface Methods 175 Implementing the Remote Interface Methods 177 Exceptions 179 Configuring and Deploying a Stateless Session Bean 180 Using deploytool 181 Structural Elements 182 Presentational Elements 183 Session Element 184 Deploying the Enterprise Application 193 Stateful Session Bean Lifecycle 193 Specifying a Stateful Session Bean 196 Implementing a Stateful Session Bean 198 Passivation 198 Timeouts 199 Chaining State 200 Configuring and Deploying a Stateful Session Bean 200 Client’s View 201 Patterns and Idioms 202 Business Interface 203 Adapter 204 Coarse-Grained 205 Gotchas 205 Summary 206 Q&A 207 Exercises 207 D AY 6 Entity EJBs 211 Overview 211 The N-tier Architecture Revisited 212 Comparison with RDBMS Technology 213 Identifying Entities 214 viii Sams Teach Yourself J2EE in 21 Days 00 0672323842 FM 3/20/02 9:31 AM Page viii Contents ix The javax.ejb Package for Entity Beans 216 Entity Bean Types 217 Remote Versus Local Interfaces 217 BMP Entity Bean Lifecycle 219 Specifying a BMP Entity Bean 225 Local-Home Interface 225 Local Interface 230 Implementing a BMP Entity Bean 231 Implementing the Local-Home Interface Methods 235 Implementing the Local Interface Methods 241 Generating IDs 243 Granularity Revisited 245 Beware Those Finder Methods! 245 EJB Container Performance Tuning 247 Configuring and Deploying a BMP Entity Bean 248 Entity Element 249 Client’s View 252 Session Beans Revisited 254 Patterns and Idioms 258 Interfaces, Façades, and State 258 Use Local Interfaces for Entity Beans 258 Dependent Value Classes 259 Self-Encapsulate Fields 261 Don’t Use Enumeration for Finders 262 Acquire Late, Release Early 262 Business Interface Revisited 264 Gotchas 264 Summary 265 Q&A 266 Exercises 266 D AY 7 CMP and EJB QL 271 Overview of Container-Managed Persistence 271 N-tier Architecture (Revisited Again) and CMP Fields 273 A Quick Word about the Case Study Database 276 CMP Entity Bean Lifecycle 277 Container-Managed Relationships 279 Relationship Types 280 Navigability 282 cmr-fields 282 Manipulating Relationships 286 00 0672323842 FM 3/20/02 9:31 AM Page ix EJB QL 291 Select Methods 291 Syntax and Examples 293 Further Notes 300 Specifying a CMP Entity Bean 301 The Local-Home Interface 301 The Local Interface 301 Implementing a CMP Entity Bean 302 Implementing javax.ejb.EntityBean 302 Implementing the Local-Home Interface Methods 305 Finder Methods 308 Implementing the Local Interface Methods 312 Configuring a CMP Entity Bean 313 The entity Element 313 The relationships Element 317 Deploying a CMP Entity Bean 322 Patterns and Idioms 323 Normalize/Denormalize Data in ejbLoad()/ejbStore() 323 Don’t Expose cmp-fields 324 Don’t Expose cmr-fields 325 Enforce Referential Integrity Through the Bean’s Interface 326 Use Select Methods to Implement Home Methods 327 Gotchas 328 Summary 329 Q&A 329 Exercises 330 WEEK 2 Developing J2EE Applications 333 DAY 8 Transactions and Persistence 335 Overview of Transactions 336 Container-Managed Transaction Demarcation 338 Bean Managed Transaction Demarcation 345 Motivation and Restrictions 345 Using the Java Transaction API 345 Deploying a BMTD Bean 349 Client-Demarcated Transactions 350 Exceptions Revisited 350 Extended Stateful Session Bean Lifecycle 352 Transactions: Behind the Scenes 354 Transaction Managers, Resource Managers, and 2PC 354 The JTA API 356 x Sams Teach Yourself J2EE in 21 Days 00 0672323842 FM 3/20/02 9:31 AM Page x [...]... 411 Simple Synchronous Receiver Example 412 Receive JMS Text Message Example 413 Asynchronous Messaging 414 The Publish/Subscribe Message Domain 415 00 0672323842 FM xii 3/20/02 9: 31 AM Page xii Sams Teach Yourself J2EE in 21 Days Point-to-Point Messaging Example 416 Bulletin Board Publisher 417 Bulletin Board Subscriber 418 Creating Durable... Programming a JMS Application Using J2EE RI 404 J2EE RI Connection Factories 404 Adding Destinations in J2EE RI 404 Creating a Queue in J2EE RI 404 Point-to-Point Messaging Example 406 JMS Messages 407 Creating a Message 409 Sending a Message 409 Closing the Connection 410 Send JMS Text Message Example 410 Consuming... Committees 10 01 Understanding the JSR Process 10 01 Taking the Next Step 10 02 Glossary 10 03 Index 10 25 00 0672323842 FM 3/20/02 9: 31 AM Page xxiii About the Authors The authors of this book work for Content Master Ltd., a technical authoring company in the United Kingdom specializing in the production of training and educational materials For more information on Content... Creating Valid XML 710 Document Type Definitions 710 Namespaces 714 Enforcing Document Structure with an XML Schema 715 How XML Is Used in J2EE 718 Parsing XML 718 The JAXP Packages 720 Parsing XML using SAX 720 Document Object Model (DOM) Parser 725 Modifying a DOM Tree 7 31 Java Architecture for XML Binding... 830 Using the Common Client Interface 834 Interacting with an EIS 834 Installing a Resource Adapter 835 Creating a First CCI Application 836 Managing Transactions and Exploring Records 843 Introducing Other Connectivity Technologies 848 Introducing CORBA 849 Introducing Java IDL 8 51 Using RMI over IIOP 8 51 RMI over JRMP... Defining the TLD Location 614 Using Simple Tags 614 Tags with Attributes 615 Tags that Define Script Variables 618 Iterative Tags 622 Co-operating Tags 626 Using Shared Scripting Variables 626 Hierarchical Tag Structures 627 Defining Tag Extra Info Objects 634 Validating Attributes 635 Defining Scripting... a European chartered engineer Martin currently works as an IT trainer and consultant based in Cornwall, England Dan Haywood has been working on large and small software development projects for more than 12 years These days, he fills his days with consulting, training and technical writing, specializing in OO design, Java and J2EE, Sybase technical consulting, and data modeling Previously, Dan worked... Existing J2EE Functionality as Web Services 909 Parameter Types and Type Mapping 911 Mapping Between Java and SOAP/WSDL Types 911 Mapping Complex Types with Serializers 912 Going Further with Complex Type Mapping 919 Summary 919 Q&A 920 Exercises 9 21 DAY 21 Web Service Registries and Message-Style Web Services 923 Registries for Web... Accessing Information in a UDDI Registry 929 Manipulating Service Information using UDDI4J 929 Manipulating Service Information Using the IBM WSTK Client API 932 Retrieving and Using Service Information 933 00 0672323842 FM 3/20/02 9: 31 AM Page xxi Contents xxi Using JAXR for Registry Access 934 A Generic Approach 934 Using JAXR to Store and Retrieve Service Information... XML-Based RPC (JAX-RPC) addresses this 3 01 0672323842 Intro 4 3/20/02 9:23 AM Page 4 Sams Teach Yourself J2EE in 21 Days • Day 21, “Web Service Registries and Message-Style Web Services,” concludes the examination of J2EE- based Web Services by examining the role of XML-based registries and how the Java API for XML Registries (JAXR) enables access to this information You will also create a message-oriented . Attributes 10 8 Searching for Objects 10 9 Manipulating Attributes 11 2 More on Objects 11 4 Loading Classes from a Code Base 11 4 Defining a Code Base 11 4 References 11 7 vi Sams Teach Yourself J2EE in 21 Days 00. 395 10 Message-Driven Beans 429 11 JavaMail 4 61 12 Servlets 5 01 13 JavaServer Pages 555 14 JSP Tag Libraries 603 WEEK 3 Integrating J2EE into the Enterprise 6 51 Day 15 Security 653 16 Integrating. Technology 213 Identifying Entities 214 viii Sams Teach Yourself J2EE in 21 Days 00 0672323842 FM 3/20/02 9: 31 AM Page viii Contents ix The javax.ejb Package for Entity Beans 216 Entity Bean Types 217 Remote

Ngày đăng: 13/08/2014, 08:21

TỪ KHÓA LIÊN QUAN