next up previous contents
Next: A.4 Datei break-it-up.pl Up: A Konvertieren von MOF- Previous: A.2 Datei pass2.pl

A.3 Datei pass3.pl

#!/usr/bin/perl -w
#
# Converting MOF-files to .mo-files, Step 3
#
# Author: Christian Schiller
# Date:   08/15/98
#

%objtype = (
   "boolean" => "Boolean",
   "char" => "Character",
   "byte" => "Byte",
   "short" => "Short",
   "int" => "Integer",
   "long" => "Long",
   "float" => "Float",
   "double" => "Double"
	    );

# output filename
$_ = $ARGV[0];
/_(\w+)\.mo/i;
$filename = $1 . ".mo";

print STDERR "output will be written to $filename\n";

open (OUTPUT, ">$filename");

while(<>) {

    # copy everything to the output
    print OUTPUT;

    # add get/set funcions for the attributes
  SWITCH: {
      # extract the class name and add appropriate constructor
      /class\s+(\w+)Impl/ && do { $classname = $1; &addConstructor(); };

      # add get/set functions for reference types
      /String\s+(\w+);/ && do { &getSetRef("String", $1); last SWITCH };
      /BigInteger\s+(\w+);/ && do {&getSetRef("BigInteger", $1); last SWITCH };

      # add get/set functions for  primitive types
      /boolean\s+(\w+);/ && do { &getSetPrim("boolean", $1); last SWITCH };
      /char\s+(\w+);/ && do { &getSetPrim("char", $1); last SWITCH };
      /byte\s+(\w+);/ && do { &getSetPrim("byte", $1); last SWITCH };
      /short\s+(\w+);/ && do { &getSetPrim("short", $1); last SWITCH };
      /int\s+(\w+);/ && do { &getSetPrim("int", $1); last SWITCH };
      /long\s+(\w+);/ && do { &getSetPrim("long", $1); last SWITCH };
      /float\s+(\w+);/ && do { &getSetPrim("float", $1); last SWITCH };
      /double\s+(\w+);/ && do { &getSetPrim("double", $1); last SWITCH };

  }
}

sub addConstructor {
    # read until opening '{', then add constructor
    while (<>) {
	/\{/ || do { print OUTPUT; next; };
	last;
    }
    print OUTPUT;                   # '{'
    print OUTPUT <<HERE;
    public ${classname}Impl() throws RemoteException {
    }
HERE
    print OUTPUT "\n";
}

# for reference types
sub getSetRef {
    my ($type, $attrib) = @_;

    print OUTPUT <<HERE;
    public $type getAttr$attrib(Session session)
        throws AuthorizationException, RemoteException
    {
	    return ($type) getPropertyByName(session, \"$attrib\");
    }
    public void setAttr$attrib(Session session, $type $attrib)
        throws NotInUpdateException, AuthorizationException, RemoteException
    {
            setPropertyByName(session, \"$attrib\", $attrib);
    }
HERE
}

# for primitive types
sub getSetPrim {
    my ($type, $attrib) = @_;

    print OUTPUT <<HERE;
    public $type getAttr$attrib(Session session)
        throws AuthorizationException, RemoteException 
    {
	    return (($objtype{$type}) getPropertyByName(session, \"$attrib\")).${type}Value();
    }
    public void setAttr$attrib(Session session, $type $attrib)
        throws NotInUpdateException, AuthorizationException, RemoteException
    {
            setPropertyByName(session, \"$attrib\", new $objtype{$type}($attrib));
    }
HERE
}



Copyright Munich Network Management Team