org.openexi.proc.common
Class GrammarOptions

java.lang.Object
  extended by org.openexi.proc.common.GrammarOptions

public final class GrammarOptions
extends java.lang.Object

GrammarOptions computes a short integer that represents settings in the EXI Grammar settings that determine how an EXI file will be encoded or decoded.

Values are set using binary switch values (represented as short integers).

If no options have been set, the value is 0 (this is an temporary internal value, rather than a valid setting).

If an XSD is available, and the file to be processed is 100% compatible with the XSD, choosing STRICT_OPTIONS (1) provides the best performance. No other options can be set when files are encoded or decoded in strict mode.

The DEFAULT_OPTIONS setting is 2. The following table lists all of the options and their values.

ConstantValue
STRICT_OPTIONS1
DEFAULT_OPTIONS2
ADD_NS4
ADD_SCN/A*
ADD_DTD16
ADD_CM32
ADD_PI64
*The self-contained option is not supported in this release.


The value of DEFAULT_OPTIONS is 2. When you pass the options variable to an add[??] method, the binary switch value is added to the current value of the options variable. The sum of all additional switches becomes a concise list of the selected options.

For example, if you preserve comments and processing instructions, the total is 98 (2 + 32 + 64). The bitwise options are set correctly, because there is one and only one combination of options that sums up to 98.

If your application uses the same options every time, you can hard code the numeric value as a short integer and use it to create your GrammarCache. For example:
 GrammarCache gc = new GrammarCache((EXISchema)null,98);
 
Be careful to use the correct numeric value, to avoid unexpected results.


Field Summary
static short DEFAULT_OPTIONS
          Indicates that undeclared elements and attributes will be processed when the XML stream is encoded and decoded.
static short OPTIONS_UNUSED
          OPTIONS_UNUSED is an internal value.
static short STRICT_OPTIONS
          Indicates that undeclared elements and attributes will throw an exception when the XML stream is encoded and decoded.
 
Method Summary
static short addCM(short options)
          Sets Preserve Comments to true.
static short addDTD(short options)
          Sets Preserve Document Type Definition to true.
static short addNS(short options)
          Sets Preserve Namespaces to true.
static short addPI(short options)
          Sets Preserve Processing Instructions to true.
static boolean hasCM(short options)
          Returns true if Preserve Comments is true.
static boolean hasDTD(short options)
          Returns true if Preserve Document Type Definition is true.
static boolean hasNS(short options)
          Returns true if Preserve Namespaces is true.
static boolean hasPI(short options)
          Returns true if Preserve Processing Instructions is true.
static boolean isPermitDeviation(short options)
          Returns true if DEFAULT_OPTIONS is set to true.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OPTIONS_UNUSED

public static final short OPTIONS_UNUSED
OPTIONS_UNUSED is an internal value. It indicates that the grammar options value has not yet been set.

See Also:
Constant Field Values

DEFAULT_OPTIONS

public static final short DEFAULT_OPTIONS
Indicates that undeclared elements and attributes will be processed when the XML stream is encoded and decoded.

See Also:
Constant Field Values

STRICT_OPTIONS

public static final short STRICT_OPTIONS
Indicates that undeclared elements and attributes will throw an exception when the XML stream is encoded and decoded. When STRICT_OPTIONS is set, all other Grammar Options are ignored.

See Also:
Constant Field Values
Method Detail

isPermitDeviation

public static boolean isPermitDeviation(short options)
Returns true if DEFAULT_OPTIONS is set to true.


hasNS

public static boolean hasNS(short options)
Returns true if Preserve Namespaces is true.


hasDTD

public static boolean hasDTD(short options)
Returns true if Preserve Document Type Definition is true.


hasCM

public static boolean hasCM(short options)
Returns true if Preserve Comments is true.


hasPI

public static boolean hasPI(short options)
Returns true if Preserve Processing Instructions is true.


addNS

public static short addNS(short options)
Sets Preserve Namespaces to true. (Adds 4 to the options value.)

Returns:
the new options short integer value

addDTD

public static short addDTD(short options)
Sets Preserve Document Type Definition to true. (Adds 16 to the options value.)

Returns:
the new options short integer value

addCM

public static short addCM(short options)
Sets Preserve Comments to true. (Adds 32 to the options value.)

Returns:
the new options short integer value

addPI

public static short addPI(short options)
Sets Preserve Processing Instructions to true. (Adds 64 to the options value.)

Returns:
the new options short integer value