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

org.zeroturnaround.javarebel.integration.javaxel.BeanELResolverElCommonsCBP 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$BeanProperties.
 */
public class BeanELResolverElCommonsCBP extends JavassistClassBytecodeProcessor {

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

			m.setBody("{\n" + 
					"   javax.el.BeanELResolver$BeanProperty property = this.properties.get($2);\n" + 
					"   if (property == null) {\n" + 
					"      $0.properties.clear();\n" + 
					"      java.beans.Introspector.flushFromCaches($0.type);\n" + 
					"      \n" + 
					"      try {\n" + 
					"         java.beans.BeanInfo info = java.beans.Introspector.getBeanInfo(this.type);\n" + 
					"         java.beans.PropertyDescriptor[] pds = info.getPropertyDescriptors();\n" + 
					"         for (int i = 0; i < pds.length; i++) {\n" + 
					"            this.properties.put(pds[i].getName(), new javax.el.BeanELResolver$BeanProperty(\n" + 
					"                  type, pds[i]));\n" + 
					"         }\n" + 
					"      } catch (java.beans.IntrospectionException ie) {\n" + 
					"         throw new javax.el.ELException(ie);\n" + 
					"      }\n" + 
					"      property = this.properties.get($2);\n" + 
					"      if (property == null) {\n" + 
					"         throw new javax.el.PropertyNotFoundException(javax.el.ELResolver.message($1,\n" + 
					"               \"propertyNotFound\",\n" + 
					"               new java.lang.Object[] { type.getName(), $2 }));\n" + 
					"      }\n" + 
					"   }\n" + 
					"   return property;\n" + 
					"}");
		}
		catch (NotFoundException e) {
		  // JSP 2.1 API contains this class but not such method
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy