KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > fractal > julia > loader > Loader


1 /***
2  * Julia: France Telecom's implementation of the Fractal API
3  * Copyright (C) 2001-2002 France Telecom R&D
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Contact: Eric.Bruneton@rd.francetelecom.com
20  *
21  * Author: Eric Bruneton
22  */

23
24 package org.objectweb.fractal.julia.loader;
25
26 import java.util.Map JavaDoc;
27
28 /**
29  * An interface to load classes or to generate them on the fly.
30  */

31
32 public interface Loader {
33
34   /**
35    * Initializes this loader.
36    *
37    * @param context the initialization arguments.
38    * @throws Exception if the initialization fails.
39    */

40   
41   void init (Map JavaDoc context) throws Exception JavaDoc;
42   
43   /**
44    * Loads the tree whose name is given.
45    *
46    * @param name a tree name.
47    * @return the tree whose name is given.
48    * @throws Exception if the tree is not found or cannot be loaded.
49    */

50   
51   Tree loadTree (String JavaDoc name) throws Exception JavaDoc;
52
53   /**
54    * Evaluates the given tree in the given context. Each leaf node of the given
55    * tree whose name begins with ' is replaced by the evaluation of the tree
56    * associated to this name in the given context (except if the result of this
57    * evaluation is "QUOTE"). For example the evaluation of "('x d)" in a context
58    * where x is associated to "(a 'y)", y is associated to "(b 'z)", and z is
59    * associated to "QUOTE" gives "((a (b 'z)) d)".
60    *
61    * @param tree the tree to be evaluated.
62    * @param context a map associating names to trees.
63    * @return the evaluated tree.
64    * @throws Exception if a name is not found in the given context. The
65    * exception's detail is equal to this name.
66    */

67
68   Tree evalTree (Tree tree, Map JavaDoc context) throws Exception JavaDoc;
69
70   /**
71    * Creates and returns the object whose description is given.
72    *
73    * @param objectDescriptor the descriptor of the object to be created. This
74    * descriptor must be either of the form "className", or of the form
75    * "(classDescriptor arg1 ... argN)". In the first case, "className"
76    * must be the fully qualified name of a class. In the second case,
77    * "classDescriptor" must be a valid class descriptor (see {@link
78    * #loadClass(Tree) loadClass}). "arg1" ... "argN" can be arbitrary
79    * trees.
80    * @param loader an optional class loader to load auxiliary classes.
81    * @return an object created according to the given description. If this
82    * description is of the form "className", this method returns a new
83    * instance of the "className" class (which must have a default public
84    * constructor). If the description is of the form "(classDescriptor
85    * arg1 ... argN)", the class described by "classDescriptor" is loaded or
86    * generated with the {@link #loadClass loadClass} method, and a new
87    * instance of this class is created (this class must have a default
88    * public constructor). Then, if the arguments "arg1 ... argN" are not
89    * empty, the {@link Initializable#initialize initialize} method is used
90    * to initialize the previous instance (in this case, the
91    * "classDescriptor" class must implement the {@link Initializable}
92    * interface; the {@link Initializable#initialize initialize} method is
93    * called with <tt>(arg1 ... argN)</tt> as parameter). Finally the
94    * previously created object is returned.
95    * @throws Exception if the specified object cannot be created.
96    */

97
98   Object JavaDoc newObject (Tree objectDescriptor, Object JavaDoc loader) throws Exception JavaDoc;
99
100   /**
101    * Loads the class whose name is given.
102    *
103    * @param className the fully qualified name of the class to be returned.
104    * @param loader an optional class loader to load auxiliary classes.
105    * @return the class whose name is given.
106    * @throws ClassNotFoundException if the specified class is not found.
107    */

108
109   Class JavaDoc loadClass (String JavaDoc className, Object JavaDoc loader) throws ClassNotFoundException JavaDoc;
110
111   /**
112    * Loads or generates the class whose descriptor is given.
113    *
114    * @param classDescriptor the descriptor of the class to be loaded or
115    * dynamically generated. This descriptor must be either of the form
116    * "className", or of the form "(objectDescriptor arg1 ... argN)". In the
117    * first case, "className" must be the fully qualified name of a class.
118    * In the second case, "objectDescriptor" must be a valid object
119    * descriptor (see {@link #newObject newObject}), describing an object
120    * that implements the {@link
121    * org.objectweb.fractal.julia.asm.ClassGenerator} interface.
122    * "arg1" ... "argN" can be arbitrary trees.
123    * @param loader an optional class loader to load auxiliary classes.
124    * @return the class whose description is given. If this description is of the
125    * form "className", this method returns the "className" class. If the
126    * description is of the form "(objectDescriptor arg1 ... argN)", the
127    * class generator described by "objectDescriptor" is instantiated with
128    * the {@link #newObject newObject} method, and its {@link
129    * org.objectweb.fractal.julia.asm.ClassGenerator#generateClass
130    * generateClass} method is used to generate a class (this method is
131    * called with <tt>classDescriptor</tt> as second argument), which is
132    * finally returned.
133    * @throws ClassNotFoundException is the specified class cannot be loaded or
134    * dynamically generated.
135    */

136
137   Class JavaDoc loadClass (Tree classDescriptor, Object JavaDoc loader) throws ClassNotFoundException JavaDoc;
138 }
139
Popular Tags