dev@fi.java.net

Re: Primitive Parsing

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Mon, 28 Feb 2005 09:34:33 +0100

Alan Hudson wrote:
> In processCIIEncodingAlgorithm, it checks whether a _primitiveHandler or
> _algorithmHandler is registered. If not then it calls
> processBuiltInEncodingAlgorithmAsCharacters. I didn't register either
> of these but tried getting at the data through the
> AttributesHolder.getAlgorithmData() and it wasn't there.
>

Yes, it will be returned as characters.


> I think the logic is a bit off though. Ie I don't really want the
> callbacks, but I do want the data in primitive form.. are callbacks
> required or did I drop through a case?
>

It is currently necessary to register the EncodingAlgorithmHandler or
PrimitiveContentHandler. No callbacks will occur with attribute values,
only element content. See the JavaDoc for:

org.jvnet.fastinfoset.sax.Interface FastInfosetReader

(See below).

The registering of the handlers also act as properties for the reporting
of encoding algorithm data for attribute values.

Do you think we need separate properties for the reporting of attribute
values? My thinking was that we should try and keep reporting of element
content and attribute values synchronized.

Paul.


Interface for reading an Fast Infoset document using callbacks.

FastInfosetReader is the interface that a Fast Infoset parser's SAX2
driver must implement. This interface allows an application to to
register Fast Infoset specific event handlers for encoding algorithms.

The reception of encoding algorithm events is determined by the
registration of:

     * A PrimitiveTypeContentHandler, for the recieving of events,
associated with built-in encoding algorithms, for decoded data that can
be reported as Java primitive types.
     * A EncodingAlgorithmContentHandler, for the recieving of events,
associated with built-in and application-defined encoding algorithms,
for decoded data that can be reported as an array of octets or as a Java
Object.
     * EncodingAlgorithm implementations, for the receiving of events,
associated with application defined algorithms. for decoded data that
shall be reported as a Java Object by way of the registered
EncodingAlgorithmContentHandler.

The reporting of element content events for built-in algorithms is
determimed by the following:

     * If a PrimitiveContentHandler is registered then decoded data is
reported as Java primitive types using the corresponding methods on the
PrimitiveContentHandler interface.
     * If a PrimitiveContentHandler is not registered and a
EncodingAlgorithmContentHandler is registered then decoded data is
reported as Java Objects using
EncodingAlgorithmContentHandler.object(String, int, Object). An Object
shall correspond to the Java primitive type that would otherwise be
reported using the PrimitiveContentHandler.
     * If neither is registered then then decoded data is reported as
characters.

The reporting of element content events for application-defined
algorithms is determimed by the following:

     * If an EncodingAlgorithmContentHandler is registered and there is
no EncodingAlgorithm registered for an application-defined encoding
algorithm then decoded data for such an algoroithm is reported as an
array of octets using EncodingAlgorithmContentHandler.octets(String,
int, byte[], int, int); otherwise
     * If there is an EncodingAlgorithm registered for the
application-defined encoding algorithm then the decoded data is reported
as a Java Object, returned by decoding according to the
EncodingAlgorithm, using EncodingAlgorithmContentHandler.object(String,
int, Object).

The reporting of attribute values for encoding algorithms is achieved
using EncodingAlgorithmAttributes that extends Attributes. The
registered ContentHandler may cast the attr paramter of the
ContentHandler.startElement(String, String, String,
org.xml.sax.Attributes) to the EncodingAlgorithmAttributes interface to
access to encoding algorithm information.

The reporting of attribute values for built-in algorithms is determimed
by the following:

     * If a PrimitiveContentHandler or EncodingAlgorithmContentHandler
is registered then decoded data is reported as Java Objects
corresponding to the Java primitive types. The Java Objects may be
obtained using EncodingAlgorithmAttributes.getAlgorithmData(int).
     * If neither is registered then then decoded data is reported as
characters.

The reporting of attribute values for application-defined algorithms is
determimed by the following:

     * If an EncodingAlgorithmContentHandler is registered and there is
no EncodingAlgorithm registered for an application-defined encoding
algorithm then decoded data for such an algoroithm is reported as Java
Object, that is an instance of byte[], using
EncodingAlgorithmAttributes.getAlgorithmData(int); otherwise
     * If there is an EncodingAlgorithm registered for the
application-defined encoding algorithm then the decoded data is reported
as a Java Object, returned by decoding according to the
EncodingAlgorithm, using EncodingAlgorithmAttributes.getAlgorithmData(int).

-- 
| ? + ? = To question
----------------\
    Paul Sandoz
         x38109
+33-4-76188109