com.microfocus.cobol.lang
Class Pointer

java.lang.Object
  extended bycom.microfocus.cobol.lang.Pointer
All Implemented Interfaces:
Cloneable, DataType
Direct Known Subclasses:
Pointer

public class Pointer
extends Object
implements DataType, Cloneable

Pointer class is a helper class for passing String/StringBuffer to COBOL in a type-safe manor

Copyright: Copyright (c) 2002-2003
Company: Micro Focus International Ltd

Since:
Net Express 4.0, Server Express 4.0

Description

Allows StringBuffer/String/byte[] types to be passed to a COBOL program without requiring the COBOL source to be modified to use mf-jarray.
Version:
3.17, 6/18/03

Constructor Summary
Pointer(byte[] bytes)
          Construct a Pointer to a bytes[] array.
CAUTION You must ensure the length of the byte[] is the same as the picture clause defined in the COBOL program.
Pointer(String initString)
          Constructor a Pointer to a string for passing to a COBOL program

CAUTION You must ensure the size of Java string is the same as the size defined in the COBOL programs picture clause.
Pointer(StringBuffer initString)
          Construct a Pointer to a StringBuffer for passing to a COBOL program
CAUTION You must ensure the capacity of StringBuffer is large enough to be passed into the COBOL program.
Pointer(StringBuffer initString, String encoding)
          Construct a Pointer to a StringBuffer given a specific encoding.
Pointer(String initString, int capacity)
          Construct a Pointer to a string with a set capacity for passing to a COBOL program.
Pointer(String initString, int capacity, String encoding)
          Construct a Pointer to a string with a set capacity for passing to a COBOL program.
Pointer(String initString, int capacity, String encoding, String filler)
          Construct a Pointer to a string with a set capacity for passing to a COBOL program.
Pointer(String initString, String encoding)
          Construct a fixed length string with a specific encoding.
CAUTION You must ensure the size of Java string is the same as the size defined in the COBOL programs picture clause.
 
Method Summary
 Object clone()
          clone method
 byte[] getBytes()
          Internal class method that returns a byte[] that represents its COBOL value for use in cobcall().
 String getEncoding()
          get the encoding (or default if not set)
 void setEncoding(String encoding)
          set the encoding for Pointer See sun's site for supported encodings
 void synchronizeData()
          Internal class method that is called when the COBOL byte[] (from getBytes()) is changed by the COBOL program.
 String toString()
          Returns a String representation of the Pointer in the specified encoding
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Pointer

public Pointer(byte[] bytes)
Construct a Pointer to a bytes[] array.
CAUTION You must ensure the length of the byte[] is the same as the picture clause defined in the COBOL program.

 For example to pass a byte[20] to a COBOL program that expects the value
 in pic x(20)

 The Java would be:

 public static void main(String[] args) throws Exception
 {
 StringBuffer myString = new StringBuffer();
 myString.append("Hello from Java 1234");             // filled to size 20
 byte ourBytes[] = myString.toString().getBytes();    // get byte[]
 Object parms[] = { new Pointer(ourBytes) };          // setup parameters
 Runtime.cobcall("showbytes",parms);                  // call our program
 System.out.println(new String(ourBytes));
 }

 and the COBOL would be:

 working-storage section.
 linkage section.
 01 lnk-string pic x(20).
 procedure division using lnk-string.
 display "lnk-string = " lnk-string.
 move "Hello from COBOL" to lnk-string.
 exit program returning 0.

 

Parameters:
bytes - a byte[]
See Also:
RuntimeSystem.cobcall(java.lang.Object, java.lang.String, java.lang.Object[], int[], boolean), RuntimeSystem.ccall(java.lang.Object, java.lang.String, java.lang.Object[], int[])

Pointer

public Pointer(StringBuffer initString)
Construct a Pointer to a StringBuffer for passing to a COBOL program
CAUTION You must ensure the capacity of StringBuffer is large enough to be passed into the COBOL program.
 For example to pass a StringBuffer with at least a capacity of 20
 to a COBOL program that expects the value in pic x(20)

 public static void main(String[] args) throws Exception
 {
 StringBuffer myString = new StringBuffer();
 myString.ensureCapacity(20);                      // size of at least 20
 myString.append("Hello from Java");
 Object parms[] = { new Pointer(myString) };       // setup parameters
 Runtime.cobcall("showbytes",parms);               // call our program
 System.out.println(new String(myString));
 }

 and the COBOL would be:

 working-storage section.
 linkage section.
 01 lnk-string pic x(20).
 procedure division using lnk-string.
 display "lnk-string = " lnk-string.
 move "Hello from COBOL" to lnk-string.
 exit program returning 0.
 

Parameters:
initString - a stringbuffer with a capacity specified via ensureCapacity()
See Also:
RuntimeSystem.cobcall(java.lang.Object, java.lang.String, java.lang.Object[], int[], boolean), RuntimeSystem.ccall(java.lang.Object, java.lang.String, java.lang.Object[], int[])

Pointer

public Pointer(StringBuffer initString,
               String encoding)
        throws UnsupportedEncodingException
Construct a Pointer to a StringBuffer given a specific encoding. See sun's site for supported encodings

Parameters:
initString -
encoding -
Throws:
UnsupportedEncodingException
See Also:
Pointer(StringBuffer)

Pointer

public Pointer(String initString)
Constructor a Pointer to a string for passing to a COBOL program

CAUTION You must ensure the size of Java string is the same as the size defined in the COBOL programs picture clause.

Parameters:
initString -
See Also:
Pointer(String,int), RuntimeSystem.cobcall(java.lang.Object, java.lang.String, java.lang.Object[], int[], boolean), RuntimeSystem.ccall(java.lang.Object, java.lang.String, java.lang.Object[], int[])

Pointer

public Pointer(String initString,
               String encoding)
        throws UnsupportedEncodingException
Construct a fixed length string with a specific encoding.
CAUTION You must ensure the size of Java string is the same as the size defined in the COBOL programs picture clause. See sun's site for supported encodings

Parameters:
initString -
encoding -
Throws:
UnsupportedEncodingException

Pointer

public Pointer(String initString,
               int capacity)
Construct a Pointer to a string with a set capacity for passing to a COBOL program. The string is padded with space if it is smaller.

Parameters:
initString -
capacity -
See Also:
RuntimeSystem.cobcall(java.lang.Object, java.lang.String, java.lang.Object[], int[], boolean), RuntimeSystem.ccall(java.lang.Object, java.lang.String, java.lang.Object[], int[])

Pointer

public Pointer(String initString,
               int capacity,
               String encoding)
        throws UnsupportedEncodingException
Construct a Pointer to a string with a set capacity for passing to a COBOL program. The string is padded with space if it is smaller. Encoding can also be specified.

Parameters:
initString -
capacity -
encoding -
Throws:
UnsupportedEncodingException
See Also:
RuntimeSystem.cobcall(java.lang.Object, java.lang.String, java.lang.Object[], int[], boolean), RuntimeSystem.ccall(java.lang.Object, java.lang.String, java.lang.Object[], int[])

Pointer

public Pointer(String initString,
               int capacity,
               String encoding,
               String filler)
        throws UnsupportedEncodingException
Construct a Pointer to a string with a set capacity for passing to a COBOL program. The string is padded with the given filler if it is smaller. Encoding can also be specified.

Parameters:
initString -
capacity -
encoding -
filler -
Throws:
UnsupportedEncodingException
See Also:
RuntimeSystem.cobcall(java.lang.Object, java.lang.String, java.lang.Object[], int[], boolean), RuntimeSystem.ccall(java.lang.Object, java.lang.String, java.lang.Object[], int[])
Method Detail

synchronizeData

public void synchronizeData()
Internal class method that is called when the COBOL byte[] (from getBytes()) is changed by the COBOL program.

Specified by:
synchronizeData in interface DataType
See Also:
DataType, getBytes()

getBytes

public byte[] getBytes()
Internal class method that returns a byte[] that represents its COBOL value for use in cobcall().

Specified by:
getBytes in interface DataType
Returns:
a byte[] for the Pointer type
See Also:
DataType

toString

public String toString()
Returns a String representation of the Pointer in the specified encoding

Returns:
the string

clone

public Object clone()
             throws CloneNotSupportedException
clone method

Returns:
a cloned object
Throws:
CloneNotSupportedException

getEncoding

public String getEncoding()
get the encoding (or default if not set)

Returns:
a string representing the encoding

setEncoding

public void setEncoding(String encoding)
                 throws UnsupportedEncodingException
set the encoding for Pointer See sun's site for supported encodings

Parameters:
encoding -
Throws:
UnsupportedEncodingException



Copyright © 2000 Micro Focus International Limited. All rights reserved.
This document and the proprietary marks and names used herein are protected by international law.