Update of /cvsroot/xdoclet/xdoclet/modules/jdo/src/xdoclet/modules/jdo In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32247/modules/jdo/src/xdoclet/modules/jdo
Modified Files: JdoXmlMetadataSubTask.java JdoTagsHandler.java Log Message: - removed the project's default-fetch-depth again (not necessary, because the fetch-depth applies only to a few special situations) - added the possibility to declare the fetch-depth (in square brackets) for each field within a fetch-group (e.g.: jdo.fetch-group name="myFetchGroup" field-names="name, parent[2], children[5]") Index: JdoXmlMetadataSubTask.java =================================================================== RCS file: /cvsroot/xdoclet/xdoclet/modules/jdo/src/xdoclet/modules/jdo/JdoXmlMetadataSubTask.java,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -r1.16 -r1.17 *** JdoXmlMetadataSubTask.java 17 Sep 2005 15:49:34 -0000 1.16 --- JdoXmlMetadataSubTask.java 18 Sep 2005 23:37:51 -0000 1.17 *************** *** 61,68 **** private String project = "metadata"; ! /** ! * @see #setFetchDepth(int) ! */ ! private int fetchDepth = -1; /** --- 61,68 ---- private String project = "metadata"; ! // /** ! // * @see #setFetchDepth(int) ! // */ ! // private int fetchDepth = -1; /** *************** *** 84,94 **** } ! /** ! * @return Returns the fetch-depth as set by [EMAIL PROTECTED] #setFetchDepth(int)} or -1 if nothing was set. ! */ ! public int getFetchDepth() ! { ! return fetchDepth; ! } public void setProject(String project) --- 84,94 ---- } ! // /** ! // * @return Returns the fetch-depth as set by [EMAIL PROTECTED] #setFetchDepth(int)} or -1 if nothing was set. ! // */ ! // public int getFetchDepth() ! // { ! // return fetchDepth; ! // } public void setProject(String project) *************** *** 102,122 **** } ! /** ! * The JDO spec defines that a fetch-depth of 1 shall be used if a field has no fetch-depth declared. In case you ! * don't like this default, you must tag every field with a different fetch-depth. This is an annoying work if you ! * want to have the same for the majority of your fields. Hence, you have the possibility to declare the <code>fetchDepth</code> ! * attribute for the <code>jdometadata</code> subtask. This will cause every field to be tagged with this default, ! * if the field doesn't have a fetch-depth declared. If the field has a fetch-depth, this one is used. ! * ! * @param fetchDepth Either -1 to indicate that no default-fetch-depth should be set, or 0 for infinite depth, or a ! * positive number indicating how many levels the detaching shall dive into the object-graph. ! */ ! public void setFetchDepth(int fetchDepth) ! { ! if (fetchDepth < -1) ! throw new IllegalArgumentException("fetchDepth=" + fetchDepth + " is illegal! Must be -1 to deactivate the default-fetch-depth or a number >= 0!"); ! ! this.fetchDepth = fetchDepth; ! } /** --- 102,122 ---- } ! // /** ! // * The JDO spec defines that a fetch-depth of 1 shall be used if a field has no fetch-depth declared. In case you ! // * don't like this default, you must tag every field with a different fetch-depth. This is an annoying work if you ! // * want to have the same for the majority of your fields. Hence, you have the possibility to declare the <code>fetchDepth</code> ! // * attribute for the <code>jdometadata</code> subtask. This will cause every field to be tagged with this default, ! // * if the field doesn't have a fetch-depth declared. If the field has a fetch-depth, this one is used. ! // * ! // * @param fetchDepth Either -1 to indicate that no default-fetch-depth should be set, or 0 for infinite depth, or a ! // * positive number indicating how many levels the detaching shall dive into the object-graph. ! // */ ! // public void setFetchDepth(int fetchDepth) ! // { ! // if (fetchDepth < -1) ! // throw new IllegalArgumentException("fetchDepth=" + fetchDepth + " is illegal! Must be -1 to deactivate the default-fetch-depth or a number >= 0!"); ! // ! // this.fetchDepth = fetchDepth; ! // } /** Index: JdoTagsHandler.java =================================================================== RCS file: /cvsroot/xdoclet/xdoclet/modules/jdo/src/xdoclet/modules/jdo/JdoTagsHandler.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -r1.12 -r1.13 *** JdoTagsHandler.java 17 Sep 2005 22:44:43 -0000 1.12 --- JdoTagsHandler.java 18 Sep 2005 23:37:51 -0000 1.13 *************** *** 7,18 **** import java.util.ArrayList; import java.util.Collection; - import java.util.HashSet; import java.util.Iterator; import java.util.Properties; - import java.util.Set; import xjavadoc.XClass; import xjavadoc.XDoc; import xjavadoc.XPackage; - import xjavadoc.XTag; import xdoclet.SubTask; --- 7,15 ---- *************** *** 33,48 **** private VendorExtension _currentExtension; ! /** ! * @see #cacheFieldsInFetchGroups ! */ ! private XClass cacheFieldsInFetchGroupsClass = null; ! /** ! * This Set stores all fields that are declared in the current class (cached in [EMAIL PROTECTED] ! * #cacheFieldsInFetchGroupsClass}) to be included in a fetch-group. If a field is in no fetch-group, it is not ! * contained in this Set. This Set is null if [EMAIL PROTECTED] #ifCurrentFieldIsInFetchGroup(String, Properties)} has not yet ! * been called. If [EMAIL PROTECTED] #cacheFieldsInFetchGroupsClass} specifies a class that is different from [EMAIL PROTECTED] ! * XDocletTagSupport#getCurrentClass()} then this Set needs to be recreated. ! */ ! private Set cacheFieldsInFetchGroups = null; /** --- 30,48 ---- private VendorExtension _currentExtension; ! // /** ! // * @see #cacheFieldsInFetchGroups ! // */ ! // private XClass cacheFieldsInFetchGroupsClass = null; ! // /** ! // * This Set stores all fields that are declared in the current class (cached in [EMAIL PROTECTED] ! // * #cacheFieldsInFetchGroupsClass}) to be included in a fetch-group. If a field is in no fetch-group, it is not ! // * contained in this Set. This Set is null if [EMAIL PROTECTED] #ifCurrentFieldIsInFetchGroup(String, Properties)} has not yet ! // * been called. If [EMAIL PROTECTED] #cacheFieldsInFetchGroupsClass} specifies a class that is different from [EMAIL PROTECTED] ! // * XDocletTagSupport#getCurrentClass()} then this Set needs to be recreated. ! // */ ! // private Set cacheFieldsInFetchGroups = null; ! ! private String currentFetchGroupFieldName = null; ! private int currentFetchGroupFieldFetchDepth = -1; /** *************** *** 195,231 **** } ! public void ifCurrentFieldIsInFetchGroup(String template, Properties attributes) throws XDocletException { ! if (cacheFieldsInFetchGroupsClass != getCurrentClass()) ! cacheFieldsInFetchGroupsClass = null; ! if (cacheFieldsInFetchGroupsClass == null || cacheFieldsInFetchGroups == null) { ! if (cacheFieldsInFetchGroups == null) ! cacheFieldsInFetchGroups = new HashSet(); ! else ! cacheFieldsInFetchGroups.clear(); ! for (Iterator it = getCurrentClass().getDoc().getTags("jdo.fetch-group").iterator(); it.hasNext(); ) { ! XTag fgt = (XTag) it.next(); ! String fieldStr = fgt.getAttributeValue("field-names"); ! if (fieldStr != null) { ! String[] fieldNames = fieldStr.split(","); ! for (int i = 0; i < fieldNames.length; ++i) { ! String fieldName = fieldNames[i].replaceAll(" ", ""); ! if (!cacheFieldsInFetchGroups.contains(fieldName)) ! cacheFieldsInFetchGroups.add(fieldName); ! } } } ! cacheFieldsInFetchGroupsClass = getCurrentClass(); ! } ! if (cacheFieldsInFetchGroups.contains(getCurrentField().getName())) generate(template); } protected void setCurrentVendorExtension(VendorExtension vendorExtension) { --- 195,318 ---- } ! public String currentFetchGroupFieldName() { ! if (currentFetchGroupFieldName == null) ! throw new IllegalStateException("You cannot access the currentFetchGroupFieldName outside of the forAllFetchGroupFieldNames loop!"); ! return currentFetchGroupFieldName; ! } ! ! public String currentFetchGroupFieldFetchDepth() ! { ! if (currentFetchGroupFieldName == null) ! throw new IllegalStateException("You cannot access the currentFetchGroupFieldFetchDepth outside of the forAllFetchGroupFieldNames loop!"); ! return Integer.toString(currentFetchGroupFieldFetchDepth); ! } ! public void ifCurrentFetchGroupFieldHasFetchDepth(String template, Properties attributes) throws XDocletException ! { ! if (currentFetchGroupFieldName == null) ! throw new IllegalStateException("You cannot use ifCurrentFetchGroupFieldHasFetchDepth outside of the forAllFetchGroupFieldNames loop!"); ! if (currentFetchGroupFieldFetchDepth >= 0) ! generate(template); ! } ! /** ! * This is used to iterate the comma-separated list of fields within a fetch-group (there must be a current ! * fetch-group!). Each field may optionally be followed by "[fetch-depth]". <p> ! * ! * Example: <pre> ! * jdo.fetch-group name="myFetchGroup" field-names="field0, field1 [3], field2" ! * </pre> </p> ! * ! * @param template ! * @param attributes ! * @throws XDocletException ! */ ! public void forAllFetchGroupFieldNames(String template, Properties attributes) throws XDocletException ! { ! if (!"jdo.fetch-group".equals(getCurrentClassTag().getName())) ! throw new IllegalStateException("currentClassTag.name=\"" + getCurrentClassTag().getName() + "\" but must be \"jdo.fetch-group\"!"); ! ! String fieldNamesString = getCurrentClassTag().getAttributeValue("field-names"); ! ! if (fieldNamesString == null) { ! // there is no field-names attribute ! return; ! } ! ! String[] fieldNames = fieldNamesString.replaceAll(" ", "").split(","); ! ! for (int i = 0; i < fieldNames.length; ++i) { ! String fieldNameRaw = fieldNames[i]; ! ! // split fieldNameRaw into fieldName + fetch-depth ! String[] parts = fieldNameRaw.split("\\["); ! String fieldName = parts[0]; ! int fetchDepth; ! ! if (parts.length == 1) { ! // there is no fetch-depth ! fetchDepth = -1; ! } ! else if (parts.length == 2) { ! String fetchDepthStr = parts[1]; ! ! if (!fetchDepthStr.endsWith("]")) ! throw new XDocletException("Attribute field-names of fetch-group \"" + getCurrentClassTag().getAttributeValue("name") + "\" is not formatted correctly! One of the fields has an open [ and misses the closing ]!"); ! ! try { ! fetchDepth = Integer.parseInt(fetchDepthStr.substring(0, fetchDepthStr.length() - 1)); ! } ! catch (NumberFormatException x) { ! throw new XDocletException("Attribute field-names of fetch-group \"" + getCurrentClassTag().getAttributeValue("name") + "\" is not formatted correctly! The text between [ and ] is not a number >= 0!"); } } ! else ! throw new XDocletException("Attribute field-names of fetch-group \"" + getCurrentClassTag().getAttributeValue("name") + "\" is not formatted correctly! One of the fields has multiple occurences of [!"); ! currentFetchGroupFieldName = fieldName; ! currentFetchGroupFieldFetchDepth = fetchDepth; generate(template); + } + currentFetchGroupFieldName = null; + currentFetchGroupFieldFetchDepth = -1; } + // public void ifCurrentFieldIsInFetchGroup(String template, Properties attributes) throws XDocletException + // { + // if (cacheFieldsInFetchGroupsClass != getCurrentClass()) + // cacheFieldsInFetchGroupsClass = null; + // + // if (cacheFieldsInFetchGroupsClass == null || cacheFieldsInFetchGroups == null) { + // if (cacheFieldsInFetchGroups == null) + // cacheFieldsInFetchGroups = new HashSet(); + // else + // cacheFieldsInFetchGroups.clear(); + // + // for (Iterator it = getCurrentClass().getDoc().getTags("jdo.fetch-group").iterator(); it.hasNext(); ) { + // XTag fgt = (XTag) it.next(); + // String fieldStr = fgt.getAttributeValue("field-names"); + // + // if (fieldStr != null) { + // String[] fieldNames = fieldStr.split(","); + // + // for (int i = 0; i < fieldNames.length; ++i) { + // String fieldName = fieldNames[i].replaceAll(" ", ""); + // + // if (!cacheFieldsInFetchGroups.contains(fieldName)) + // cacheFieldsInFetchGroups.add(fieldName); + // } + // } + // } + // cacheFieldsInFetchGroupsClass = getCurrentClass(); + // } + // + // if (cacheFieldsInFetchGroups.contains(getCurrentField().getName())) + // generate(template); + // } + protected void setCurrentVendorExtension(VendorExtension vendorExtension) { ------------------------------------------------------- SF.Net email is sponsored by: Tame your development challenges with Apache's Geronimo App Server. Download it for free - -and be entered to win a 42" plasma tv or your very own Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php _______________________________________________ xdoclet-devel mailing list xdoclet-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/xdoclet-devel