KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > bsf > smartValueObject > tools > Instrumentor


1 package org.bsf.smartValueObject.tools;
2
3 import java.util.Properties JavaDoc;
4
5 /**
6  * Minimal set of methods for instrumenting classes.
7  * <p>A Class implementing instrumentor is seen
8  * as a "black-box" which makes passed in classes versionable and
9  * hands out the bytecode needed.
10  * <p>The general idea is to be independent of the underlying implementation.
11  */

12 public interface Instrumentor {
13     /** Interface to be used for versionable objects. */
14     String JavaDoc VERSIONINTERFACE = "org.bsf.smartValueObject.Versionable";
15     /** Default implementation for VERSIONINTERFACE. */
16     String JavaDoc VERSIONCLASS = "org.bsf.smartValueObject.Version";
17     /** The helper class used by instrumentors + TOs (on runtime) */
18     String JavaDoc VERSIONHELPER = "org.bsf.smartValueObject.VersionHelper";
19     /** Name of the field in versionable classes. */
20     String JavaDoc VERSIONFIELD = "version";
21     /** Method to call upon field write access. */
22     String JavaDoc VERSIONMETHOD = "touch";
23     /** To verify is object has been altered. */
24     String JavaDoc DIRTYMETHOD = "isDirty";
25     /** Method to clean flags. */
26     String JavaDoc CLEANMETHOD = "markClean";
27     /** To verify if object is marked for deletion. */
28     String JavaDoc DELETEDMETHOD = "isDeleted";
29     /** To verify if object has newly created. */
30     String JavaDoc CREATEDMETHOD = "isCreated";
31     /** Mark object for deletion. */
32     String JavaDoc DELETEMETHOD = "delete";
33     /** Mark object as freshly created. */
34     String JavaDoc CREATEMETHOD = "create";
35
36     /** A replacement for <tt>java.util.Collection</tt>. */
37     String JavaDoc SMARTCOLLECTION = "org.bsf.smartValueObject.container.SmartCollection";
38     /** A replacement for <tt>java.util.Map</tt>. */
39     String JavaDoc SMARTMAP = "org.bsf.smartValueObject.container.SmartMap";
40     /** A replacement for <tt>java.util.List</tt>. */
41     String JavaDoc SMARTLIST = "org.bsf.smartValueObject.container.SmartList";
42     /** A replacement for <tt>java.util.Set</tt>. */
43     String JavaDoc SMARTSET = "org.bsf.smartValueObject.container.SmartSet";
44
45     /** A map containing container classes and their smart replacements. */
46     Properties JavaDoc SMARTCONTAINERS = SmartReplacements.containerReplacementProps;
47
48     /**
49      * Modifies this class.
50      *
51      * @param name class to modify, package notation or filename.
52      * @throws org.bsf.smartValueObject.tools.InstrumentorException in case of errors
53      */

54     void modifyClass(String JavaDoc name) throws InstrumentorException;
55     void modifyClass(String JavaDoc basedir, String JavaDoc file) throws InstrumentorException;
56
57     /**
58      * Get modified class as byte array.
59      *
60      * @return versionable class as bytecode.
61      * @throws org.bsf.smartValueObject.tools.InstrumentorException
62      */

63     byte[] getBytecode() throws InstrumentorException;
64
65     /**
66      * Use internal classloader to build class object.
67      * <p>Exists rather for testing purposes, as classes won't be compatible !
68      *
69      * @return Versionable class.
70      */

71     Class JavaDoc defineClass();
72
73     public static class SmartReplacements {
74         private static final Properties JavaDoc containerReplacementProps = new Properties JavaDoc();
75         static final String JavaDoc[][] containerReplacements = {
76           { "java.util.Collection", SMARTCOLLECTION },
77           { "java.util.Map", SMARTMAP },
78           { "java.util.List", SMARTLIST },
79           { "java.util.Set", SMARTSET }
80         };
81
82         static {
83             for (int i = 0; i < containerReplacements.length; i++) {
84                 String JavaDoc[] containerReplacement = containerReplacements[i];
85                 containerReplacementProps.setProperty(
86                     containerReplacement[0],
87                     containerReplacement[1]);
88             }
89         }
90     }
91 }
92
Popular Tags