ClassFileManager.java
Go to the documentation of this file.
00001 package com.rosalfred.core.ia.rivescript.lang.java;
00002 
00003 import java.io.IOException;
00004 import java.security.SecureClassLoader;
00005 import java.util.HashMap;
00006 
00007 import javax.tools.FileObject;
00008 import javax.tools.ForwardingJavaFileManager;
00009 import javax.tools.JavaFileManager;
00010 import javax.tools.JavaFileObject;
00011 import javax.tools.StandardJavaFileManager;
00012 import javax.tools.JavaFileObject.Kind;
00013 
00014 public class ClassFileManager
00015         extends ForwardingJavaFileManager<JavaFileManager> {
00016 
00021     private HashMap<String, JavaClassObject> jclassObjects =
00022             new HashMap<String, JavaClassObject>();
00023 
00030     public ClassFileManager(StandardJavaFileManager standardManager) {
00031         super(standardManager);
00032     }
00033 
00041     @Override
00042     public ClassLoader getClassLoader(Location location) {
00043         return new SecureClassLoader() {
00044 
00045             @Override
00046             protected Class<?> findClass(String name)
00047                     throws ClassNotFoundException {
00048 
00049                 if (jclassObjects.containsKey(name)) {
00050                     JavaClassObject jclassObject = jclassObjects.get(name);
00051                     byte[] b = jclassObject.getBytes();
00052 
00053                     return super.defineClass(
00054                             name,
00055                             jclassObject.getBytes(),
00056                             0,
00057                             b.length);
00058                 }
00059 
00060                 return null;
00061             }
00062         };
00063     }
00064 
00069     @Override
00070     public JavaFileObject getJavaFileForOutput(Location location,
00071             String className, Kind kind, FileObject sibling)
00072                     throws IOException {
00073         JavaClassObject jclassObject;
00074 
00075         if (sibling instanceof CharSequenceJavaFileObject) {
00076                 ((CharSequenceJavaFileObject) sibling).setQualifiedName(className);
00077         }
00078 
00079         //if (!this.jclassObjects.containsKey(className)) {
00080             jclassObject = new JavaClassObject(className, kind);
00081             if (jclassObjects.containsKey(className));
00082                 this.jclassObjects.put(className, jclassObject);
00083         //} else {
00084         //    jclassObject = this.jclassObjects.get(className);
00085         //}
00086 
00087         return jclassObject;
00088     }
00089 }


alfred_bot
Author(s): Mickael Gaillard , Erwan Le Huitouze
autogenerated on Tue Jun 14 2016 01:34:50