站内搜索: 请输入搜索关键词
当前页面: 图书首页 > How to be a Successful Technical Architect for J2EE Applications

Chapter 11: Building XML Access Objects - How to be a Successful Technical Architect for J2EE Applications

Team LiB
Previous Section Next Section

Chapter 11: Building XML Access Objects

Overview

Data access objects are classes that read and write persistent data. XML manipulation, because it's really a data access operation, is part of the DAO layer. An XML access object (XAO) reads and writes data in an XML format and converts that format to value objects that other layers in the application can use. For example, PurchaseOrderXAO is an XAO for a purchasing application that reads and transmits orders in an XML format. PurchaseOrderXAO contains the following methods:

public void setPurchaseOrder(String xmlText);
public void setPurchaseOrder(PurchaseOrderVO[] order);
public void setPurchaseOrder(InputStream order);

public String        getPurchaseOrderXmlText();
public PurchaseOrderVO[]  getPurchaseOrder();

public void transmit(EDIDestination dest);
public void save(OutputStream os);

Business objects use XAOs to interpret and produce XML data, as illustrated in figure 11.1. Typically, XAOs should have little to do with implementing the business rules associated with processing the data. XML-related code is separated to limit and localize the impact that changes in the XML structure have on your application. If this logic were scattered in various places in the business logic layer, for example, it would be much harder to find and change.

Click To expand
Figure 11.1: Using XML Access Objects Within a Layered Architecture

As a technical architect, you are responsible for forming coding standards and guidelines. This chapter provides implementation guidance and examples for structuring XAOs. In addition, we'll look at a way to generate code that XAOs can use easily, saving you development and maintenance time.

The chapter assumes that you have a basic knowledge of XML concepts and have used an XML parser with Java. Familiarity with XSL style sheets and templates will also help you understand the examples presented here. For readers wanting an XML concept review, the tutorials at W3Schools (http://www.w3schools.com/) are well written and concise.


Team LiB
Previous Section Next Section