uCosminexus Service Platform, Basic Development Guide

[Contents][Glossary][Index][Back][Next]

Appendix I.5 CSCOwnCodeReaderContext interface

Organization of this subsection
(1) Interface
(2) Exception class
(3) Implementation example(MS932)
(4) Implementation example (IBM Kanji code)

(1) Interface

Reading information interface is as follows:

Create the implementation class of following interface, when developing character code conversion UOC.

Figure I-5 FigureCSCOwnCodeReaderContext implementation class

[Figure]

Interface name
CSCOwnCodeReaderContext interface

Description
This is reading information interface.
Package name of CSCOwnCodeReaderContext is jp.co.Hitachi.soft.csc.dt.uoc.CSCOwnCodeReaderContext.
Uses the parsing result of CSCOwnCodeReader to pass to the data transformation process.
Generates 1 instance in 1 thread. In CSCOwnCodeReader#readChar, parsing result of character string must be set to the implementation class of CSCOwnCodeReaderContext. The set information is referenced in the data transformation process.

Format
 
package jp.co.Hitachi.soft.csc.dt.uoc ;
 
public interface CSCOwnCodeReaderContext {
 
      int getPosition() ;
 
      int getLength() ;
 
      boolean canSeparate() ;
}
 

Methods
Following table describes the methods of CSCOwnCodeReaderContext interface.
Method name Description
getPosition method This method returns the current character position or size of data to be read.
getLength method This method returns the current character length.
canSeparate method This method returns whether to consider the current character as the separator parsing target.

When data transformation target is variable length character string and separator has been set in the binary format definition, data transformation executes the separator parsing process. Following figure shows the order of invoking each method of CSCOwnCodeReader and CSCOwnCodeReaderContext.

Figure I-6 FigureOrder of invoking each method of CSCOwnCodeReader and CSCOwnCodeReaderContext

[Figure]

  1. Generating an instance
    Generate an instance of CSCOwnCodeReader by data transformation.
  2. CSCOwnCodeReader#start method
    Generate an instance of self-thread dedicated CSCOwnCodeReaderContext. Here onwards, deliver of values with CSCOwnCodeReader is executed by instance of CSCOwnCodeReaderContext saved by self-thread.
  3. CSCOwnCodeReader#readChar method
    At the time of executing readChar, data transformation process passes the instance of CSCOwnCodeReaderContext to the argument. In process of readChar, parsing result is set in the instance of CSCOwnCodeReaderContext. The set parsing result is used for parsing the separator in the data transformation process.
  4. getPosition method, getLength method, canSeparate method
    The respective methods are invoked from data transformation. Method execution order depends on the message format.
    • getPosition method
      This method returns the current character position.
    • getLength method
      This method returns the current character length.
    • canSeparate method
      This method returns whether to consider the current character as the separator parsing target.
  5. CSCOwnCodeReader#end method
    When parsing process of implementation class of CSCOwnCodeReaderContext is required, execute end method.
(a) getPosition method

Description
When result of readChar is true, returns the current character position.
When result of readChar is false, returns the size of data that can be read.

Format
 
public int getPosition()
 

Parameter
None

Exception
None

Return value
Current character position and size (unit is byte) of the data that can be read. Position of offset passed by CSCOwnCodeReader#start is considered as 0.
(b) getLength method

Description
Returns the current character length.

Format
 
public int getLength()
 

Parameter
None

Exception
None

Return value
Returns the current character length.
(c) canSeparate method

Description
Returns whether to consider the current character as the separator parsing target. When false is returned, even if the byte string of separator match with the current character, it is not considered as separator.

Format
 
public boolean canSeparate()
 

Parameter
None

Exception
None

Return value
Returns true when separator is to be parsed.
Returns false when separator is not to be parsed.

(2) Exception class

Exception class that occurs at the time of developing character code conversion UOC is as follows:

Class name
CSCOwnCodeConverterException class

Description
This exception is sent when error occurs during the character code conversion process.
When this exception occurs, entire data transformation process is aborted.

(3) Implementation example(MS932)

Implementation example (MS932) of CSCOwnCodeReaderContext interface is as follows:

public class CSCOwnCodeReaderContextImpl implements CSCOwnCodeReaderContext {
 
    private final byte[] data ;
 
    private int position = 0 ;
 
    private int next = 0 ;
 
    private int length = 0 ;
 
 
    public CSCOwnCodeReaderContextImpl(
        final byte[] data ) {
 
        this.data = data ;
    }
 
 
    @Override
    public int getPosition() {
 
        return position ;
    }
 
 
    @Override
    public int getLength() {
 
        return length ;
    }
 
 
    @Override
    public boolean canSeparate() {
 
        // MS932 does not have shift (escape sequence) status and
        // no limitation for occurrence of separator. Hence, always returns true
        return true ;
    }
 
 
    public byte[] getData() {
 
        return data ;
    }
 
 
    public void setPosition( int position ) {
 
        this.position = position ;
    }
 
 
    public void setLength( int length ) {
 
        this.length = length ;
    }
 
 
    public int getNextPosition() {
 
        return this.next ;
    }
 
 
    public void setNextPosition( int position ) {
 
        this.next = position ;
    }
}
 

(4) Implementation example (IBM Kanji code)

Implementation example (IBM Kanji code) of CSCOwnCodeReaderContext interface is as follows:

public class CSCOwnCodeReaderContextImpl implements CSCOwnCodeReaderContext {
 
    private final byte[] data ;
 
    private int position = 0 ;
 
    private int length = 1 ;
 
    private int next = 0 ;
 
    private boolean canSeparate = true ;
 
 
    public CSCOwnCodeReaderContextImpl( final byte[] data ) {
 
        this.data = data ;
    }
 
 
    @Override
    public int getPosition() {
 
        return position ;
    }
 
 
    @Override
    public int getLength() {
 
        return length ;
    }
 
 
    @Override
    public boolean canSeparate() {
 
        return canSeparate ;
    }
 
 
    public byte[] getData() {
 
        return data ;
    }
 
 
    public void setPosition( int position ) {
 
        this.position = position ;
    }
 
 
    public void setLength( int length ) {
 
        this.length = length ;
    }
 
 
    public void setCanSeparate( boolean canSeparate ) {
 
        this.canSeparate = canSeparate ;
    }
 
 
    public int getNextPosition() {
 
        return this.next ;
    }
 
 
    public void setNextPosition( int position ) {
 
        this.next = position ;
    }
}