01: /*
02: * Copyright (c) 1998 - 2005 Versant Corporation
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * Versant Corporation - initial API and implementation
10: */
11: package com.versant.core.compiler;
12:
13: import com.versant.lib.pizzacompiler.compiler.SrcCompiler;
14:
15: import java.util.Map;
16: import java.util.Collection;
17: import java.util.HashMap;
18: import java.util.Iterator;
19: import java.io.PrintStream;
20: import java.io.ByteArrayOutputStream;
21:
22: import com.versant.core.common.BindingSupportImpl;
23:
24: /**
25: * ClassCompiler implementation that compiles classes using the Pizza compiler.
26: * Pizza is a superset of Java and the compiler is very fast.
27: */
28: public class PizzaClassCompiler implements ClassCompiler {
29:
30: public Map compile(Map classMap, ClassLoader loader) {
31: try {
32: ByteArrayOutputStream buf = new ByteArrayOutputStream();
33: PrintStream out = new PrintStream(buf, false);
34: Collection c = SrcCompiler.compile(classMap, loader, out);
35: out.close();
36: if (buf.size() > 0) {
37: String msg = buf.toString();
38: throw BindingSupportImpl.getInstance().internal(msg);
39: }
40: HashMap ans = new HashMap();
41: for (Iterator i = c.iterator(); i.hasNext();) {
42: byte[] bytecode = (byte[]) i.next();
43: ans
44: .put(ClassFileUtils.getClassName(bytecode),
45: bytecode);
46: }
47: return ans;
48: } catch (Throwable t) {
49: if (BindingSupportImpl.getInstance().isOwnException(t)) {
50: throw (RuntimeException) t;
51: }
52: throw BindingSupportImpl.getInstance().internal(
53: t.toString(), t);
54: }
55: }
56:
57: }
|