All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.zeroturnaround.javarebel.integration.javaxel.BeanELResolverCBP Maven / Gradle / Ivy

The newest version!
package org.zeroturnaround.javarebel.integration.javaxel;

import org.zeroturnaround.bundled.javassist.ClassPool;
import org.zeroturnaround.bundled.javassist.CtClass;
import org.zeroturnaround.bundled.javassist.CtMethod;
import org.zeroturnaround.bundled.javassist.NotFoundException;
import org.zeroturnaround.javarebel.integration.support.JavassistClassBytecodeProcessor;

/**
 * Transforms javax.el.BeanELResolver in JSP 2.1 API.
 * 
 * @author Rein Raudjärv
 */
public class BeanELResolverCBP extends JavassistClassBytecodeProcessor {

  public void process(ClassPool cp, ClassLoader cl, CtClass ctClass) throws Exception {
    try {
      CtMethod m = ctClass.getMethod("getBeanProperty",
      "(Ljavax/el/ELContext;Ljava/lang/Object;Ljava/lang/Object;)Ljavax/el/BeanELResolver$BeanProperty;");

      m.setBody(
          "{" +
          "  java.lang.String property = $3.toString();" +
          "  java.lang.Class baseClass = $2.getClass();" +
          "  javax.el.BeanELResolver.BeanProperties bps = (javax.el.BeanELResolver.BeanProperties) properties.get(baseClass);" +
          "  if (bps == null) {" +
          "    bps = new javax.el.BeanELResolver.BeanProperties(baseClass);" +
          "    properties.put(baseClass, bps);" +
          "  }" +
          "  javax.el.BeanELResolver.BeanProperty bp = bps.getBeanProperty(property);" +
          
          // START of added code
          "  if (bp == null) {" +
          // Maybe new property was added - rescan
          "    bps = new javax.el.BeanELResolver.BeanProperties(baseClass);" +
          "    properties.put(baseClass, bps);" +
          "    bp = bps.getBeanProperty(property);" +
          "  }" +
          // END of added code
          
          "  if (bp == null) {" +
          "    throw new javax.el.PropertyNotFoundException(" +
          "        javax.el.ELUtil.getExceptionMessageString($1, \"propertyNotFound\", new java.lang.Object[] { baseClass.getName(), property }));" +
          "  } else {" +
          "    return bp;" +
          "  }" +
          "}");
    }
    catch (NotFoundException e) {
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy