286N/A<?
xml version="1.0" encoding="UTF-8"?>
286N/ACopyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved. 286N/ADO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 286N/AThis code is free software; you can redistribute it and/or modify it 286N/Aunder the terms of the GNU General Public License version 2 only, as 286N/Apublished by the Free Software Foundation. Oracle designates this 286N/Aparticular file as subject to the "Classpath" exception as provided 286N/Aby Oracle in the LICENSE file that accompanied this code. 286N/AThis code is distributed in the hope that it will be useful, but WITHOUT 286N/AANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 286N/AFITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 286N/Aversion 2 for more details (a copy is included in the LICENSE file that 286N/AYou should have received a copy of the GNU General Public License version 286N/A2 along with this work; if not, write to the Free Software Foundation, 286N/AInc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 286N/APlease contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 286N/A PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 286N/A <
title>Transformation API For XML</
title>
286N/A content="Jeff.Suttor@Sun.com" />
286N/A<
h2>Transformation API For XML</
h2>
286N/A<
p>This overview describes the set of APIs contained in
286N/A as TrAX (Transformations for XML). </
p>
286N/A<
p>There is a broad need for Java applications to be able to transform XML
286N/A and related tree-shaped data structures. In fact, XML is not normally very
286N/A useful to an application without going through some sort of transformation,
286N/A unless the semantic structure is used directly as data. Almost all XML-related
286N/A applications need to perform transformations. Transformations may be described
286N/A Stylesheets, other types of script, or by proprietary formats. The inputs, one
286N/A or multiple, to a transformation, may be a URL, XML stream, a DOM tree, SAX
286N/A Events, or a proprietary format or data structure. The output types are the
286N/A pretty much the same types as the inputs, but different inputs may need to be
286N/A combined with different outputs.</
p>
286N/A<
p>The great challenge of a transformation API is how to deal with all the
286N/A possible combinations of inputs and outputs, without becoming specialized for
286N/A any of the given types.</
p>
286N/A<
p>The Java community will greatly benefit from a common API that will
286N/A allow them to understand and apply a single model, write to consistent
286N/A interfaces, and apply the transformations polymorphically. TrAX attempts to
286N/A define a model that is clean and generic, yet fills general application
286N/A requirements across a wide variety of uses. </
p>
286N/A<
h3>General Terminology</
h3>
286N/A<
p>This section will explain some general terminology used in this
286N/A document. Technical terminology will be explained in the Model section. In many
286N/A cases, the general terminology overlaps with the technical terminology.</
p>
286N/A<
br>This term, as used within this document, describes an
286N/A abstract structure that consists of nodes or events that may be produced by
286N/A XML. A Tree physically may be a DOM tree, a series of well balanced parse
286N/A events (such as those coming from a SAX2 ContentHander), a series of requests
286N/A (the result of which can describe a tree), or a stream of marked-up
286N/A<
br>One or more trees that are the inputs to the
286N/A<
br>One or more trees that are the output of the
286N/A<
br>The processor of consuming a stream or tree to produce
286N/A another stream or tree.</
p>
286N/A<
b>Identity (or Copy) Transformation</
b>
286N/A<
br>The process of transformation from a source to a result,
286N/A making as few structural changes as possible and no informational changes. The
286N/A term is somewhat loosely used, as the process is really a copy. from one
286N/A "format" (such as a DOM tree, stream, or set of SAX events) to
286N/A<
br>The process of taking a tree and turning it into a stream. In
286N/A some sense, a serialization is a specialized transformation.</
p>
286N/A<
br>The process of taking a stream and turning it into a tree. In
286N/A some sense, parsing is a specialized transformation.</
p>
286N/A<
br>A Transformer is the object that executes the transformation.
286N/A<
b>Transformation instructions</
b>
286N/A<
br>Describes the transformation. A form of code, script, or
286N/A simply a declaration or series of declarations.</
p>
286N/A<
br>The same as "transformation instructions," except it is
286N/A<
br>Another form of "transformation instructions." In the TrAX
286N/A interface, this term is used to describe processed or compiled transformation
286N/A instructions. The Source flows through a Templates object to be formed into the
286N/A<
br>A general term for the thing that may both process the
286N/A transformation instructions, and perform the transformation.</
p>
286N/A<
br>Document Object Model, specifically referring to the
286N/A (DOM) Level 2 Specification</
A>.</
p>
286N/A<
p>The section defines the abstract model for TrAX, apart from the details
286N/A<
p>A TRaX <
A href="#pattern-TransformerFactory">TransformerFactory</
A> is an object
286N/A that processes transformation instructions, and produces
286N/A <
A href="#pattern-Templates">Templates</
A> (in the technical
286N/A terminology). A <
A href="#pattern-Templates">Templates</
A>
286N/A object provides a <
A href="#pattern-Transformer">Transformer</
A>, which transforms one or
286N/A more <
A href="#pattern-Source">Source</
A>s into one or more
286N/A <
A href="#pattern-Result">Result</
A>s.</
p>
286N/A<
p>To use the TRaX interface, you create a
286N/A <
A href="#pattern-TransformerFactory">TransformerFactory</
A>,
286N/A which may directly provide a <
A href="#pattern-Transformers">Transformers</
A>, or which can provide
286N/A <
A href="#pattern-Templates">Templates</
A> from a variety of
286N/A <
A href="#pattern-Source">Source</
A>s. The
286N/A <
A href="#pattern-Templates">Templates</
A> object is a processed
286N/A or compiled representation of the transformation instructions, and provides a
286N/A <
A href="#pattern-Transformer">Transformer</
A>. The
286N/A <
A href="#pattern-Transformer">Transformer</
A> processes a
286N/A <
A href="#pattern-Transformer">Source</
A> according to the
286N/A instructions found in the <
A href="#pattern-Templates">Templates</
A>, and produces a
286N/A <
A href="#pattern-Result">Result</
A>.</
p>
286N/A<
p>The process of transformation from a tree, either in the form of an
286N/A object model, or in the form of parse events, into a stream, is known as
286N/A <
code>serialization</
code>. We believe this is the most suitable term for
286N/A this process, despite the overlap with Java object serialization.</
p>
286N/A<
b><
a name="pattern-Processor">Processor</
a></
b>
286N/A<
i>Intent: </
i>Generic concept for the
286N/A set of objects that implement the TrAX interfaces.<
br>
286N/A<
i>Responsibilities: </
i>Create compiled transformation instructions, transform
286N/A sources, and manage transformation parameters and
286N/A<
i>Thread safety: </
i>Only the Templates object can be
286N/A used concurrently in multiple threads. The rest of the processor does not do
286N/A synchronized blocking, and so may not be used to perform multiple concurrent
286N/A operations. Different Processors can be used concurrently by different
286N/A<
b><
a name="pattern-TransformerFactory">TransformerFactory</
a></
b>
286N/A<
i>Intent: </
i>Serve as a vendor-neutral Processor interface for
286N/A<
i>Responsibilities: </
i>Serve as a factory for a concrete
286N/A implementation of an TransformerFactory, serve as a direct factory for
286N/A Transformer objects, serve as a factory for Templates objects, and manage
286N/A processor specific features.<
br>
286N/A TransformerFactory may not perform mulitple concurrent
286N/A<
b><
a name="pattern-Templates">Templates</
a></
b>
286N/A runtime representation of the transformation instructions.<
br>
286N/A<
i>Responsibilities: </
i>A data bag for transformation instructions; act as a factory
286N/A<
i>Thread safety: </
i>Threadsafe for concurrent
286N/A usage over multiple threads once construction is complete.</
p>
286N/A<
b><
a name="pattern-Transformer">Transformer</
a></
b>
286N/A<
i>Intent: </
i>Act as a per-thread
286N/A execution context for transformations, act as an interface for performing the
286N/A<
i>Responsibilities: </
i>Perform the
286N/A<
i>Thread safety: </
i>Only one instance per thread
286N/A<
i>Notes: </
i>The Transformer is bound to the Templates
286N/A object that created it.</
p>
286N/A<
b><
a name="pattern-Source">Source</
a></
b>
286N/A<
i>Intent: </
i>Serve as a
286N/A single vendor-neutral object for multiple types of input.<
br>
286N/A<
i>Responsibilities: </
i>Act as simple data holder for System IDs, DOM nodes, streams,
286N/A<
i>Thread safety: </
i>Threadsafe concurrently over multiple
286N/A threads for read-only operations; must be synchronized for edit
286N/A<
b><
a name="pattern-Result">Result</
a></
b>
286N/A<
i>Potential alternate name: </
i>ResultTarget<
br>
286N/A as a single object for multiple types of output, so there can be simple process
286N/A<
i>Responsibilities: </
i>Act as simple data holder for
286N/A output stream, DOM node, ContentHandler, etc.<
br>
286N/A<
i>Thread safety: </
i>Threadsafe concurrently over multiple threads for read-only,
286N/A must be synchronized for edit.</
p>