User: rinkrank Date: 02/09/29 17:39:00 Modified: src/java/xgg Element.java ElementFactory.java Modifiable.java XggWriter.java Log: -DTDs are now converted to HTML, and there are cross-links between the bean interfaces' javadocs and the DTD. This should make the documentation of the XGG generated stuff quite good. -Generation of a factory class for each DTD, that will return the impl bean. -Impl beans are now package private. Let's try to keep them package private. Revision Changes Path 1.4 +31 -4 xgg/src/java/xgg/Element.java Index: Element.java =================================================================== RCS file: /cvsroot/xdoclet/xgg/src/java/xgg/Element.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -w -r1.3 -r1.4 --- Element.java 27 Sep 2002 13:20:23 -0000 1.3 +++ Element.java 30 Sep 2002 00:39:00 -0000 1.4 @@ -25,6 +25,8 @@ private boolean _isSequence = false; private boolean _isChoice = false; + private int _nextImplicitIndex = 0; + /** * All elements are marked as root by default. If the DTD has no * unreferenced elements (it should!), there will only be one element @@ -247,14 +249,21 @@ * @return a new Child that has us a s parent. */ public Child createChild() { - if( isImplicit() ) { -// System.out.println(getImplicitName() + " creating child"); - } - Child child = new Child( this, _elementFactory, _children.size() ); + int childIndex = -1; +// if( isImplicit() ) { + childIndex = getNextImplicitIndex(); +// } + Child child = new Child( this, _elementFactory, childIndex ); _children.add( child ); return child; } + private int getNextImplicitIndex() { + int result = _nextImplicitIndex; + _nextImplicitIndex++; + return result; + } + /** * Factory method for new attributes. * @@ -290,5 +299,23 @@ */ public boolean isRoot() { return _isRoot; + } + + private String _representation; + public void setRepresentation( String s ) { + _representation = s; + } + + public String getRepresentation() { + return _representation; + } + + private String _comment; + public void setComment( String s ) { + _comment = s; + } + + public String getComment() { + return _comment; } } 1.3 +17 -4 xgg/src/java/xgg/ElementFactory.java Index: ElementFactory.java =================================================================== RCS file: /cvsroot/xdoclet/xgg/src/java/xgg/ElementFactory.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -w -r1.2 -r1.3 --- ElementFactory.java 27 Sep 2002 13:20:23 -0000 1.2 +++ ElementFactory.java 30 Sep 2002 00:39:00 -0000 1.3 @@ -3,6 +3,8 @@ import java.util.Map; import java.util.HashMap; import java.util.Iterator; +import java.util.Collection; +import java.util.ArrayList; /** * Abstraction layer for a parser. Currently a DTD/JavaCC parser exists. @@ -13,23 +15,26 @@ */ public abstract class ElementFactory { // The global map that maps from name to element - private final Map _elements = new HashMap(); + private final Map _elementMap = new HashMap(); + + // Contains Elements in the order they occur in the source + private final Collection _declaredElements = new ArrayList(); /** * Returns an element corresponding to the name. If the * */ public Element getElement( String name ) { - Element element = (Element) _elements.get( name ); + Element element = (Element) _elementMap.get( name ); if( element == null ) { element = new Element( name, this ); - _elements.put( element.getName(), element ); + _elementMap.put( element.getName(), element ); } return element; } public Map getElementMap() { - return _elements; + return _elementMap; } public Element getRootElement() { @@ -52,5 +57,13 @@ ); } return root; + } + + public void addDeclaredElement(Element element) { + _declaredElements.add(element); + } + + public Collection getDeclaredElements() { + return _declaredElements; } } 1.2 +13 -12 xgg/src/java/xgg/Modifiable.java Index: Modifiable.java =================================================================== RCS file: /cvsroot/xdoclet/xgg/src/java/xgg/Modifiable.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -w -r1.1 -r1.2 --- Modifiable.java 24 Sep 2002 18:30:55 -0000 1.1 +++ Modifiable.java 30 Sep 2002 00:39:00 -0000 1.2 @@ -8,28 +8,29 @@ */ public class Modifiable { // modifiers - private boolean _isOptional = false; - private boolean _isMany = false; + public static final int PLUS = 1; + public static final int STAR = 2; + public static final int QUESTION = 3; + public static final int REQUIRED = 4; + + private int _modifier = REQUIRED; public boolean isOptional() { - return _isOptional; + return _modifier == QUESTION || _modifier == STAR; } public boolean isMany() { - return _isMany; + return _modifier == PLUS || _modifier == STAR; } - /** - * Called by parser if element is + or * - */ - public void setMany( boolean isMany ) { - _isMany = isMany; + public int getModifier() { + return _modifier; } /** - * Called by parser if element is ? + * Called by parser. */ - public void setOptional( boolean isOptional ) { - _isOptional = isOptional; + public void setModifier( int modifier ) { + _modifier = modifier; } } 1.4 +84 -44 xgg/src/java/xgg/XggWriter.java Index: XggWriter.java =================================================================== RCS file: /cvsroot/xdoclet/xgg/src/java/xgg/XggWriter.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -w -r1.3 -r1.4 --- XggWriter.java 27 Sep 2002 13:20:23 -0000 1.3 +++ XggWriter.java 30 Sep 2002 00:39:00 -0000 1.4 @@ -7,7 +7,8 @@ import org.apache.velocity.VelocityContext; /** - * This class writes xbeans and a velocity template. + * This class writes a velocity template, bean interfaces and + * optionally bean implementation skeletons. * * @author <a href="mailto:[EMAIL PROTECTED]">Aslak Hellesøy</a> */ @@ -16,47 +17,57 @@ public void write( ElementFactory elementFactory, URL dtd, - String pakkage, - File rootDir, String publicid, - String systemid + String systemid, + File destination, + String pakkage, + File implDestination, + boolean generateImpl, + File htmlDir ) throws Exception { - // This doesn't work because of Ant's jooli-wooli class loader mechanism - // (Ant's jar is always returned) - // URL codeSource = getClass().getProtectionDomain().getCodeSource().getLocation(); - // System.out.println( codeSource ); - - try { Velocity.init(System.getProperty("xgg.properties", "xgg.properties")); - } catch(Exception e) { - e.printStackTrace(); - throw new Exception( - "The first time xgg is built, uncomment the last 2 lines in xgg.properties" + template( + elementFactory, + publicid, + systemid, + destination, + pakkage, + htmlDir + ); + beans( + elementFactory, + dtd, + publicid, + systemid, + destination, + pakkage, + implDestination, + generateImpl ); - } - - template( elementFactory, pakkage, rootDir, publicid, systemid ); - beans( dtd, elementFactory, pakkage, rootDir, publicid, systemid ); } private void template( ElementFactory elementFactory, - String pakkage, - File rootDir, String publicid, - String systemid + String systemid, + File destination, + String pakkage, + File htmlDir ) throws Exception { /* lets make a Context and put data into it */ VelocityContext context = new VelocityContext(); context.put("root", elementFactory.getRootElement()); + context.put("packagePath", pakkage.replace('.','/')); context.put("publicid", publicid); context.put("systemid", systemid); + // required for HTML generation + context.put("elements", elementFactory.getDeclaredElements()); + context.put("htmlUtil", new xgg.html.HTMLUtil()); - /* lets render a template */ - - File dir = new File( rootDir, pakkage.replace( '.', File.separatorChar) ); + // XML Template + File dir = new File( destination, pakkage.replace( '.', File.separatorChar) ); dir = new File( dir, "resources" ); dir.mkdirs(); File xml = new File( dir, elementFactory.getRootElement().getName() + ".vm" ); @@ -65,15 +76,26 @@ Velocity.mergeTemplate("xgg/templates/xml.vm", "ISO-8859-1", context, w ); w.flush(); w.close(); + + // HTML docs + htmlDir.mkdirs(); + File html = new File( htmlDir, elementFactory.getRootElement().getName() + ".html" ); + FileWriter htmlW = new FileWriter( html ); + + Velocity.mergeTemplate("xgg/templates/html.vm", "ISO-8859-1", context, htmlW ); + htmlW.flush(); + htmlW.close(); } private void beans( - URL dtd, ElementFactory elementFactory, - String pakkage, - File rootDir, + URL dtd, String publicid, - String systemid + String systemid, + File destination, + String pakkage, + File implDestination, + boolean generateImpl ) throws Exception { @@ -81,41 +103,59 @@ VelocityContext context = new VelocityContext(); + context.put("root", elementFactory.getRootElement()); context.put("dtdURL", dtd); context.put("package", pakkage); context.put("publicid", publicid); context.put("systemid", systemid); + context.put("htmlUtil", new xgg.html.HTMLUtil()); /* lets render a template */ - File dir = new File( rootDir, pakkage.replace( '.', File.separatorChar) ); - dir.mkdirs(); + File interfaceDir = new File( destination, pakkage.replace( '.', File.separatorChar) ); + interfaceDir.mkdirs(); + + File implDir = null; + if( generateImpl ) { + // generate impl too + String implPackage = pakkage + ".impl"; + implDir = new File( implDestination, implPackage.replace( '.', File.separatorChar) ); + implDir.mkdirs(); + + // Generate factory class + File factory = new File( implDir, elementFactory.getRootElement().getJavaName() + "Factory.java" ); + FileWriter factoryW = new FileWriter( factory ); + + Velocity.mergeTemplate("xgg/templates/factory.vm", "ISO-8859-1", context, factoryW ); + factoryW.flush(); + factoryW.close(); + } + for( Iterator elements = elementFactory.getElementMap().values().iterator(); elements.hasNext(); ) { Element element = (Element) elements.next(); context.put("element", element); if( !element.isPcdata() ) { - bean(context, dir, element); + bean(context, element, interfaceDir, implDir); } } } - private void bean(VelocityContext context, File dir, Element element) throws Exception { + private void bean(VelocityContext context, Element element, File interfaceDir, File implDir ) throws Exception { - File intf = new File( dir, element.getJavaName() + ".java" ); + File intf = new File( interfaceDir, element.getJavaName() + ".java" ); FileWriter intfW = new FileWriter( intf ); Velocity.mergeTemplate("xgg/templates/bean.vm", "ISO-8859-1", context, intfW ); intfW.flush(); intfW.close(); -// This is only a helper to generate bean impl classes - File implDir = new File( dir, "impl"); - implDir.mkdirs(); + if( implDir != null ) { File impl = new File( implDir, element.getJavaName() + "Impl.java" ); FileWriter implW = new FileWriter( impl ); Velocity.mergeTemplate("xgg/templates/bean-impl.vm", "ISO-8859-1", context, implW ); implW.flush(); implW.close(); + } } }
------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf _______________________________________________ Xdoclet-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/xdoclet-devel