ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/experimental/agents/AgentClassLoader.java
Revision: 1.1
Committed: Sun May 6 19:01:48 2001 UTC (23 years, 6 months ago) by ajm
Branch: MAIN
CVS Tags: HEAD
Log Message:
Now has some VERY crude byte code passing mechanisms in place.

Currently it does it a very silly and non standard way, this will change.  But hey, it works ;p

File Contents

# User Rev Content
1 ajm 1.1 //---PACKAGE DECLARATION---
2    
3     //---IMPORTS---
4     import java.util.Hashtable;
5     import java.io.ByteArrayInputStream;
6     import java.io.FileInputStream;
7    
8     /**
9     * <ONE LINE DESCRIPTION>
10     * <DETAILED DESCRIPTION>
11     *
12     * @author $Author: ajm4 $
13     * @version $Id: TemplateClass.java,v 1.1 2001/05/04 19:03:34 ajm4 Exp $
14     */
15     public class AgentClassLoader extends ClassLoader {
16    
17     //---FINAL / FINAL STATIC ATTRIBUTES---
18    
19     /**
20     * The current CVS revision of this class
21     */
22     public static final String REVISION = "$Revision: 1.1 $";
23    
24     //---STATIC METHODS---
25    
26     //---CONSTRUCTORS---
27    
28     public AgentClassLoader(ClassLoader parent) {
29     super(parent);
30     }
31    
32     //---PUBLIC METHODS---
33    
34     public void defineAgentClass(byte[] byteCode) throws ClassFormatError {
35     defineClass(null, byteCode, 0, byteCode.length);
36     }
37    
38     public byte[] getBytecode(String className) {
39     byte result[];
40     try {
41     FileInputStream fi = new FileInputStream(className+".class");
42     result = new byte[fi.available()];
43     fi.read(result);
44     return result;
45     } catch (Exception e) {
46    
47     /*
48     * If we caught an exception, either the class wasnt found or it
49     * was unreadable by our process.
50     */
51     _logger.write(toString(), Logger.DEBUG, "I/O Error when loading class - " + e);
52     return null;
53     }
54     }
55    
56     /**
57     * Overrides the {@link java.lang.Object#toString() Object.toString()}
58     * method to provide clean logging (every class should have this).
59     *
60     * This uses the uk.ac.ukc.iscream.util.FormatName class
61     * to format the toString()
62     *
63     * @return the name of this class and its CVS revision
64     */
65     public String toString() {
66     return FormatName.getName(
67     _name,
68     getClass().getName(),
69     REVISION);
70     }
71    
72     //---PRIVATE/PROTECTED METHODS---
73    
74     //---ACCESSOR/MUTATOR METHODS---
75    
76     //---ATTRIBUTES---
77    
78     /**
79     * This is the friendly identifier of the
80     * component this class is running in.
81     * eg, a Filter may be called "filter1",
82     * If this class does not have an owning
83     * component, a name from the configuration
84     * can be placed here. This name could also
85     * be changed to null for utility classes.
86     */
87     private String _name = "AgentClassLoader";
88    
89     /**
90     * This holds a reference to the
91     * system logger that is being used.
92     */
93     private Logger _logger = Logger.getInstance();
94    
95     //---STATIC ATTRIBUTES---
96    
97     }