All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class macrolanguage.MacroExtention

java.lang.Object
   |
   +----java.lang.ClassLoader
           |
           +----macrolanguage.MacroExtention

public class MacroExtention
extends ClassLoader
To use the MacroExtention you must simply add it to your program and add an interface for selecting the macro, then use the simple methods of this class to compile and execute a macro. The class offers several features: 1. Interation with your application. 2. The full power you had writing the application will be available to your users. 3. You can add a sandbox to block some functionality. 4. You can ship upgrades/fixes as plugins. 5. Other vendors and users can easly write plugins. 6. Plugins will be fully integrate, cross platform and run in the same speed as the VM. It is recommended you expose some of your softwares internal's to your users to make this tool the most effective. There is great room for improvment in the loading from JAR's. did not implemtent any cahcing and the loader searchs the JAR every time. It should be rather simple to implement a Hashtable which will cache the JAR.


Variable Index

 o classCache
 o compilerClass
Notice the long name.
 o dataStream
 o jarFileName
 o streamSize

Constructor Index

 o MacroExtention()
the default constructor does nothing except create an instance of sun.tools.javac.Main for later use.

Method Index

 o compile(String)
This method accepts a java file as parameter and compiles it.
 o getClassData(String)
This method returns the data within the disk file to the class loader so it can load the class.
 o getClassDataFromJAR(String, String)
This method returns the data within the JAR to the class loader so it can load a class.
 o getCompilationErrors()
This method returns a vector in which all the compilation errors are stored as strings.
 o getJarInputStream(String, String)
this method returns an InputStream to the fileName we are looking for.
 o getObject(String)
This method accepts a class file as parameter and returns an instance of it.
 o getResource(String)
Find a resource with a given name.
 o getResourceAsStream(String)
Get an InputStream on a given resource.
 o loadClass(String, boolean)
the load class method loads a class file from the disk or from a jar file and resolves the class with the JVM.
 o loadObject(String)
creats an instance of a class by getting its name and returns that instance, or null if none were found.
 o main(String[])
I use this method in my experimenting and chose not to remove it since it may be of interest for the readers.
 o setJARFileName(String)
this is a setter for the current JAR file name.

Variables

 o compilerClass
 private Main compilerClass
Notice the long name. It's here to avoid namespace problems with another Main

 o dataStream
 private SimpleStream dataStream
 o classCache
 private Hashtable classCache
 o jarFileName
 private transient String jarFileName
 o streamSize
 private transient int streamSize

Constructors

 o MacroExtention
 MacroExtention()
the default constructor does nothing except create an instance of sun.tools.javac.Main for later use.

Methods

 o compile
 public boolean compile(String fileName)
This method accepts a java file as parameter and compiles it. It returns true if compilation was successful and false otherwize.

 o getClassData
 public byte[] getClassData(String className) throws IOException
This method returns the data within the disk file to the class loader so it can load the class. This version of the method loads the class file from the disk. The className is the name and path of the file.

 o getClassDataFromJAR
 public byte[] getClassDataFromJAR(String className,
                                   String jarFileName) throws IOException
This method returns the data within the JAR to the class loader so it can load a class. This version of the method loads the class file from a JAR archive. The className is the name and path of the file in the JAR the jarFileName is the full name of the JAR file.

 o getCompilationErrors
 public Vector getCompilationErrors()
This method returns a vector in which all the compilation errors are stored as strings.

 o getJarInputStream
 private synchronized InputStream getJarInputStream(String fileName,
                                                    String jarFileName) throws IOException
this method returns an InputStream to the fileName we are looking for. The fileName must be fully qualified for search in the zip: all subdirectories shiould use the / notation, i.e.: this file \VisualDeveloper\FreeFormEdit.class should in fact be /VisualDeveloper/FreeFormEdit.class

 o getObject
 public Object getObject(String fileName) throws ClassNotFoundException, InstantiationException, IllegalAccessException
This method accepts a class file as parameter and returns an instance of it.

 o getResource
 public URL getResource(String name)
Find a resource with a given name. The return is a URL to the resource. Doing a getContent() on the URL may return an Image, an AudioClip, or an InputStream. The class loader can choose what to do to locate the resource.

Overrides:
getResource in class ClassLoader
 o getResourceAsStream
 public InputStream getResourceAsStream(String name)
Get an InputStream on a given resource. Will return null if no resource with this name is found. The class loader can choose what to do to locate the resource.

Overrides:
getResourceAsStream in class ClassLoader
 o loadClass
 protected Class loadClass(String className,
                           boolean callReslove)
the load class method loads a class file from the disk or from a jar file and resolves the class with the JVM. This method can be extended to support loading classes from a web site or any othe source. When developing a class loader security can be a major thorn, if you load classes from the internet make sure you habdle the security issue correctly.

Overrides:
loadClass in class ClassLoader
 o loadObject
 public Object loadObject(String className)
creats an instance of a class by getting its name and returns that instance, or null if none were found.

 o main
 public static void main(String argv[])
I use this method in my experimenting and chose not to remove it since it may be of interest for the readers.

 o setJARFileName
 public void setJARFileName(String fileName)
this is a setter for the current JAR file name. once set to a certin file all class loader queries will be redirected to the JAR fileName. This must be set to null when no JAR is being used.


All Packages  Class Hierarchy  This Package  Previous  Next  Index