private void loadPatchersAndJavaScriptObjects() throws Exception {
    jsoSubClasses = new HashSet<String>();
    patchers = new HashMap<String, Patcher>();
    List<String> classList = findScannedClasses();
    CtClass jsoCtClass = GwtClassPool.get().get(JSO_CLASSNAME);
    for (String className : classList) {
      CtClass ctClass = GwtClassPool.get().get(className);
      if (ctClass.subclassOf(jsoCtClass) && !ctClass.equals(jsoCtClass)) {
        jsoSubClasses.add(className);
      } else if (ctClass.hasAnnotation(PatchClass.class)) {

        treatPatchClass(ctClass);
      }
    }
  }
 private void enhanceClass(Enhancer enhancer, File file) {
   byte[] enhancedBytecode = null;
   InputStream is = null;
   CtClass clas = null;
   try {
     is = new FileInputStream(file.toString());
     clas = getClassPool().makeClass(is);
     if (!clas.hasAnnotation(Entity.class)) {
       getLog().debug("Class $file not an annotated Entity class. skipping...");
     } else {
       enhancedBytecode = enhancer.enhance(clas.getName(), clas.toBytecode());
     }
   } catch (Exception e) {
     getLog().error("Unable to enhance class [${file.toString()}]", e);
     return;
   } finally {
     try {
       if (null != is) is.close();
     } catch (IOException ioe) {
     }
   }
   if (null != enhancedBytecode) {
     if (file.delete()) {
       try {
         if (!file.createNewFile()) {
           getLog().error("Unable to recreate class file [" + clas.getName() + "]");
         }
       } catch (IOException ioe) {
       }
     } else {
       getLog().error("Unable to delete class file [" + clas.getName() + "]");
     }
     FileOutputStream outputStream = null;
     try {
       outputStream = new FileOutputStream(file, false);
       outputStream.write(enhancedBytecode);
       outputStream.flush();
     } catch (IOException ioe) {
     } finally {
       try {
         if (outputStream != null) outputStream.close();
         clas.detach(); // release memory
       } catch (IOException ignore) {
       }
     }
   }
 }
Exemplo n.º 3
0
 @Override
 public boolean isCompositeClass(CtClass classDescriptor) {
   return classDescriptor.hasAnnotation(Embeddable.class);
 }
Exemplo n.º 4
0
 @Override
 public boolean isEntityClass(CtClass classDescriptor) {
   return classDescriptor.hasAnnotation(Entity.class);
 }