Class ClassAdapter

java.lang.Object
org.rexxla.bsf.engines.rexx.ClassAdapter

public class ClassAdapter extends Object
This class creates a proxied Java class on the fly, which has concrete implementations for all abstract (inherited or not) methods. Additionally it allows for creating proxy methods for concrete methods and matching "_forwardToSuper" methods to allow ooRexx to forward proxied Java method invocations to their original target on the Java side.
------------------------ Apache Version 2.0 license -------------------------
    Copyright (C) 2010-2019 Rony G. Flatscher

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
 ----------------------------------------------------------------------------- 
Since:
2010
Version:
1.04, 2010-03-27, 2010-04-14, 2010-04-17, 2010-04-18, 2010-11-30, 2011-05-31, 2014-08-30, 2016-11-01, 2016-11-04/5, 2017-03-13, 2019-08-24
Author:
Rony G. Flatscher (WU-Wien/Wirtschaftsuniversität Wien, http://www.wu.ac.at)
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static boolean
    Flag that determines whether the generated class name should get the CRC32 value appended, defaults to true.
    static boolean
    Flag that determines whether the supplied newName should get the CRC32 value appended, defaults to true.
    static boolean
    Flag that determines whether the generated class name should get the hash value of the class object appended, defaults to false.
    static boolean
    Controls whether the generated file name's date and time portion should contain the date portion only, defaults to false.
    static boolean
    Controls whether the generated file name includes a date and time portion, defaults to true.
    static boolean
    Controls whether the generated file name should be led in with the extended class' simple name, defaults to true.
    static boolean
    Flag that determines whether the generated program should be stored in the file system.
    static boolean
     
    static boolean
     
    static String
    String that gets appended to the generated class name to ease locating such classes, defaults to "_$RexxExtendClass$_".
    static String
    Package name that will replace the package name of the extended class, defaults to "org.rexxla.bsf.engines.rexx.onTheFly".
    static String
    Path where a generated program should be stored to, defaults to the Java temporary directory (System.getProperty("java.io.tmpdir")).
    static final String
    Version information on this class.
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    Calculate the CRC32 value for the supplied string and return an uppercased hex-string.
    static Class
    createProxiedJavaClass(Class javaClassToProxy, String strNewClzName, String[] methodNames2proxy, Class[] interfaceClasses)
    Creates and returns a proxy class in which Java method invocations get forwarded to a RexxProxy.
    static String
    Creates and formats a Date object.
    static String
    Formats a Date object.
    static void
    main(String[] args)
    Allow using this class from the command line to create an extended Java class and displaying the generated source.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • bTiming

      public static boolean bTiming
    • bShowSource

      public static boolean bShowSource
    • version

      public static final String version
      Version information on this class.
      See Also:
    • bFileNameWithSimpleName

      public static boolean bFileNameWithSimpleName
      Controls whether the generated file name should be led in with the extended class' simple name, defaults to true.
    • bFileNameWithDateTime

      public static boolean bFileNameWithDateTime
      Controls whether the generated file name includes a date and time portion, defaults to true.
    • bFileNameWithDateOnly

      public static boolean bFileNameWithDateOnly
      Controls whether the generated file name's date and time portion should contain the date portion only, defaults to false.
    • bSaveToFilesystem

      public static boolean bSaveToFilesystem
      Flag that determines whether the generated program should be stored in the file system.
    • bAddCRC32toNewName

      public static boolean bAddCRC32toNewName
      Flag that determines whether the supplied newName should get the CRC32 value appended, defaults to true. The CRC32 value gets calculated from the string values of the arguments such that the same arguments are expected to create the same CRC32 value.
    • bAddCRC32toGeneratedClassName

      public static boolean bAddCRC32toGeneratedClassName
      Flag that determines whether the generated class name should get the CRC32 value appended, defaults to true.
    • bAddHashToGeneratedClassName

      public static boolean bAddHashToGeneratedClassName
      Flag that determines whether the generated class name should get the hash value of the class object appended, defaults to false. If name clashes occur in an application due to having duplicate CRC32 values generated, then setting this flag to true should allow for creating unique class names thereafter.
    • extensionIndicator

      public static String extensionIndicator
      String that gets appended to the generated class name to ease locating such classes, defaults to "_$RexxExtendClass$_".
    • packageName

      public static String packageName
      Package name that will replace the package name of the extended class, defaults to "org.rexxla.bsf.engines.rexx.onTheFly". If the value is null, then the package name will not be replaced. If the value is the empty String (length of 0), then the package of the extended class will be removed.
    • pathToSaveTo

      public static String pathToSaveTo
      Path where a generated program should be stored to, defaults to the Java temporary directory (System.getProperty("java.io.tmpdir")).
  • Method Details

    • main

      public static void main(String[] args) throws org.apache.bsf.BSFException
      Allow using this class from the command line to create an extended Java class and displaying the generated source. Example:
      java java org.rexxla.bsf.engines.rexx.ClassAdapter javax.swing.AbstractAction ronysClass "*"
      Parameters:
      args - array of blank delimited Strings in the form of "fullJavaClassName [newClassName [methodToProxy [...]]". If there is a single method to proxy with a value of "*" (asterisk), then all declared methods will get proxied.
      Throws:
      org.apache.bsf.BSFException - if any execution error occurs
    • createProxiedJavaClass

      public static Class createProxiedJavaClass(Class javaClassToProxy, String strNewClzName, String[] methodNames2proxy, Class[] interfaceClasses) throws org.apache.bsf.BSFException
      Creates and returns a proxy class in which Java method invocations get forwarded to a RexxProxy.
      Parameters:
      javaClassToProxy - Class object to use for proxying
      strNewClzName - null or name for proxy class to create
      methodNames2proxy - an array denoting the protected or public methods to proxy. Please note: each proxied class will get all public/protected abstract methods and constructors created (proxied).
      Each method name element denotes a public or protected single method which may be optionally preceeded by a blank and preceeded by the name of some Java superclass to be used for looking up the method definitions to proxy. The following special cases apply for this argument:
      • if this argument is null, then only the public/protected abstract methods and constructors get proxied.
      • if this argument has no elements (its lengthfield is 0), then only the public/protected abstract methods and constructors get proxied.
      • if this argument has a single element with the value "*" (asterisk), then all public/protected methods and constructors get proxied.
      interfaceClasses - optional, the extended class should in addition implement all abstract methods of these interface classes
      Returns:
      the class object representing the extended class
      Throws:
      org.apache.bsf.BSFException - if any execution error occurs
    • formatDateTime

      public static String formatDateTime()
      Creates and formats a Date object. Depending on bFileNameWithDateOnly the time portion may be left out.
      Returns:
      formatted Date object representing the date and time of invocation
    • formatDateTime

      public static String formatDateTime(Date d)
      Formats a Date object. Depending on bFileNameWithDateOnly the time portion may be left out.
      Parameters:
      d - the Date object to format
      Returns:
      formatted Date object representing
    • calcCRC32

      public static String calcCRC32(String str)
      Calculate the CRC32 value for the supplied string and return an uppercased hex-string.
      Parameters:
      str - the String for which the checksum should get calculated
      Returns:
      the uppercased hexadecimal value