Java2OWL
Class J2OSynchroniser

Object
  extended by J2OSynchroniser
All Implemented Interfaces:
ClassFileTransformer

public class J2OSynchroniser
extends Object
implements ClassFileTransformer

This is the program which manipulates the annotated compiled class files to insert the code for synchronising Java and OWL.

An example is: The class

 @J2OWLClass(name = "Person", OWLSuperClasses = "LivingThing")
 class Person {
 boolean male; 
 public TestPerson(boolean male) {this.male = male;}
 
 @J2OWLProperty(setter = "setGender", required=true)
 public boolean isMale(){return male;}
 
 public void setGender(boolean male){
      this.male = male;}}
 
would be changed to
 @J2OWLClass(name = "Person", OWLSuperClasses = "LivingThing")
 class Person {
 boolean male;  
 public static J2OIndividualManager j2OWLIndividualManager;
 public boolean j2OWLNoSynchronizationByObject;
 private static Method J2OWL_getter_isMale = J2OSynchroniser.getMethod(TestPackage/TestPerson, "isMale");
 
 J2OIndividualManager J2OSynchronisationActive() {
    Java2OWLFlags |= 6;
    return  (Java2OWLFlags & 1) == 0 ? null : j2OWLIndividualManager;}
 
 public TestPerson(boolean male) {this.male = male;}
 
 @J2OWLProperty(setter = "setGender", required=true)
 public boolean isMale(){return male;}
 
 public void setGender(boolean male){
 if(J2OSynchronisationActive() != null)
      J2OSynchronisationActive().exchangePropertyValue(this, J2OWL_getter_isMale, Boolean.valueOf(isMale()), Boolean.valueOf(male));
      this.male = male;}}
 

The variables j2OWLIndividualManager and Java2OWLFlags are injected in each class even in subclasses. This means, if A is a subclass of B then A has these two variables twice, its own pair and the inherited pair. The method J2OSynchronisationActive() accesses the pair belonging to the object's actual class. Therefore one can, for example, activate synchronisation for a superclass and deactivate it for a subclass.


Field Summary
 String dump
          For test purposes: a filename where the transformed class is to be dumped.
 
Constructor Summary
J2OSynchroniser()
          creates a new J2OSynchroniser
 
Method Summary
static Method getMethod(Class jcl, String name)
          returns jcl's method with the given name.
static void main(String[] args)
           
 byte[] transform(ClassLoader loader, String className, Class redefiningClass, ProtectionDomain domain, byte[] bytes)
          This method is called by the class loader.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dump

public String dump
For test purposes: a filename where the transformed class is to be dumped.

Constructor Detail

J2OSynchroniser

public J2OSynchroniser()
creates a new J2OSynchroniser

Method Detail

transform

public byte[] transform(ClassLoader loader,
                        String className,
                        Class redefiningClass,
                        ProtectionDomain domain,
                        byte[] bytes)
                 throws IllegalClassFormatException
This method is called by the class loader. It initiates the transformation

Specified by:
transform in interface ClassFileTransformer
Throws:
IllegalClassFormatException

getMethod

public static Method getMethod(Class jcl,
                               String name)
returns jcl's method with the given name. Exceptions are printed, but otherwise suppressed.


main

public static void main(String[] args)