Class UnmarshallingContext

    • Constructor Detail

      • UnmarshallingContext

        public UnmarshallingContext()
    • Method Detail

      • setRecordValue

        public abstract void setRecordValue​(java.lang.Object value)
        Sets the value of the record returned from the RecordReader
        Parameters:
        value - the record value read by a record reader
        See Also:
        RecordReader
      • toRecordValue

        public java.lang.Object toRecordValue​(java.lang.String[] array)
        Converts a String[] to a record value.
        Parameters:
        array - the String[] to convert
        Returns:
        the record value, or null if not supported
      • toRecordValue

        public java.lang.Object toRecordValue​(java.util.List<java.lang.String> list)
        Converts a List to a record value.
        Parameters:
        list - the List to convert
        Returns:
        the record value, or null if not supported
      • toRecordValue

        public java.lang.Object toRecordValue​(org.w3c.dom.Node node)
        Converts a Node to a record value.
        Parameters:
        node - the Node to convert
        Returns:
        the record value, or null if not supported
      • prepare

        public void prepare​(java.lang.String componentName,
                            boolean isRecordGroup)
        Prepares this context for unmarshalling a record (or group of records that are combined to form a single bean object).
        Parameters:
        componentName - the record or group name to be unmarshalled
        isRecordGroup - true if the component is a group, false if it is a record
      • recordStarted

        public final void recordStarted​(java.lang.String recordName)
        This method must be invoked before a record is unmarshalled.
        Parameters:
        recordName - the name of the record
      • recordCompleted

        public final void recordCompleted()
        Either this method (or recordSkipped()) must be invoked after a record is unmarshalled, even if an error has occurred.
      • recordSkipped

        public final void recordSkipped()
        This method should be invoked when a record is skipped.
      • validate

        public final void validate()
                            throws InvalidRecordException
        Validates all unmarshalled records and throws an exception if any record is invalid. This method must be invoked after unmarshalling is completed. If unmarshalling fails due to some other fatal exception, there is no need to call this method.
        Throws:
        InvalidRecordException - if one or more unmarshalled records were invalid
      • getRecordCount

        public final int getRecordCount()
        Returns the number of record read for the last unmarshalled bean object.
        Returns:
        the record count for the last unmarshalled bean object
      • getRecordContext

        public final RecordContext getRecordContext​(int index)
                                             throws java.lang.IndexOutOfBoundsException
        Returns the record context for a record read for the last unmarshalled bean object.
        Parameters:
        index - the index of the record
        Returns:
        the RecordContext
        Throws:
        java.lang.IndexOutOfBoundsException - if there is no record for the given index
      • setFieldText

        public final void setFieldText​(java.lang.String fieldName,
                                       java.lang.String text)
        Sets the raw field text for a named field.
        Parameters:
        fieldName - the name of the field
        text - the raw field text
      • hasFieldErrors

        public final boolean hasFieldErrors()
        Returns true if a field error was reported while parsing this record.
        Returns:
        true if a field error was reported
      • hasRecordErrors

        public final boolean hasRecordErrors()
        Returns true if a record level error was reported while parsing this record.
        Returns:
        true if a record level error was reported
      • addFieldError

        public java.lang.String addFieldError​(java.lang.String fieldName,
                                              java.lang.String fieldText,
                                              java.lang.String rule,
                                              java.lang.Object... params)
        Adds a field error to this record.
        Parameters:
        fieldName - the name of the field in error
        fieldText - the invalid field text
        rule - the name of the failed validation rule
        params - an optional list of parameters for formatting the error message
        Returns:
        the formatted field error message
      • addRecordError

        public final java.lang.String addRecordError​(java.lang.String rule,
                                                     java.lang.Object... params)
        Adds a record level error to this record.
        Parameters:
        rule - the name of the failed validation rule
        params - an optional list of parameters for formatting the error message
        Returns:
        the formatted record error message
      • addRecordError

        protected java.lang.String addRecordError​(ErrorContext errorContext,
                                                  java.lang.String rule,
                                                  java.lang.Object... params)
        Adds a record level error to this record.
        Parameters:
        errorContext - the error context to update
        rule - the name of the failed validation rule
        params - an optional list of parameters for formatting the error message
        Returns:
        the formatted record error message
      • newUnsatisfiedGroupException

        public BeanReaderException newUnsatisfiedGroupException​(java.lang.String groupName)
      • newUnsatisfiedRecordException

        public BeanReaderException newUnsatisfiedRecordException​(java.lang.String recordName)
      • recordUnexpectedException

        public BeanReaderException recordUnexpectedException​(java.lang.String recordName)
      • recordException

        protected ErrorContext recordException​(java.lang.String recordName,
                                               java.lang.String rule,
                                               java.lang.Object... params)
        Handles a record level exception and returns a new ErrorContext for the exception.
        Parameters:
        recordName - the name of the record that failed
        rule - the record level rule that failed validation
        params - message parameters for formatting the error message
        Returns:
        the created ErrorContext
      • getLineNumber

        public final int getLineNumber()
        Returns the last line number read from the input stream. If the end of stream was reached, the line number is still incremented so that this method returns the expected line number if another record was read. If newlines are not used to terminate records, this method will always return zero.
        Returns:
        the line number
      • isEOF

        public final boolean isEOF()
        Returns whether the end of the stream was reached after nextRecord() was called.
        Returns:
        true if the end of the stream was reached
      • getLocale

        public java.util.Locale getLocale()
        Returns the locale to format error messages in.
        Returns:
        the Locale
      • setLocale

        public void setLocale​(java.util.Locale locale)
        Sets the locale to format error messages in.
        Parameters:
        locale - the Locale