public int compare(Method a, Method b) { if (a == b) return 0; else if (a == null) return -1; else if (b == null) return 1; else if (a.equals(b)) return 0; int cmp = a.getName().compareTo(b.getName()); if (cmp != 0) return cmp; Class[] paramA = a.getParameterTypes(); Class[] paramB = b.getParameterTypes(); if (paramA.length < paramB.length) return -1; else if (paramB.length < paramA.length) return 1; for (int i = 0; i < paramA.length; i++) { cmp = paramA[i].getName().compareTo(paramB[i].getName()); if (cmp != 0) return cmp; } cmp = a.getDeclaringClass().getName().compareTo(b.getDeclaringClass().getName()); if (cmp != 0) return cmp; return a.getReturnType().getName().compareTo(b.getReturnType().getName()); }
/** Calculates a MD5 digest of the class. */ public String getDigest() { try { if (_className == null || "".equals(_className)) return ""; DynamicClassLoader loader = (DynamicClassLoader) Thread.currentThread().getContextClassLoader(); ClassLoader tmpLoader = loader.getNewTempClassLoader(); Class cl = Class.forName(_className, false, tmpLoader); if (cl == null) return ""; MessageDigest digest = MessageDigest.getInstance("MD5"); addDigest(digest, cl.getName()); addDigest(digest, cl.getModifiers()); Class superClass = cl.getSuperclass(); if (superClass != null) addDigest(digest, superClass.getName()); Class[] interfaces = cl.getInterfaces(); for (int i = 0; i < interfaces.length; i++) addDigest(digest, interfaces[i].getName()); Field[] fields = cl.getDeclaredFields(); Arrays.sort(fields, new FieldComparator()); if (_checkFields) { for (Field field : fields) { if (Modifier.isPrivate(field.getModifiers()) && !_checkPrivate) continue; if (Modifier.isProtected(field.getModifiers()) && !_checkProtected) continue; addDigest(digest, field.getName()); addDigest(digest, field.getModifiers()); addDigest(digest, field.getType().getName()); addDigest(digest, field.getAnnotations()); } } Method[] methods = cl.getDeclaredMethods(); Arrays.sort(methods, new MethodComparator()); for (int i = 0; i < methods.length; i++) { Method method = methods[i]; if (Modifier.isPrivate(method.getModifiers()) && !_checkPrivate) continue; if (Modifier.isProtected(method.getModifiers()) && !_checkProtected) continue; if (Modifier.isStatic(method.getModifiers()) && !_checkStatic) continue; addDigest(digest, method.getName()); addDigest(digest, method.getModifiers()); addDigest(digest, method.getName()); Class[] param = method.getParameterTypes(); for (int j = 0; j < param.length; j++) addDigest(digest, param[j].getName()); addDigest(digest, method.getReturnType().getName()); Class[] exn = method.getExceptionTypes(); for (int j = 0; j < exn.length; j++) addDigest(digest, exn[j].getName()); addDigest(digest, method.getAnnotations()); } byte[] digestBytes = new byte[256]; int len = digest.digest(digestBytes, 0, digestBytes.length); return digestToBase64(digestBytes, len); } catch (Exception e) { log.log(Level.FINER, e.toString(), e); return ""; } }
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>"); }