org.apache.torque.betwixt
Class Resolver

java.lang.Object
  extended by org.apache.torque.betwixt.Resolver
All Implemented Interfaces:
org.xml.sax.EntityResolver

public class Resolver
extends java.lang.Object
implements org.xml.sax.EntityResolver

This class resolves the where to find the versions of the Betwixt Bean Map and DTD files to use in converting XML data to Torque OM objects. These files are found by using the methods described below.

Note: Both these files can be created from the Torque DB schema by using adding the 'Betwixt add-on' to Torque's Generator and using the datadtd task.

The DTD file is locate using the following method:

First, the URI on the XML Import file's DOCTYPE definition is parsed to get the specified file name (allows for DTD versioning). This name is combined with the value of the dtdPackage property and the classpath is searched. If this file is not found, the value specified by the dtdFileName property is used. If neither file is found, the normal SAX parser will attempt to load the DTD using the DOCTYPE URI

The Betwixt mapping file is found by searching the classpath for a file with the mapFileName located in the mapFilePackage.

Author:
Greg Monroe

Constructor Summary
Resolver()
          A resolver to get the inputSource that a SAX parser will use for an import DTD definition.
Resolver(java.lang.String dtdPackage)
           
 
Method Summary
 java.lang.String getBewtixtFileName()
          Gets the correctly qualified Betwixt mapping file name to try to open via a resource lookup.
 java.lang.String getDtdFileName()
          Get the file name of the DTD that that will be used to validate the XML import with.
 java.lang.String getDtdPackage()
          Get the package directory the DTD will be located in.
 java.lang.String getDtdUri()
          Gets the URI to locate the DTD via the Internet (if any)
 java.lang.String getMapFileName()
          Get the name of the Betwixt multi (bean) mapping file to be used.
 java.lang.String getMapFilePackage()
          Get the package directory the Betwixt mapping file will be located in.
 org.xml.sax.InputSource makeInputSource(java.lang.String packageFileName)
          Try to find the specified resource on the classpath.
 org.xml.sax.InputSource resolveBetwixtFile()
          Locate the required Betwixt map file on the classpath.
 java.lang.String resolveDtdUri()
          Resolve the DTD file's URI to use in DOCTYPE elements in the following manner:
 org.xml.sax.InputSource resolveEntity(java.lang.String publicID, java.lang.String systemID)
          Return an InputSource that provides access to the indicated entity.
 void setDtdFileName(java.lang.String dtdFileName)
          Set the file name (no path ) of the DTD file to validate the XML against.
 void setDtdPackage(java.lang.String dtdPackage)
          Set the package directory the DTD will be located in.
 void setDtdUri(java.lang.String dtdURI)
          Sets the URI to locate the DTD via the Internet (if any).
 void setMapFileName(java.lang.String mapFileName)
          Set the name of the Betwixt multi (bean) mapping file to be used.
 void setMapFilePackage(java.lang.String mapFilePackage)
          Set the package directory the Betwixt mapping file will be located in.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Resolver

public Resolver()
A resolver to get the inputSource that a SAX parser will use for an import DTD definition.


Resolver

public Resolver(java.lang.String dtdPackage)
Method Detail

resolveEntity

public org.xml.sax.InputSource resolveEntity(java.lang.String publicID,
                                             java.lang.String systemID)
                                      throws org.xml.sax.SAXException,
                                             java.io.IOException
Return an InputSource that provides access to the indicated entity. Assumes that systemId is in a URL format that ends in the dtd file name, e.g. "http://www.my.org/dtds/myDTD.dtd".

The file name and dtdPackage value are combine and the class path is searched for the DTD resource. If not found, a null is returned to indicate the parser should use it's normal resolving method.

Specified by:
resolveEntity in interface org.xml.sax.EntityResolver
Parameters:
publicID - a java.lang.String that contains the public identifier of the desired entity
systemID - a java.lang.String that contains the system identifier (i.e., the URL) of the desired entity
Returns:
org.xml.sax.InputSource
Throws:
org.xml.sax.SAXException
java.io.IOException
See Also:
EntityResolver.resolveEntity(java.lang.String, java.lang.String)

resolveBetwixtFile

public org.xml.sax.InputSource resolveBetwixtFile()
                                           throws java.lang.Exception
Locate the required Betwixt map file on the classpath.

Returns:
The InputSource to read the mapping file from.
Throws:
java.lang.Exception

getBewtixtFileName

public java.lang.String getBewtixtFileName()
Gets the correctly qualified Betwixt mapping file name to try to open via a resource lookup. E.g., packageDir/fileName or just fileName.

Returns:
The map file name to look for.

makeInputSource

public org.xml.sax.InputSource makeInputSource(java.lang.String packageFileName)
                                        throws java.lang.Exception
Try to find the specified resource on the classpath.

Parameters:
packageFileName -
Returns:
The source or null if not found.
Throws:
java.lang.Exception

resolveDtdUri

public java.lang.String resolveDtdUri()
                               throws java.lang.IllegalStateException
Resolve the DTD file's URI to use in DOCTYPE elements in the following manner:

If the dtdURI property is set, just use that. Otherwise, try to find the specified dtd file locally on the Classpath. If that fails, just the dtd file name.

Throws:
java.lang.IllegalStateException - if dtdFileName has not been set.

getDtdFileName

public java.lang.String getDtdFileName()
Get the file name of the DTD that that will be used to validate the XML import with.

Returns:
Returns the dtdFileName.

setDtdFileName

public void setDtdFileName(java.lang.String dtdFileName)
Set the file name (no path ) of the DTD file to validate the XML against.

Parameters:
dtdFileName - The dtdFileName to set.

getDtdPackage

public java.lang.String getDtdPackage()
Get the package directory the DTD will be located in. This will be a directory under the classpath or jar root, e.g. org/apache/torque/dtd

Returns:
Returns the dtdPackage or "" if not set.

setDtdPackage

public void setDtdPackage(java.lang.String dtdPackage)
Set the package directory the DTD will be located in. This will be a directory under the classpath or jar root, e.g. org/apache/torque/dtd

Parameters:
dtdPackage - The dtdPackage to set

getMapFileName

public java.lang.String getMapFileName()
Get the name of the Betwixt multi (bean) mapping file to be used. E.g. myDatabase.betwixt.

Returns:
Returns the mapFileName.

setMapFileName

public void setMapFileName(java.lang.String mapFileName)
Set the name of the Betwixt multi (bean) mapping file to be used. E.g. myDatabase.betwixt.

Parameters:
mapFileName - The mapFileName to set.

getMapFilePackage

public java.lang.String getMapFilePackage()
Get the package directory the Betwixt mapping file will be located in. This will be a directory under the classpath or jar root, e.g. org/apache/torque/dtd

Returns:
Returns the mapFilePackage.

setMapFilePackage

public void setMapFilePackage(java.lang.String mapFilePackage)
Set the package directory the Betwixt mapping file will be located in. This will be a directory under the classpath or jar root, e.g. org/apache/torque/dtd

Parameters:
mapFilePackage - The mapFilePackage to set.

getDtdUri

public java.lang.String getDtdUri()
Gets the URI to locate the DTD via the Internet (if any)

Returns:
Returns the dtdUri or null in not set.

setDtdUri

public void setDtdUri(java.lang.String dtdURI)
Sets the URI to locate the DTD via the Internet (if any). This value will be used by resolveDtdUri() method if non-null.

Parameters:
dtdURI - The DTD URI to use.


Copyright © 2006 Torque Add-ons Project. All Rights Reserved.