sk.baka.ikslibs
Enum SourceEnum

java.lang.Object
  extended by java.lang.Enum<SourceEnum>
      extended by sk.baka.ikslibs.SourceEnum
All Implemented Interfaces:
Serializable, Comparable<SourceEnum>

public enum SourceEnum
extends Enum<SourceEnum>

Enumerates all possible source types that exporter can accept as an input.

Author:
Martin Vysny

Enum Constant Summary
DOM
          The DOM Document instance source.
OBJECT
          Java Object source.
SAX
          The DocumentHandler instance source.
STAX
          STAX source.
STREAM
          InputStream source.
 
Field Summary
static List<SourceEnum> priorityList
           List describing priorities for target-to-source conversion.
 
Method Summary
static void checkReadability(Source source)
          If given source is not readable IllegalArgumentException is thrown.
abstract  Source convert(Source source, String encoding)
           Tries to convert given source to this source type.
static void copy(Source source, Result result)
          Performs a data copy from the source to the result.
protected abstract  void copyIntern(Source source, Result result)
           Performs a data copy from the source to the result.
abstract  ResultEnum getPair()
          Returns result type that has the same type as this source.
static EnumSet<ResultEnum> getPairSet(EnumSet<SourceEnum> sourceTypes)
          Returns set consisting of pairs for all items in given set.
static EnumSet<SourceEnum> getRedirectKinds(EnumSet<ResultEnum> products)
          Computes all kinds of sources, that the product kinds are able to be redirected to.
 Class<? extends Source> getSourceClass()
          Returns the class of Source object that is represented by the enum item.
static boolean isReadable(Source source)
          Checks if given source is readable (if it contains at least one non-null stream, node, etc).
protected abstract  boolean isReadableIntern(Source source)
          Checks if given source is readable (if it contains at least one non-null stream, node, etc).
 boolean represents(Class<? extends Source> sourceClass)
          Returns true if this enum constant represents Source object of required instance.
static SourceEnum valueOf(Class<? extends Source> sourceClass)
          Finds appropriate enum item for the source instance.
static SourceEnum valueOf(String name)
          Returns the enum constant of this type with the specified name.
static SourceEnum[] values()
          Returns an array containing the constants of this enum type, in the order they're declared.
 
Methods inherited from class java.lang.Enum
clone, compareTo, equals, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Enum Constant Detail

DOM

public static final SourceEnum DOM
The DOM Document instance source.


SAX

public static final SourceEnum SAX
The DocumentHandler instance source.


STREAM

public static final SourceEnum STREAM
InputStream source.


OBJECT

public static final SourceEnum OBJECT
Java Object source.


STAX

public static final SourceEnum STAX
STAX source.

Field Detail

priorityList

public static final List<SourceEnum> priorityList

List describing priorities for target-to-source conversion. First item has the highest priority. Items priorities are as follows:

  1. OBJECT - native data exchange
  2. DOM
  3. STAX - lowest memory consumption,
  4. SAX - lowest memory consumption,
  5. STREAM

Method Detail

values

public static final SourceEnum[] values()
Returns an array containing the constants of this enum type, in the order they're declared. This method may be used to iterate over the constants as follows:
for(SourceEnum c : SourceEnum.values())
        System.out.println(c);

Returns:
an array containing the constants of this enum type, in the order they're declared

valueOf

public static SourceEnum valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)

Parameters:
name - the name of the enum constant to be returned.
Returns:
the enum constant with the specified name
Throws:
IllegalArgumentException - if this enum type has no constant with the specified name

getSourceClass

public final Class<? extends Source> getSourceClass()
Returns the class of Source object that is represented by the enum item.

Returns:
the class of Source object that is represented by the enum item.

represents

public final boolean represents(Class<? extends Source> sourceClass)
Returns true if this enum constant represents Source object of required instance.

Parameters:
sourceClass -
Returns:
true if this enum constant represents this class, false otherwise.

valueOf

public static SourceEnum valueOf(Class<? extends Source> sourceClass)
Finds appropriate enum item for the source instance.

Parameters:
sourceClass - class of Source object instance.
Returns:
enum item.

getPair

public abstract ResultEnum getPair()
Returns result type that has the same type as this source.

Returns:
result of same type.

convert

public abstract Source convert(Source source,
                               String encoding)
                        throws IOException,
                               TransformerException

Tries to convert given source to this source type. Conversion follows this table:

From To Description
DOM SAX, STAX Standard conversion
SAX DOM, STAX Standard conversion
DOM, SAX, STAX Stream Serialization is performed. Result is valid XML file. Output document formatting is undefined.
Stream DOM, SAX, STAX Stream is not parsed - one Text node containing stream contents is constructed instead. Stream is expected to be in UTF-8 encoding.
Object Stream, DOM, SAX, STAX Returns null.
DOM, SAX, Stream, STAX Object Returns null

If both kinds are same then source is simply returned. If a different source is returned then you should not attempt to read from the original source.

The conversion may be performed by a background thread, to save memory space. The conversion simply uses TransformUtils' sourceToXXX methods (depending on the source type). For full description of blocking/thread safety please consult appropriate sourceToXXX method.

Parameters:
source - source to convert.
encoding - the encoding to use when reading from/writing to a stream. If null then it is detected from the source and/or result. If it cannot be detected then UTF-8 is used. For details please see TransformUtils.getEncoding(String, Source, Result).
Returns:
source converted to this type. If the conversion is not possible then return null. Returned source instance is fully initialized and prepared for reading.
Throws:
IOException - if i/o error occurs during source reading.
TransformerException - if transformer fails while processing source.

copy

public static void copy(Source source,
                        Result result)
                 throws IOException
Performs a data copy from the source to the result. Both source and result must be of same kind. Source nor result are closed after the copy. Blocks until the copy is finished. If copying from an input source to a writer (or vice versa), UTF-8 encoding is used.

Parameters:
source - data source, must not be null. Must be readable.
result - data result, must not be null. Must be writable.
Throws:
IOException - if IO error occurs.

isReadableIntern

protected abstract boolean isReadableIntern(Source source)
Checks if given source is readable (if it contains at least one non-null stream, node, etc).

Parameters:
source - source to check
Returns:
true if given source gives access to some content.

isReadable

public static boolean isReadable(Source source)
Checks if given source is readable (if it contains at least one non-null stream, node, etc).

Parameters:
source - source to check
Returns:
true if given source gives access to some content.

checkReadability

public static void checkReadability(Source source)
If given source is not readable IllegalArgumentException is thrown.

Parameters:
source - source to check.

copyIntern

protected abstract void copyIntern(Source source,
                                   Result result)
                            throws IOException

Performs a data copy from the source to the result. Both source and result will be of same kind. Blocks until the copy is finished. If copying from an input source to a writer (or vice versa), UTF-8 encoding is used.

Parameters:
source - data source, must not be null.
result - data result, must not be null.
Throws:
IOException - if IO error occurs.

getPairSet

public static EnumSet<ResultEnum> getPairSet(EnumSet<SourceEnum> sourceTypes)
Returns set consisting of pairs for all items in given set.

Parameters:
sourceTypes - the source types.
Returns:
set of target types

getRedirectKinds

public static final EnumSet<SourceEnum> getRedirectKinds(EnumSet<ResultEnum> products)
Computes all kinds of sources, that the product kinds are able to be redirected to.

Parameters:
products - set of result kinds.
Returns:
set of sources, each source is redirectable from at least one pipe output kind specified in products set.


Copyright © 2006 Martin Vysny - baka. All Rights Reserved.