View Javadoc
1 package xdoclet.sdk.xgg; 2 3 import java.io.IOException; 4 import java.util.ArrayList; 5 import java.util.Collection; 6 import java.util.HashMap; 7 import java.util.Iterator; 8 import java.util.Map; 9 10 import xdoclet.XDoclet; 11 import xdoclet.XDocletException; 12 import xdoclet.MetadataProvider; 13 import xdoclet.plugins.VelocityPlugin; 14 import xdoclet.sdk.beans.BeanInfoPlugin; 15 import xdoclet.sdk.xgg.binding.Binder; 16 import xdoclet.sdk.xgg.binding.Element; 17 import xdoclet.xjavadoc.XJavadocMetadataProvider; 18 import xjavadoc.filesystem.FileSourceSet; 19 20 /*** 21 * Generates Java Bean classes from DTDs and XSDs. 22 * These beans can be serialised back and forth to XML 23 * with Betwixt. 24 * 25 * @bean.class 26 * name="xgg" 27 * displayName="xgg" 28 * shortDescription="XML Generator Generator." 29 * 30 * @bean.attribute 31 * name="xdoclet-class" 32 * value="xdoclet.XDoclet" 33 * 34 * @version $Revision: 1.9 $ 35 * @author <a href="mailto:aslak.hellesoy at bekk.no">Aslak Hellesøy</a> 36 */ 37 public class XGGPlugin extends VelocityPlugin { 38 private final Collection _binders = new ArrayList(); 39 private final Map _classModels = new HashMap(); 40 41 42 /***Constructor for the XGGPlugin object */ 43 public XGGPlugin() { 44 setTemplatePath("xdoclet/sdk/xgg/bean.vm"); 45 setFileName("{0}.java"); 46 } 47 48 49 /*** 50 * Description of the Method 51 * 52 * @return Description of the Return Value 53 */ 54 public Binder createBinder() { 55 Binder binder = new Binder(this); 56 _binders.add(binder); 57 return binder; 58 } 59 60 /*** 61 * Description of the Method 62 * 63 * @exception IOException Description of the Exception 64 * @exception XDocletException Description of the Exception 65 */ 66 public void execute() throws IOException, XDocletException { 67 super.execute(); 68 69 // Invoke the BeanInfo plugin on the generated beans. 70 // Betwixt will look for BeanInfo and use the name 71 // property as XML name. 72 // TODO remove this when the SDK is wrapped up. Should be handled 73 // from the outside. 74 XDoclet xdoclet = new XDoclet(); 75 xdoclet.setClasspath(getXDoclet().getClasspathManager().getClasspath()); 76 XJavadocMetadataProvider xJavadocMetadataProvider = (XJavadocMetadataProvider) xdoclet.createMetadataProvider("xjavadoc"); 77 xJavadocMetadataProvider.getXJavaDoc().addSourceSet(new FileSourceSet(getDestinationDir())); 78 BeanInfoPlugin beanInfoPlugin = (BeanInfoPlugin) xdoclet.createPlugin("beaninfo"); 79 beanInfoPlugin.setDestinationDir(getDestinationDir()); 80 beanInfoPlugin.setPackageName(getPackageName()); 81 xdoclet.execute(); 82 } 83 84 protected MetadataProvider getMetadataProvider() { 85 return new XGGMetadataProvider(); 86 } 87 88 private class XGGMetadataProvider implements MetadataProvider { 89 /*** 90 * Creates a Collection of {@link MergedClass}. 91 * 92 * @return Description of the Return Value 93 * @exception XDocletException Description of the Exception 94 */ 95 public Collection createMetadataCollection() throws XDocletException { 96 for (Iterator binders = _binders.iterator(); binders.hasNext(); ) { 97 Binder binder = (Binder) binders.next(); 98 for (Iterator elements = binder.getElements().iterator(); elements.hasNext(); ) { 99 Element element = (Element) elements.next(); 100 // Get (or create) a ClassModel for the current Class 101 MergedClass mergedClass = getMergedClass(element); 102 mergedClass.addElement(element); 103 } 104 } 105 return _classModels.values(); 106 } 107 108 /*** 109 * Gets the filenameSubstitutionValue attribute of the XGGPlugin object 110 * 111 * @param o Description of the Parameter 112 * @return The filenameSubstitutionValue value 113 */ 114 public String getFilenameSubstitutionValue(Object o) { 115 MergedClass mergedClass = (MergedClass) o; 116 return mergedClass.getJavaName(); 117 } 118 119 120 /*** 121 * Gets the mergedClass attribute of the XGGPlugin object 122 * 123 * @param element Description of the Parameter 124 * @return The mergedClass value 125 */ 126 public MergedClass getMergedClass(Element element) { 127 MergedClass classModel = (MergedClass) _classModels.get(element.getXmlName()); 128 if (classModel == null) { 129 classModel = new MergedClass(); 130 _classModels.put(element.getXmlName(), classModel); 131 } 132 return classModel; 133 } 134 135 136 /*** 137 * Gets the packageName attribute of the XGGPlugin object 138 * 139 * @param o Description of the Parameter 140 * @return The packageName value 141 */ 142 public String getPackageName(Object o) { 143 return XGGPlugin.this.getPackageName(); 144 } 145 146 public void setClasspath(String classpath) {} 147 public void cleanup() {} 148 } 149 }

This page was automatically generated by Maven