/** Verify and invoke main if present in the specified class. */ public static void invokeApplicationMain(Class mainClass, String[] args) throws InvocationTargetException, IllegalAccessException, ClassNotFoundException { String err = localStrings.getLocalString("utility.no.main", "", new Object[] {mainClass}); // determine the main method using reflection // verify that it is public static void and takes // String[] as the only argument Method mainMethod = null; try { mainMethod = mainClass.getMethod("main", new Class[] {String[].class}); } catch (NoSuchMethodException msme) { _logger.log(Level.SEVERE, "enterprise_util.excep_in_utility", msme); throw new ClassNotFoundException(err); } // check modifiers: public static int modifiers = mainMethod.getModifiers(); if (!Modifier.isPublic(modifiers) || !Modifier.isStatic(modifiers)) { err = localStrings.getLocalString( "utility.main.notpublicorstatic", "The main method is either not public or not static"); _logger.log(Level.SEVERE, "enterprise_util.excep_in_utility_main.notpublicorstatic"); throw new ClassNotFoundException(err); } // check return type and exceptions if (!mainMethod.getReturnType().equals(Void.TYPE)) { err = localStrings.getLocalString( "utility.main.notvoid", "The main method's return type is not void "); _logger.log(Level.SEVERE, "enterprise_util.excep_in_utility_main.notvoid"); throw new ClassNotFoundException(err); } // build args to the main and call it Object params[] = new Object[1]; params[0] = args; mainMethod.invoke(null, params); }
private void printComponentTree( PrintWriter out, String errorId, FacesContext context, UIComponent comp, int depth) { for (int i = 0; i < depth; i++) out.print(' '); boolean isError = false; if (errorId != null && errorId.equals(comp.getClientId(context))) { isError = true; out.print("<span style='color:red'>"); } out.print("<" + comp.getClass().getSimpleName()); if (comp.getId() != null) out.print(" id=\"" + comp.getId() + "\""); for (Method method : comp.getClass().getMethods()) { if (!method.getName().startsWith("get") && !method.getName().startsWith("is")) continue; else if (method.getParameterTypes().length != 0) continue; String name; if (method.getName().startsWith("get")) name = method.getName().substring(3); else if (method.getName().startsWith("is")) name = method.getName().substring(2); else continue; // XXX: getURL name = Character.toLowerCase(name.charAt(0)) + name.substring(1); ValueExpression expr = comp.getValueExpression(name); Class type = method.getReturnType(); if (expr != null) { out.print(" " + name + "=\"" + expr.getExpressionString() + "\""); } else if (method.getDeclaringClass().equals(UIComponent.class) || method.getDeclaringClass().equals(UIComponentBase.class)) { } else if (name.equals("family")) { } else if (String.class.equals(type)) { try { Object value = method.invoke(comp); if (value != null) out.print(" " + name + "=\"" + value + "\""); } catch (Exception e) { } } } int facetCount = comp.getFacetCount(); int childCount = comp.getChildCount(); if (facetCount == 0 && childCount == 0) { out.print("/>"); if (isError) out.print("</span>"); out.println(); return; } out.println(">"); if (isError) out.print("</span>"); for (int i = 0; i < childCount; i++) { printComponentTree(out, errorId, context, comp.getChildren().get(i), depth + 1); } for (int i = 0; i < depth; i++) out.print(' '); if (isError) out.print("<span style='color:red'>"); out.println("</" + comp.getClass().getSimpleName() + ">"); if (isError) out.print("</span>"); }