KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > loader > enhancer > ClassEnhancerConfig


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

29
30 package com.caucho.loader.enhancer;
31
32 import com.caucho.bytecode.JClass;
33 import com.caucho.bytecode.JavaClass;
34 import com.caucho.config.ConfigException;
35 import com.caucho.java.gen.GenClass;
36 import com.caucho.util.L10N;
37
38 import java.util.logging.Logger JavaDoc;
39
40 /**
41  * Configuration for a class-enhancer builder.
42  */

43 public class ClassEnhancerConfig implements ClassEnhancer {
44   private static final L10N L = new L10N(ClassEnhancerConfig.class);
45
46   private static final Logger JavaDoc log =
47     Logger.getLogger(ClassEnhancerConfig.class.getName());
48   
49   private EnhancerManager _manager;
50   
51   private Class JavaDoc _annotation;
52   private Class JavaDoc _type;
53   private boolean _isStatic = true;
54
55   private ClassEnhancer _enhancer;
56
57   /**
58    * Sets the manager.
59    */

60   public void setEnhancerManager(EnhancerManager manager)
61   {
62     _manager = manager;
63   }
64
65   /**
66    * Sets the annotation.
67    */

68   public void setAnnotation(Class JavaDoc ann)
69   {
70     _annotation = ann;
71   }
72
73   /**
74    * Gets the annotation.
75    */

76   public Class JavaDoc getAnnotation()
77   {
78     return _annotation;
79   }
80   
81   /**
82    * Sets the type of the method enhancer.
83    */

84   public void setType(Class JavaDoc type)
85     throws Exception JavaDoc
86   {
87     _type = type;
88
89     if (ClassEnhancer.class.isAssignableFrom(type)) {
90       _enhancer = (ClassEnhancer) type.newInstance();
91     }
92     else
93       throw new ConfigException(L.l("'{0}' is an unsupported class enhancer type. ClassEnhancer is required.",
94                     type.getName()));
95   }
96
97   /**
98    * Set true for a static instance.
99    */

100   public void setStatic(boolean isStatic)
101   {
102     _isStatic = isStatic;
103   }
104
105   /**
106    * Initializes the enhancer.
107    */

108   public Object JavaDoc createInit()
109   {
110     return _enhancer;
111   }
112
113   /**
114    * Initializes the config.
115    */

116   public void init()
117     throws ConfigException
118   {
119     // _enhancer.setAnnotation(_annotation);
120
}
121   
122   /**
123    * Returns true if the class will be enhanced.
124    */

125   public boolean shouldEnhance(String JavaDoc className)
126   {
127     return _enhancer.shouldEnhance(className);
128   }
129
130   /**
131    * Fixups for the pre-enhancement class.
132    */

133   public void preEnhance(JavaClass baseClass)
134     throws Exception JavaDoc
135   {
136     _enhancer.preEnhance(baseClass);
137   }
138
139   /**
140    * Enhances the class by adding to the GenClass.
141    */

142   public void enhance(GenClass genClass,
143               JClass baseClass,
144               String JavaDoc extClassName)
145     throws Exception JavaDoc
146   {
147     _enhancer.enhance(genClass, baseClass, extClassName);
148   }
149   
150   /**
151    * Any post compilation fixups.
152    */

153   public void postEnhance(JavaClass extClass)
154     throws Exception JavaDoc
155   {
156     _enhancer.postEnhance(extClass);
157   }
158 }
159
Popular Tags