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.
-
classCache
-
-
compilerClass
- Notice the long name.
-
dataStream
-
-
jarFileName
-
-
streamSize
-
-
MacroExtention()
- the default constructor does nothing except create an instance
of sun.tools.javac.Main for later use.
-
compile(String)
- This method accepts a java file as parameter
and compiles it.
-
getClassData(String)
- This method returns the data within the disk file to the class loader
so it can load the class.
-
getClassDataFromJAR(String, String)
- This method returns the data within the JAR to the class loader so it
can load a class.
-
getCompilationErrors()
- This method returns a vector in which all
the compilation errors are stored as strings.
-
getJarInputStream(String, String)
- this method returns an InputStream to the fileName we are looking
for.
-
getObject(String)
- This method accepts a class file as parameter
and returns an instance of it.
-
getResource(String)
- Find a resource with a given name.
-
getResourceAsStream(String)
- Get an InputStream on a given resource.
-
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.
-
loadObject(String)
- creats an instance of a class by getting its name
and returns that instance, or null if none were found.
-
main(String[])
- I use this method in my experimenting and chose not to remove it
since it may be of interest for the readers.
-
setJARFileName(String)
- this is a setter for the current JAR file name.
compilerClass
private Main compilerClass
- Notice the long name. It's here to avoid namespace
problems with another Main
dataStream
private SimpleStream dataStream
classCache
private Hashtable classCache
jarFileName
private transient String jarFileName
streamSize
private transient int streamSize
MacroExtention
MacroExtention()
- the default constructor does nothing except create an instance
of sun.tools.javac.Main for later use.
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.
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.
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.
getCompilationErrors
public Vector getCompilationErrors()
- This method returns a vector in which all
the compilation errors are stored as strings.
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
getObject
public Object getObject(String fileName) throws ClassNotFoundException, InstantiationException, IllegalAccessException
- This method accepts a class file as parameter
and returns an instance of it.
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
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
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
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.
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.
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