01: /*
02: * Copyright 1999-2004 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package com.opensymphony.webwork.util.classloader;
17:
18: import com.opensymphony.webwork.util.classloader.compilers.JavaCompiler;
19: import com.opensymphony.webwork.util.classloader.compilers.eclipse.EclipseJavaCompiler;
20: import com.opensymphony.webwork.util.classloader.listeners.CompilingListener;
21: import com.opensymphony.webwork.util.classloader.monitor.FilesystemAlterationMonitor;
22: import com.opensymphony.webwork.util.classloader.stores.MemoryResourceStore;
23: import com.opensymphony.webwork.util.classloader.stores.TransactionalResourceStore;
24: import com.uwyn.rife.continuations.ClassByteAware;
25:
26: import java.io.File;
27:
28: /**
29: * @author tcurdt
30: */
31: public class CompilingClassLoader extends ReloadingClassLoader
32: implements ClassByteAware {
33:
34: private final TransactionalResourceStore transactionalStore;
35: private final JavaCompiler compiler;
36:
37: public CompilingClassLoader(final ClassLoader pParent,
38: final File pRepository) {
39: this (pParent, pRepository, new TransactionalResourceStore(
40: new MemoryResourceStore()) {
41: public void onStart() {
42: }
43:
44: ;
45:
46: public void onStop() {
47: }
48:
49: ;
50: });
51: }
52:
53: public CompilingClassLoader(final ClassLoader pParent,
54: final File pRepository,
55: final TransactionalResourceStore pStore) {
56: this (pParent, pRepository, pStore, new EclipseJavaCompiler());
57: }
58:
59: public CompilingClassLoader(final ClassLoader pParent,
60: final File pRepository,
61: final TransactionalResourceStore pStore,
62: final JavaCompiler pCompiler) {
63: super (pParent, pRepository, pStore);
64: transactionalStore = pStore;
65: compiler = pCompiler;
66: }
67:
68: public byte[] getClassBytes(String classname)
69: throws ClassNotFoundException {
70: return transactionalStore.read(classname);
71: }
72:
73: public void start() {
74: fam = new FilesystemAlterationMonitor();
75:
76: // FIXME keep reference for accessing errors/warnings
77: listener = new CompilingListener(reader, compiler,
78: transactionalStore) {
79: public void reload() {
80: super .reload();
81: CompilingClassLoader.this .reload();
82: }
83: };
84:
85: fam.addListener(listener, repository);
86: thread = new Thread(fam);
87: fam.doRun();
88: thread.start();
89: }
90: }
|