001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.loader.enhancer;
031:
032: import com.caucho.bytecode.JClass;
033: import com.caucho.bytecode.JavaClass;
034: import com.caucho.config.ConfigException;
035: import com.caucho.java.gen.GenClass;
036: import com.caucho.util.L10N;
037:
038: import java.util.logging.Logger;
039:
040: /**
041: * Configuration for a class-enhancer builder.
042: */
043: public class ClassEnhancerConfig implements ClassEnhancer {
044: private static final L10N L = new L10N(ClassEnhancerConfig.class);
045:
046: private static final Logger log = Logger
047: .getLogger(ClassEnhancerConfig.class.getName());
048:
049: private EnhancerManager _manager;
050:
051: private Class _annotation;
052: private Class _type;
053: private boolean _isStatic = true;
054:
055: private ClassEnhancer _enhancer;
056:
057: /**
058: * Sets the manager.
059: */
060: public void setEnhancerManager(EnhancerManager manager) {
061: _manager = manager;
062: }
063:
064: /**
065: * Sets the annotation.
066: */
067: public void setAnnotation(Class ann) {
068: _annotation = ann;
069: }
070:
071: /**
072: * Gets the annotation.
073: */
074: public Class getAnnotation() {
075: return _annotation;
076: }
077:
078: /**
079: * Sets the type of the method enhancer.
080: */
081: public void setType(Class type) throws Exception {
082: _type = type;
083:
084: if (ClassEnhancer.class.isAssignableFrom(type)) {
085: _enhancer = (ClassEnhancer) type.newInstance();
086: } else
087: throw new ConfigException(
088: L
089: .l(
090: "'{0}' is an unsupported class enhancer type. ClassEnhancer is required.",
091: type.getName()));
092: }
093:
094: /**
095: * Set true for a static instance.
096: */
097: public void setStatic(boolean isStatic) {
098: _isStatic = isStatic;
099: }
100:
101: /**
102: * Initializes the enhancer.
103: */
104: public Object createInit() {
105: return _enhancer;
106: }
107:
108: /**
109: * Initializes the config.
110: */
111: public void init() throws ConfigException {
112: // _enhancer.setAnnotation(_annotation);
113: }
114:
115: /**
116: * Returns true if the class will be enhanced.
117: */
118: public boolean shouldEnhance(String className) {
119: return _enhancer.shouldEnhance(className);
120: }
121:
122: /**
123: * Fixups for the pre-enhancement class.
124: */
125: public void preEnhance(JavaClass baseClass) throws Exception {
126: _enhancer.preEnhance(baseClass);
127: }
128:
129: /**
130: * Enhances the class by adding to the GenClass.
131: */
132: public void enhance(GenClass genClass, JClass baseClass,
133: String extClassName) throws Exception {
134: _enhancer.enhance(genClass, baseClass, extClassName);
135: }
136:
137: /**
138: * Any post compilation fixups.
139: */
140: public void postEnhance(JavaClass extClass) throws Exception {
141: _enhancer.postEnhance(extClass);
142: }
143: }
|