KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > versant > core > compiler > PizzaClassCompiler


1
2 /*
3  * Copyright (c) 1998 - 2005 Versant Corporation
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  * Versant Corporation - initial API and implementation
11  */

12 package com.versant.core.compiler;
13
14 import com.versant.lib.pizzacompiler.compiler.SrcCompiler;
15
16 import java.util.Map JavaDoc;
17 import java.util.Collection JavaDoc;
18 import java.util.HashMap JavaDoc;
19 import java.util.Iterator JavaDoc;
20 import java.io.PrintStream JavaDoc;
21 import java.io.ByteArrayOutputStream JavaDoc;
22
23 import com.versant.core.common.BindingSupportImpl;
24
25 /**
26  * ClassCompiler implementation that compiles classes using the Pizza compiler.
27  * Pizza is a superset of Java and the compiler is very fast.
28  */

29 public class PizzaClassCompiler implements ClassCompiler {
30
31     public Map JavaDoc compile(Map JavaDoc classMap, ClassLoader JavaDoc loader) {
32         try {
33             ByteArrayOutputStream JavaDoc buf = new ByteArrayOutputStream JavaDoc();
34             PrintStream JavaDoc out = new PrintStream JavaDoc(buf, false);
35             Collection JavaDoc c = SrcCompiler.compile(classMap, loader, out);
36             out.close();
37             if (buf.size() > 0) {
38                 String JavaDoc msg = buf.toString();
39                 throw BindingSupportImpl.getInstance().internal(msg);
40             }
41             HashMap JavaDoc ans = new HashMap JavaDoc();
42             for (Iterator JavaDoc i = c.iterator(); i.hasNext(); ) {
43                 byte[] bytecode = (byte[])i.next();
44                 ans.put(ClassFileUtils.getClassName(bytecode), bytecode);
45             }
46             return ans;
47         } catch (Throwable JavaDoc t) {
48             if (BindingSupportImpl.getInstance().isOwnException(t)) {
49                 throw (RuntimeException JavaDoc)t;
50             }
51             throw BindingSupportImpl.getInstance().internal(t.toString(), t);
52         }
53     }
54
55 }
56
57
Popular Tags