On Wed, 2005-08-31 at 20:47, Marco Schulze wrote: > Update of /cvsroot/xdoclet/xdoclet/modules/jdo/src/xdoclet/modules/jdo > In directory > sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1239/modules/jdo/src/xdoclet/modules/jdo > > Modified Files: > JdoObjectIdGeneratorTagsHandler.java > Log Message: > added support of include-files (imports and body) in objectid-creation
Marco, Asides from the fact that the implementation needs changing so it still builds under JDK 1.4 (see XDT-1526), why couldn't this just use the existing merge handler? i.e. instead of using <XDtJdoObjectIdGenerator:includeImports/> and <XDtJdoObjectIdGenerator:includeBody/> with corresponding @jdo.create-objectid-class include-imports="somefile" include-body="someotherfile" tag parameters, why not use <XDtMerge:merge file="jso-objectid-imports-{0}.xdt"> <XDtMerge:merge file="jso-objectid-body-{0}.xdt"> instead to include them as per-class merge files? This has the advantage that the merge files can also include further <XDt...> tags for processing. Alternatively, if there is a good reason for handling the JDO include files this way, perhaps it should make use of xdoclet.util.FileManager like the merge handler does? That would also fix XDT-1526. Andrew. > > Index: JdoObjectIdGeneratorTagsHandler.java > =================================================================== > RCS file: > /cvsroot/xdoclet/xdoclet/modules/jdo/src/xdoclet/modules/jdo/JdoObjectIdGeneratorTagsHandler.java,v > retrieving revision 1.4 > retrieving revision 1.5 > diff -C2 -r1.4 -r1.5 > *** JdoObjectIdGeneratorTagsHandler.java 29 Aug 2005 22:55:05 -0000 > 1.4 > --- JdoObjectIdGeneratorTagsHandler.java 31 Aug 2005 19:47:00 -0000 > 1.5 > *************** > *** 5,18 **** > --- 5,26 ---- > package xdoclet.modules.jdo; > > + import java.io.File; > + import java.io.FileReader; > + import java.io.Reader; > + import java.nio.CharBuffer; > import java.util.ArrayList; > import java.util.Collections; > import java.util.Comparator; > + import java.util.HashMap; > import java.util.HashSet; > import java.util.Iterator; > import java.util.List; > + import java.util.Map; > import java.util.Properties; > import java.util.Set; > > import org.apache.commons.logging.Log; > + > + import xjavadoc.SourceClass; > import xjavadoc.XClass; > import xjavadoc.XDoc; > *************** > *** 54,57 **** > --- 62,71 ---- > private static Set primitiveClassNames = null; > > + /** > + * key: String qualifiedClassName<br/> > + * value: [EMAIL PROTECTED] SourceClass} sourceClass > + */ > + private Map sourceFileMap = null; > + > public static XField getCurrentPrimaryKeyField() > { > *************** > *** 294,301 **** > * @return > * @exception XDocletException > */ > public String code(Properties attributes) throws XDocletException > { > ! return > getCurrentClass().getDoc().getTagAttributeValue("jdo.create-objectid-class", > "code"); > } > > --- 308,366 ---- > * @return > * @exception XDocletException > + * @deprecated Use [EMAIL PROTECTED] > #includeBody(Properties)} instead! > */ > public String code(Properties attributes) throws XDocletException > { > ! String res = > getCurrentClass().getDoc().getTagAttributeValue("jdo.create-objectid-class", > "code"); > ! > ! if (res != null) { > ! LogUtil.getLog(JdoObjectIdGeneratorTagsHandler.class, > "code").warn("The attribute 'code' for the tag '@jdo.create-objectid-class' > is deprecated! Use 'include-body' (in combination with 'include-imports') > instead! Class: " + getCurrentClass().getQualifiedName()); > ! System.err.println("The attribute 'code' for the tag > '@jdo.create-objectid-class' is deprecated! Use 'include-body' (in > combination with 'include-imports') instead! Class: " + > getCurrentClass().getQualifiedName()); > ! } > ! return res; > ! } > ! > ! public String includeImports(Properties attributes) throws > XDocletException > ! { > ! String fileName = > getCurrentClass().getDoc().getTagAttributeValue("jdo.create-objectid-class", > "include-imports"); > ! > ! return includeFile(getCurrentClass(), fileName); > ! } > ! > ! public String includeBody(Properties attributes) throws XDocletException > ! { > ! String fileName = > getCurrentClass().getDoc().getTagAttributeValue("jdo.create-objectid-class", > "include-body"); > ! > ! return includeFile(getCurrentClass(), fileName); > ! } > ! > ! /** > ! * @param className The fully qualified name of the > class. > ! * @param throwExceptionIfNotFound > ! * @return Returns either <tt>null</tt> (if > <tt>throwExceptionIfNotFound == false</tt> and > ! * the class is not known) or the searched instance of SourceClass. > ! * @throws XDocletException If <tt>throwExceptionIfNotFound == > true</tt> and the specified <tt>className > ! * </tt> is unknown. > ! */ > ! protected SourceClass getSourceClass(String className, boolean > throwExceptionIfNotFound) > ! throws XDocletException > ! { > ! if (sourceFileMap == null) { > ! Map m = new HashMap(); > ! > ! for (Iterator it = getXJavaDoc().getSourceClasses().iterator(); > it.hasNext(); ) { > ! SourceClass sc = (SourceClass) it.next(); > ! > ! m.put(sc.getQualifiedName(), sc); > ! } > ! sourceFileMap = m; > ! } > ! > ! SourceClass sc = (SourceClass) sourceFileMap.get(className); > ! > ! if (throwExceptionIfNotFound && sc == null) > ! throw new XDocletException("The class \"" + className + "\" is > not known!"); > ! > ! return sc; > } > > *************** > *** 331,333 **** > --- 396,442 ---- > return objectIDClass; > } > + > + /** > + * @param clazz The class which is used as anchor if the > <tt>fileName</tt> is specified relatively. > + * @param fileName An absolute or more likely relative (to > clazz) fileName of the file to be included. > + * @return Returns the content of the specified file > or <tt>null</tt> if <tt>fileName</tt> is <tt> > + * null</tt> or an empty string. > + * @throws XDocletException In case, the specified file does not exist > or cannot be read. > + */ > + protected String includeFile(XClass clazz, String fileName) > + throws XDocletException > + { > + if (fileName == null || "".equals(fileName)) > + return null; > + > + SourceClass sourceClass = getSourceClass(clazz.getQualifiedName(), > true); > + String classFileName = sourceClass.getFile().getPath(); > + File classFile = new File(classFileName); > + File classDir = classFile.getParentFile(); > + File includeFile = new File(classDir, fileName); > + > + if (includeFile.length() > Integer.MAX_VALUE) > + throw new XDocletException("File \"" + > includeFile.getAbsolutePath() + "\" is too big!"); > + > + CharBuffer buf = CharBuffer.allocate((int) includeFile.length()); > + > + try { > + > + Reader r = new FileReader(includeFile); > + > + try { > + r.read(buf); > + } > + finally { > + r.close(); > + } > + > + } > + catch (Exception x) { > + throw new XDocletException(x, "Reading include file failed!"); > + } > + > + buf.flip(); > + return buf.toString(); > + } > } ------------------------------------------------------- SF.Net email is Sponsored by the Better Software Conference & EXPO September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf _______________________________________________ xdoclet-devel mailing list xdoclet-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/xdoclet-devel