artefaktur
software engineer &        architecture

 
 
 
 

acdk_java_serialization Manual



The package provides a java compatible object serialization.


See also  Sample.

Content of this chapter:

   Type mapping
     Basic Types
     Arrays of basic
   Arrays of Objects
   Arrays of basic
     Create Typemappings for own ACDK classes
     Modify the type mapping
     Define own writer and reader methods.
   Sample



 Type mapping

Java and ACDK has similar but not identical object model.
Therefore for serialization a type mapping between Java and ACDK is necessary.

 Basic Types

Basic types will be serialized in network byte order.
In Java a character is 16 bit wide (like a short). In ACDK a character is only 8 bit wide (like a byte). At the moment no transformation (UTF8/16) will be made in conversion of characters from ACDK to Java and vice version.
Transfering data from Java to ACDK information about the higher 8 bytes may be lost.

 Arrays of basic

Similar to the meta-information of ACDK classes with generated structures ::acdk::lang::dmi::ClazzInfo, there is also a database for the typmapping using static structs of type ::acdk::java::serialization::ClassTypeMapping.

The typmapping for some standard Java/ACDK classes can be found in the files a2jser_acdk_lang.cpp, a2jser_acdk_util.cpp, and so on in the directory ./src/acdk/java/serialization.

 Arrays of Objects

The type mapping of Objects is supported via a user defined type mapping.
(See below.)

 Arrays of basic

The serialization of the basic types and Object in one dimensional arrays is supperted. Not supported are serialization of multi dimensional arrays.

 Create Typemappings for own ACDK classes

To create own type mappings you can use the Java programm ./src/java/JavaClassDeclToAcdkSer.java.
promt> javac JavaClassDeclToAcdkSer java.package.ClassName
The output can be copied/appended into a .cpp source file.

 Modify the type mapping


The default mapping can be modified:
  • Name of member
  • Type of member

!

Do not delete member definition of the type mapping, because the original Java serialization is still needed to write a correct Java class description to the stream.

 Define own writer and reader methods.


In the struct ClassTypeMapping the members read_func and write_func can be overwritten to define own methods to read/write an Object in a Java compatible way.

Please refer to the file acdk_java/src/acdk/java/serialization/a2jser_acdk_util.cpp and the other a2jser_* files to look some examples.

!

In the read_func function the newly created ACDK-Object has to be registered before reading other members.

RObject 
a2jser_read_acdk_util_ArrayList(IN(::acdk::java::serialization::RJavaObjectReader) in, 
                                const ::acdk::java::serialization::ClassTypeMapping* ctm)
{
  int count = in->readInt();
  RArrayList al = new ArrayList();
  in->registerNewObject(&al); // register Object.
  for (int i = 0; i < count; ++i)
  {
    al->add(in->readObject());
  }
  return al;
}

:acdk::java::serialization::ClassTypeMapping a2jser_java_util_ArrayList = 
{
  "acdk/util/ArrayList", // acdk_name
  "java/util/ArrayList", // java_name
  "", // acdk_super
  "", // java_super
  ::acdk::java::serialization::SC_SERIALIZABLE, // flags
  JLONG_CONSTANT(0x7881d21d99c7619d), // UID
  JLONG_CONSTANT(0x788cfdda08df1046), //[] UID
  a2jser_java_util_ArrayList_fields, // Fields
  a2jser_read_acdk_util_ArrayList, // read_func
  a2jser_write_acdk_util_ArrayList, // write_func
  0 // used for internal linked list
};

 Sample

Please refer to  Sample.
 
Last modified 2005-05-08 22:31 by SYSTEM By Artefaktur, Ing. Bureau Kommer