Revision | $Id: //guest/julian_hyde/mondrian/src/main/mondrian/xom/package.html#1 $ |
---|---|
Copyright | (C) Copyright 2001-2002 Kana Software, Inc. |
Author | Dan Sommerfield, Julian Hyde |
The schema is defined in an XML file, whose format is somewhat similar to an
XML Schema. The (self-describing) meta-schema is meta.xml
(
as you can see, an XSL style-sheet formats each schema into a javadoc-like web
page).
Other schemas include mondrian.xml
and resource.xml
.
The utilities in this package enable conversion of XML (stored in a DOM-style model) into a typesafe Java representation. Roughly, conversion occurs as follows:
Element
becomes a Java Class. The Java Class name matches the
Element name. All classes representing Elements descend from
{@link mondrian.xom.ElementDef}. All classes from the same model are
implemented as static inner classes of a single enclosure class.
By convention, enclosure classes always end in "Def".Attribute
becomes a public member of its enclosing Element class.PCDATA
) content becomes a single public String called cdata
.ANY
content becomes a single array of {@link mondrian.xom.ElementDef}
called children
.
Converting an XML Document to its XOM representation is a two-step process. First, you parse the XML into a DOM representation using your favorite W3C DOM Level 1-compliant parser (note: MSXML is supported as well for backward compatibility). Then, you instantiate the XOM {@link mondrian.xom.ElementDef} subclass corresponding to the root element in the document, passing a portion of the DOM as input to the constructor. After this, the fully-constructed root element provides complete typesafe access to the whole document!
Specific instructions for parsing using a DOM-compliant parser (such as XERCES):
Specific instructions for parsing using Microsoft's XML Parser:
The utility is the Java class {@link MetaGenerator}. It takes command-line arguments; usage:
The XML model file is the name of the XML model file to use (e.g. assoc.xml, input.xml, etc). You would have something like 'diablo.xml'.jview <classpath_options> mondrian.xom.MetaGenerator [-debug] [-test] <XML model file> <output directory>
The output directory is the directory in which all output files (a DTD and a
.java file to be precise) will be created. Note that the actual names of
these files are specified by the dtdName
, className
,
and packageName
attributes of the <Model>
.
Given mondrian.xml
as follows:
A run generates<Model name="bas" dtdName="mondrian.dtd" className="MondrianDef" packageName="mondrian.olap" root="Schema" version="1.0"> ...
mondrian.dtd
and {@link
mondrian.olap.MondrianDef}:
$ cd das $ jview mondrian.xom.MetaGenerator src/main/mondrian/olap/mondrian.xml src/main Writing src/main/mondrian/olap/mondrian.dtd Writing src/main/mondrian/olap/MondrianDef.java Done $
todo: There is now an ANT target, XOMGen
, implemented by {@link mondrian.xom.XOMGenTask}.
There is another helpful utility we use to verify that the stuff we generate works. It is class {@link MetaTester}, and you invoke it as follows:
All the arguments are the same as the ones for {@link MetaGenerator}, except for tests. <tests> is a list of test .xml files that should be valid according to the generated DTD. The tester will validate the java files against the DTD and also against the java class. It also runs some basic checks on the java class to make sure that it works.jview <classpath_options> mondrian.xom.MetaTester [-debug] [-msxml | -xerces] <XML model file> <output dir> [<tests>...]
We run both utilities from a test harness in the mining directory. Look
at any of the runtest.sh files under the mining/test/metamodel/<anydir>
hierarchy. These files ultimately call down to a common script file.
The test script runs {@link MetaGenerator}, compiles the generated java
class (to verify that it was created correctly), tests one or more test xml
files against the model, and optionally installs the generated files into the
build tree (it was easier to generate the files and check them in than to run
MetaGenerator with each build). The package declaration "Broadbase.mining.xml"
is added to any java classes when they get installed. Also, the test
harness diffs the generated DTD and .java file against the most recently
generated version.
Currently the test harness tests all files against both the MSXML parser and against the Apache XERCES parser.
meta.xml
, we generate corresponding DTD and NameDef.java
at build time. {@link MetaDef} is tricky, because it
depends upon itself. We source-control it and meta.dtd
.
If you change meta.xml
, you need to regenerate them as follows:
$ p4 edit src/main/mondrian/xom/meta.dtd src/main/mondrian/xom/MetaDef.java $ build metadef
Then insert the modified class files into lib/boot.jar
. If things get screwed up, refresh MetaDef.java
and meta.dtd
from perforce.
<Entity>
, all <Attribute>
s
must occur before all <Object>
, <Array>
or <CData>
elements.This package is dependent upon the following other packages:
Class {@link XOMGenTask} only is dependent upon {@link org.apache.tools.ant}. You therefore require ant.jar
to build, but not to run.
Class {@link mondrian.xom.wrappers.XercesDOMParser} only is dependent upon {@link org.xml.sax} and {@link org.apache.xerces.parsers.DOMParser}. You therefore require xerces.jar
to build, but not to run.