package com.javaworld.JavaBeans.XMLBeans; import org.w3c.dom.*; import java.lang.reflect.*; /** * Static utility functions to ease dealing with DOM classes. */ public class Util { /** * Util constructor comment. */ public Util() { super(); } /** * Capitalize the first letter of a word. * @param s java.lang.String */ public static String capitalize(String s) { char chars[] = s.toCharArray(); chars[0] = Character.toUpperCase(chars[0]); return new String(chars); } /** * Return the first "interesting" child node. An "interesting" node is * either a text node that contains something besides white space, or * anything else other than a comment. Return null if children are all * boring (that is, not interesting.) * @return org.w3c.dom.Node * @param node org.w3c.dom.Node */ public static Node getFirstInterestingChild(Node node) { NodeList nl = node.getChildNodes(); int i; for (i = 0; i < nl.getLength(); i++) { Node n = nl.item(i); // If it's a comment, skip if (n instanceof Comment) { continue; } // If it's Text, but contains only white space, skip if (n instanceof Text) { String text = ((Text) n).getData(); if (text.trim().equals("")) { continue; } } return n; } return null; } /** * Return the method with the given signature, or null if it doesn't * exist. This method simply catches and ignores NoSuchMethodException. * @return java.lang.reflect.Method * @param c java.lang.Class * @param name java.lang.String */ public static Method getMethodByName(Class c, String name, Class[] args) { Method mResult = null; try { mResult = c.getMethod(name, args); } catch (NoSuchMethodException ex) { ; // Ignore } return mResult; } }