Author: tchemit Date: 2008-10-19 20:15:06 +0000 (Sun, 19 Oct 2008) New Revision: 978 Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/PrintTagInfo.java Log: begin of refactor of this tools to make it works with rst... to be finished Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/PrintTagInfo.java =================================================================== --- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/PrintTagInfo.java 2008-10-19 19:44:06 UTC (rev 977) +++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/PrintTagInfo.java 2008-10-19 20:15:06 UTC (rev 978) @@ -8,6 +8,11 @@ import jaxx.tags.DefaultObjectHandler; import jaxx.tags.TagManager; +import java.io.BufferedWriter; +import java.io.FileWriter; +import java.io.IOException; +import java.io.OutputStreamWriter; + /** Generates information about a tag for use on the jaxxframework.org web site. */ public class PrintTagInfo { /** @@ -17,20 +22,48 @@ * @throws Exception if an error occurs */ public static void main(String[] arg) throws Exception { - JAXXCompiler.init(); + if (arg.length < 1) { + throw new IllegalArgumentException("programm needs at least two parameters : the file where to put the result, and at least one fqn class to treate"); + } + String firstarg = arg[0]; + boolean toFile = false; + BufferedWriter w; + if (firstarg.startsWith("file:")) { + w = new BufferedWriter(new FileWriter(firstarg.substring(5))); + toFile = true; + } else { + w = new BufferedWriter(new OutputStreamWriter(System.out)); + } - ClassDescriptor beanClass = ClassDescriptorLoader.getClassDescriptor(arg[0]); + try { + JAXXCompiler.loadLibraries(false); + for (int i = toFile ? 1 : 0; i < arg.length; i++) { + String className = arg[i]; + treateClass(w, className); + } + } finally { + w.flush(); + w.close(); + } + + } + + protected static void treateClass(BufferedWriter w, String className) throws ClassNotFoundException, IOException { + + ClassDescriptor beanClass = ClassDescriptorLoader.getClassDescriptor(className); DefaultObjectHandler handler = TagManager.getTagHandler(beanClass); DefaultObjectHandler superHandler = TagManager.getTagHandler(beanClass.getSuperclass()); // dump all bean properties - System.out.println("Properties in " + beanClass); + w.append("Properties in ").append(String.valueOf(beanClass)); + w.newLine(); JAXXPropertyDescriptor[] properties = handler.getJAXXBeanInfo().getJAXXPropertyDescriptors(); JAXXPropertyDescriptor[] superProperties = superHandler.getJAXXBeanInfo().getJAXXPropertyDescriptors(); for (JAXXPropertyDescriptor property : properties) { - if (property.getWriteMethodDescriptor() == null) + if (property.getWriteMethodDescriptor() == null) { continue; + } boolean found = false; String name = property.getName(); @@ -41,29 +74,42 @@ } } if (!found) { - if (property.getPropertyType() == null) + if (property.getPropertyType() == null) { System.err.println(name + " has null type"); - else { - System.out.println("{{EquivalentAttribute|" + name + "|" + arg[0].replace('.', '/') + - "|set" + JAXXCompiler.capitalize(name) + "|" + - JAXXCompiler.getCanonicalName(property.getPropertyType()) + "}}"); - System.out.println("|-"); + } else { + w.append("{{EquivalentAttribute|"); + w.append(name); + w.append("|"); + w.append(className.replace('.', '/')); + w.append("|set"); + w.append(JAXXCompiler.capitalize(name)); + w.append("|"); + w.append(JAXXCompiler.getCanonicalName(property.getPropertyType())); + w.append("}}"); + w.append("|-"); + w.newLine(); } } } - System.out.println(); - System.out.println(); + w.newLine(); + w.newLine(); // dump all bound methods + dumpMethods(w, beanClass, handler); + } + + protected static void dumpMethods(BufferedWriter w, ClassDescriptor beanClass, DefaultObjectHandler handler) throws IOException { MethodDescriptor[] methods = beanClass.getMethodDescriptors(); - System.out.println("Bound methods in " + beanClass); + w.append("Bound methods in ").append(String.valueOf(beanClass)); + w.newLine(); for (MethodDescriptor method : methods) { try { - if (handler.isMemberBound(method.getName())) - System.out.println("* <tt>" + method.getName() + "()</tt>"); - } - catch (Throwable e) { + if (handler.isMemberBound(method.getName())) { + w.append("* <tt>").append(method.getName()).append("()</tt>"); + w.newLine(); + } + } catch (Throwable e) { // ignore ? } }
participants (1)
-
tchemit@users.labs.libre-entreprise.org