<%@ page import="javax.servlet.jsp.*,javax.el.*,javax.naming.*,javax.inject.*"%> <%@ page import="javax.enterprise.inject.spi.*"%> <%@ page import="java.util.*,java.lang.annotation.*,java.lang.reflect.*,java.io.*,java.text.Collator"%> <%@ page import="org.apache.webbeans.container.*"%> test JSP <%! class BeanSorter implements Comparator> { @Override public int compare(Bean o1, Bean o2) { String s1 = (String) o1.getBeanClass().getName(); String s2 = (String) o2.getBeanClass().getName(); return s1.toLowerCase().compareTo(s2.toLowerCase()); } } String getBeanValue(String beanName, String beanMethod, PageContext pageContext) { ExpressionFactory factory = JspFactory.getDefaultFactory().getJspApplicationContext(pageContext.getServletContext()).getExpressionFactory(); ELContext elContext = pageContext.getELContext(); String beanExpression = "${" + beanName + "." + beanMethod + "}"; if (beanMethod.equals("toString")) { beanExpression = "${" + beanName + "}"; } ValueExpression expression = factory.createValueExpression(elContext, beanExpression, String.class); return expression.getValue(elContext).toString(); } void dumpBeanManager(BeanManagerImpl manager, JspWriter out, String baseURL) throws IOException { Set> beans = null; beans = manager.getComponents(); out.println("

beans

"); ArrayList> sorted = new ArrayList>(beans); Collections.sort(sorted, new BeanSorter()); Iterator> it = sorted.iterator(); out.println("
    "); while (it.hasNext()) { Bean b = it.next(); // classloader issue with ELResolver built-in bean if (b.getBeanClass().getName().indexOf("java") == 0) { continue; } if(b.getQualifiers().toString().indexOf("enterprise.inject.New") != -1) { continue; } String defaultELName = b.getBeanClass().getSimpleName(); char[] n = defaultELName.toCharArray(); n[0] = Character.toLowerCase(n[0]); defaultELName = new String(n); out.println("
  • " + b.getBeanClass().getName() + "
  • "); } out.println("
"); it = sorted.iterator(); while (it.hasNext()) { StringBuffer sb = new StringBuffer(); Bean b = it.next(); // classloader issue with ELResolver built-in bean if (b.getBeanClass().getName().indexOf("java") == 0) { continue; } if(b.getQualifiers().toString().indexOf("enterprise.inject.New") != -1) { continue; } String defaultELName = b.getBeanClass().getSimpleName(); char[] n = defaultELName.toCharArray(); n[0] = Character.toLowerCase(n[0]); defaultELName = new String(n); sb.append("

" + b.getBeanClass().getName() + "

");

            sb.append("\n\t\t\t [" + b.getBeanClass().getSimpleName() + "] Scope: " + b.getScope().toString());
            sb.append("\n\t\t\t [" + b.getBeanClass().getSimpleName() + "] API types: " + b.getTypes().toString());
            sb.append("\n\t\t\t [" + b.getBeanClass().getSimpleName() + "] qualifiers: " + b.getQualifiers().toString());

            sb.append("\n\t\t\t [" + b.getBeanClass().getSimpleName() + "] annotations: ");
            for (Annotation a : b.getClass().getAnnotations()) {
                sb.append(a.getClass().getName() + ", ");
            }

            sb.append("\n\t\t\t stereotypes: ");
            for (Class stereo : b.getStereotypes()) {
                sb.append(stereo.getClass().getName() + ", ");
            }

            
            sb.append("\n\t\t\t methods: ");

             for (Method m : b.getBeanClass().getMethods()) {
              	String defaultMethodName = null;
              	
                 if (m.getParameterTypes().length == 0) {
                    defaultMethodName = m.getName();
                 	if (defaultMethodName.indexOf("get") == 0) { 
                 	   defaultMethodName =  defaultMethodName.substring(3,defaultMethodName.length());
                    }
                    char[] mname = defaultMethodName.toCharArray();
                    mname[0] = Character.toLowerCase(mname[0]);
                    defaultMethodName = new String(mname);
                 }
                 
                 if (defaultMethodName == null) { 
                 	sb.append("\n\t\t\t\t " + m.getName() + "(): ");
                 }
                 else { 
                     sb.append("\n\t\t\t\t " + m.toString() + "");
                     if (m.getAnnotations().length > 0) { 
                         sb.append(" method annotations: ");
                         for (Annotation a : m.getAnnotations()) {
                             sb.append(a.toString() + ", ");
                         }
                     }
                 }
             }
             sb.append("
"); out.println(sb); } } %> <% String beanName = request.getParameter("beanName"); String beanMethod = request.getParameter("methodName"); if (beanName != null) { if (beanMethod == null) { out.println("

No beanMethod parameter, using toString"); beanMethod = "toString"; } out.println("

" + beanName + "." + beanMethod + "() = [" + getBeanValue(beanName, beanMethod, pageContext) + "]"); } else { try { out.println("

usage

pass query string parameters beanName and methodName to call resolve a bean, or click the link of a getter below

"); dumpBeanManager(BeanManagerImpl.getManager(), out, request.getRequestURI()); } catch (Exception e) { e.printStackTrace(); } } %>