org.jibx.binding
Class Utility

java.lang.Object
  extended by org.jibx.binding.Utility

public class Utility
extends java.lang.Object

Binding compiler support class. Supplies common methods for use in compiling binding definitions.

Author:
Dennis M. Sosnoski

Field Summary
private static int COPY_BUFFER_SIZE
           
 
Constructor Summary
private Utility()
           
 
Method Summary
static java.lang.String bindingFromFileName(java.lang.String fname)
          Get the default binding name from a supplied file name.
static java.lang.String fileName(java.lang.String path)
          Extract base file name from a full path.
private static ClassFile findMappedClass(BindingElement root)
          Recursively search through binding definitions for a modifiable mapped class.
static java.lang.String[] getClassPaths()
          Method builds a string array of items in the class path.
private static byte[] getStreamData(java.io.InputStream is)
          Read contents of stream into byte array.
static BindingDefinition loadBinding(java.lang.String fname, java.lang.String sname, java.io.InputStream istrm, java.net.URL url, boolean test)
          Load validated binding definition.
static BindingDefinition loadFileBinding(java.lang.String path, boolean valid)
          Load binding definition from file.
private static void recursePathJars(java.lang.String path, java.util.ArrayList paths)
          Recurse through jar file path component, adding all jars referenced from the original jar to the path collection.
static BindingElement validateBinding(java.lang.String name, java.net.URL url, java.io.InputStream is)
          Validate binding definition.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COPY_BUFFER_SIZE

private static final int COPY_BUFFER_SIZE
See Also:
Constant Field Values
Constructor Detail

Utility

private Utility()
Method Detail

getStreamData

private static byte[] getStreamData(java.io.InputStream is)
                             throws java.io.IOException
Read contents of stream into byte array.

Parameters:
is - input stream to be read
Returns:
array of bytes containing all data from stream
Throws:
java.io.IOException - on stream access error

recursePathJars

private static void recursePathJars(java.lang.String path,
                                    java.util.ArrayList paths)
Recurse through jar file path component, adding all jars referenced from the original jar to the path collection. Silently ignores problems loading jar files.

Parameters:
path - jar path component
paths - set of paths processed (added to by call)

getClassPaths

public static java.lang.String[] getClassPaths()
Method builds a string array of items in the class path.

Returns:
array of classpath components

fileName

public static java.lang.String fileName(java.lang.String path)
Extract base file name from a full path.

Parameters:
path - full file path
Returns:
file name component from path

bindingFromFileName

public static java.lang.String bindingFromFileName(java.lang.String fname)
Get the default binding name from a supplied file name.

Parameters:
fname - simple file name (without leading path information)
Returns:
default binding name

validateBinding

public static BindingElement validateBinding(java.lang.String name,
                                             java.net.URL url,
                                             java.io.InputStream is)
Validate binding definition. If issues are found in the binding the issues are printed directly to the console.

Parameters:
name - identifier for binding definition
url - URL for binding definition (null if not available)
is - input stream for reading binding definition
Returns:
root element of binding model if binding is valid, null if one or more errors in binding

loadBinding

public static BindingDefinition loadBinding(java.lang.String fname,
                                            java.lang.String sname,
                                            java.io.InputStream istrm,
                                            java.net.URL url,
                                            boolean test)
                                     throws JiBXException,
                                            java.io.IOException
Load validated binding definition. This first reads the input stream into a memory buffer, then parses the data once for validation and a second time for the actual binding definition construction. If any errors are found in the binding definition validation the construction is skipped and an exception is thrown.

Parameters:
fname - binding definition full name
sname - short form of name to use as the default name of the binding
istrm - input stream for binding definition document
url - URL for binding definition (null if not available)
test - validate binding flag
Returns:
constructed binding definition
Throws:
java.io.FileNotFoundException - if path cannot be accessed
JiBXException - if error in processing the binding definition
java.io.IOException - if error reading the binding

findMappedClass

private static ClassFile findMappedClass(BindingElement root)
Recursively search through binding definitions for a modifiable mapped class. This is used to determine the default package for code generation.

Parameters:
root - binding element at root of definition
Returns:
modifiable mapped class, or null if none

loadFileBinding

public static BindingDefinition loadFileBinding(java.lang.String path,
                                                boolean valid)
                                         throws JiBXException,
                                                java.io.IOException
Load binding definition from file.

Parameters:
path - file path for binding definition
valid - validate binding flag
Returns:
constructed binding definition
Throws:
java.io.IOException - if error accessing file
JiBXException - if error in processing the binding definition


Project Web Site