public class ExtensionLoader extends Object
Title: CASA Agent Infrastructure
Copyright: Copyright (c) 2003-2014, Knowledge Science Group, University of Calgary. Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation. The Knowledge Science Group makes no representations about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty.
Company: Knowledge Science Group, Department of Computer Science, University of Calgary
This class is responsible for discovering all extensions at application startup time, and then acting as a repository for extension object at run time.Modifier and Type | Field and Description |
---|---|
private Set<Extension> |
extensions
the set of all known extension objects.
|
private static ExtensionLoader |
instance
The singleton ExtensionLoader object.
|
Modifier | Constructor and Description |
---|---|
private |
ExtensionLoader()
This constructor is private.
|
Modifier and Type | Method and Description |
---|---|
private String |
capitalize(String s) |
(package private) static ExtensionLoader |
get()
Access to the singleton object.
|
(package private) ExtensionDescriptor[] |
getAllExtensionDescriptors() |
private Class<Extension> |
getClassForType(String type) |
private File[] |
getFilesFromDir(File dir,
String fileExtension)
Returns a list of all files in the directory dir with the file extension fileExtension.
|
static void |
loadType(String type,
AbstractInternalFrame frame,
AbstractProcess agent)
Calls
Extension.load(AbstractInternalFrame, AbstractProcess) on every know extension that matches
the type with the parameters frame and agent. |
static void |
main(String[] args)
Simple test of this class.
|
private Pair<String,Integer> |
parseEntryName(String s)
Returns s with any digits at the end removed.
|
private File[] |
processCandidateFiles()
At application initialization, search out all extension files (files ending in ".lisp" or ".jar") residing
in ~/.casa/extensions or the /extensions/ directory in the application jar file.
|
private void |
processJarFile(File file)
Processes a jar file for one or more Extension objects.
|
private void |
processLispFile(File file,
InputStream stream)
Reads a lisp file to determine the attributes it should have as an Extension.
|
String |
toString() |
private static ExtensionLoader instance
private ExtensionLoader()
static ExtensionLoader get()
private File[] processCandidateFiles()
Extension.load(AbstractInternalFrame, AbstractProcess)
method with both parameters set to null.private File[] getFilesFromDir(File dir, String fileExtension)
dir
- The directory to search.fileExtension
- The file extension. If it does not have a prefix ".", then one is added before searching.public static void main(String[] args)
toString()
method on the singleton instance.args
- Ignored.private void processLispFile(File file, InputStream stream)
The parameters seem redundant, but in the case of reading within a jar, the caller may keep the stream open and
pass it to this method in the second (stream) parameter. If the second parameter is null, a file stream
will be created from the first (file) parameter.
The created Extension object is added to extensions
.
file
- The file to read.stream
- The steam for the file. May be null.private void processJarFile(File file)
extensions
.file
- private Class<Extension> getClassForType(String type)
type
- The type (usually "code", "tab", or "LispScript").Extension
class.
The type is automatically converted to first-letter-capitalized and any dashes converted to camel case.
public static void loadType(String type, AbstractInternalFrame frame, AbstractProcess agent)
Extension.load(AbstractInternalFrame, AbstractProcess)
on every know extension that matches
the type with the parameters frame and agent. This method is called at process
startup (with type==null, frame==null and agent==null), at agent initialization
(with type==null, frame==null and agent==the started-up agent), and may be called
from places like GUI menus (with frame!=null and agent!=null). It is up to the individual
Extension types to distinguish these situations and act (or not act) accordingly.type
- The type of the extension: , , or ; may be null to indicate all (wildcard).frame
- The agent GUI element this is applied to.agent
- The agent this is applied to.private String capitalize(String s)
s
- private Pair<String,Integer> parseEntryName(String s)
s
- public String toString()
toString
in class Object
Object.toString()
ExtensionDescriptor[] getAllExtensionDescriptors()