User: ko5tik  
  Date: 02/04/18 04:42:41

  Modified:    src/java/xtags ConditionFactory.java OptionSet.java Tag.java
                        TagParameter.java
  Log:
  implemented  default parameter values
  
  Revision  Changes    Path
  1.9       +83 -49    xdocletgui/src/java/xtags/ConditionFactory.java
  
  Index: ConditionFactory.java
  ===================================================================
  RCS file: /cvsroot/xdoclet/xdocletgui/src/java/xtags/ConditionFactory.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -w -r1.8 -r1.9
  --- ConditionFactory.java     17 Apr 2002 15:10:27 -0000      1.8
  +++ ConditionFactory.java     18 Apr 2002 11:42:40 -0000      1.9
  @@ -56,7 +56,7 @@
    */
   public class ConditionFactory {
        /**
  -      * @todo-javadoc Describe the field
  +      * parsed xml document
         */
        private Document _document;
   
  @@ -66,7 +66,7 @@
        private static org.apache.log4j.Category _log = 
org.apache.log4j.Category.getInstance(ConditionFactory.class.getName());
   
        /**
  -      * @todo-javadoc Describe the field
  +      * binding between contidion type and implementing class
         */
        private static Properties _conditionTypes = new Properties();
   
  @@ -150,31 +150,43 @@
                                                List parameterElements = 
tagElement.getChildren("parameter");
                                                for (Iterator parameterIterator = 
parameterElements.iterator(); parameterIterator.hasNext(); ) {
                                                        Element parameterElement = 
(Element)parameterIterator.next();
  +                                                     TagParameter tagParameter = 
parseTagParameter(parameterElement);
  +                                                     
tag.addTagParameter(tagParameter);
  +                                             }
  +                                     }
  +                             }
  +                     }
   
  -                                                     // We need a parent
  -                                                     Condition condition = 
iterateCondition(parameterElement, null);
  -
  -                                                     // Add a new tag parameter to 
the tag
  -                                                     String tagParameterName = 
parameterElement.getChild("name").getTextTrim();
  -                                                     String tagParameterUsage = 
parameterElement.getChild("usage-description").getTextNormalize();
  -                                                     String tagParameterType = 
parameterElement.getAttributeValue("type");
  -                                                     boolean mandatory = false;
  -                                                     Element 
tagParameterMandatoryElement = parameterElement.getChild("mandatory");
  -                                                     if 
(tagParameterMandatoryElement != null) {
  -                                                             mandatory = 
"true".equals(tagParameterMandatoryElement.getTextTrim());
  +                     return tagFamilies;
  +             } catch (Exception e) {
  +                     e.printStackTrace();
  +                     throw new ConditionException(e.getMessage());
  +             }
                                                        }
  -                                                     TagParameter tagParameter = 
tag.addTagParameter(tagParameterName,
  -                                                                     
tagParameterUsage,
  -                                                                     
tagParameterType,
  -                                                                     mandatory,
  -                                                                     condition);
   
  +
  +     /**
  +      * Describe what the method does
  +      *
  +      * @param tagParameter Describe what the parameter does
  +      * @param parameterElement Describe what the parameter does
  +      * @exception Exception Describe the exception
  +      * @todo-javadoc Write javadocs for method
  +      * @todo-javadoc Write javadocs for method parameter
  +      * @todo-javadoc Write javadocs for method parameter
  +      * @todo-javadoc Write javadocs for exception
  +      */
  +     void iterateOptions(TagParameter tagParameter, Element parameterElement) 
throws Exception {
                                                        // find the valid options for 
this condition
                                                        Element optionSetsElement = 
parameterElement.getChild("option-sets");
                                                        if (optionSetsElement != null) 
{
                                                                List 
optionsSetElements = optionSetsElement.getChildren("option-set");
                                                                for (Iterator 
optionSetIterator = optionsSetElements.iterator(); optionSetIterator.hasNext(); ) {
                                                                        Element 
optionSetElement = (Element)optionSetIterator.next();
  +                             String def = "";
  +                             if (optionSetElement.getChild("default") != null) {
  +                                     def = 
optionSetElement.getChild("default").getTextTrim();
  +                             }
                                                                        // find the 
options
                                                                        Element 
optionsElement = optionSetElement.getChild("options");
                                                                        String[] 
options = null;
  @@ -188,35 +200,57 @@
                                                                        }
                                                                        Condition 
optionCondition = iterateCondition(optionSetElement, null);
   
  -                                                                     
tagParameter.addOptionSet(new OptionSet(options, optionCondition));
  -                                                             }
  -                                                     }
  -                                             }
  -                                     }
  +                             tagParameter.addOptionSet(new OptionSet(options, 
optionCondition, def));
                                }
                        }
  -
  -                     return tagFamilies;
  -             } catch (Exception e) {
  -                     e.printStackTrace();
  -                     throw new ConditionException(e.getMessage());
  -             }
        }
   
   
        /**
  -      * Recursively builds a condition
  +      * parse tag parameter node and create new tag parameter
         *
  -      * @param parentCondition Describe what the parameter does
  -      * @param conditionElementParent Describe what the parameter does
  +      * @param tagParameterElement Describe what the parameter does
         * @return Describe the return value
         * @exception Exception Describe the exception
  -      * @todo-javadoc Write javadocs for return value
         * @todo-javadoc Write javadocs for method parameter
         * @todo-javadoc Write javadocs for return value
         * @todo-javadoc Write javadocs for exception
  -      * @todo-javadoc Write javadocs for method parameter
  -      * @todo-javadoc Write javadocs for method parameter
  +      */
  +     private TagParameter parseTagParameter(Element tagParameterElement) throws 
Exception {
  +             Condition condition = iterateCondition(tagParameterElement, null);
  +             String name = tagParameterElement.getChild("name").getTextTrim();
  +             String usage = 
tagParameterElement.getChild("usage-description").getTextNormalize();
  +             String type = tagParameterElement.getAttributeValue("type");
  +             boolean mandatory = false;
  +             Element tagParameterMandatoryElement = 
tagParameterElement.getChild("mandatory");
  +             if (tagParameterMandatoryElement != null) {
  +                     mandatory = 
"true".equals(tagParameterMandatoryElement.getTextTrim());
  +             }
  +
  +             String def = "";
  +             Element tagParameterDefaultElement = 
tagParameterElement.getChild("default");
  +             if (tagParameterDefaultElement != null) {
  +                     def = tagParameterDefaultElement.getTextTrim();
  +             }
  +
  +             Condition c = iterateCondition(tagParameterElement, null);
  +
  +             TagParameter tp = new TagParameter(name, usage, type, def, mandatory, 
condition);
  +
  +             iterateOptions(tp, tagParameterElement);
  +
  +             return tp;
  +     }
  +
  +
  +     /**
  +      * Recursively builds a condition. If there is none, return And() which always
  +      * evaluates to true
  +      *
  +      * @param parentCondition condition to weawe result into
  +      * @param conditionElementParent parent element
  +      * @return ready condition tree
  +      * @exception Exception Describe the exception
         */
        private Condition iterateCondition(Element conditionElementParent, Condition 
parentCondition) throws Exception {
                Condition result = null;
  
  
  
  1.3       +32 -4     xdocletgui/src/java/xtags/OptionSet.java
  
  Index: OptionSet.java
  ===================================================================
  RCS file: /cvsroot/xdoclet/xdocletgui/src/java/xtags/OptionSet.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -w -r1.2 -r1.3
  --- OptionSet.java    22 Feb 2002 18:28:09 -0000      1.2
  +++ OptionSet.java    18 Apr 2002 11:42:40 -0000      1.3
  @@ -47,13 +47,18 @@
    */
   class OptionSet {
        /**
  -      * @todo-javadoc Describe the field
  +      * applicabolity condition
         */
        private final Condition _condition;
        /**
  -      * @todo-javadoc Describe the field
  +      * configured opttions
         */
  -     private String[] _options;
  +     private final String[] _options;
  +
  +     /**
  +      * default value if any
  +      */
  +     private final String _default;
   
   
        /**
  @@ -61,13 +66,16 @@
         *
         * @param options Describe what the parameter does
         * @param condition Describe what the parameter does
  +      * @param def Describe what the parameter does
  +      * @todo-javadoc Write javadocs for method parameter
         * @todo-javadoc Write javadocs for constructor
         * @todo-javadoc Write javadocs for method parameter
         * @todo-javadoc Write javadocs for method parameter
         */
  -     public OptionSet(String[] options, Condition condition) {
  +     public OptionSet(String[] options, Condition condition, String def) {
                _options = options;
                _condition = condition;
  +             _default = def;
        }
   
   
  @@ -78,6 +86,26 @@
         */
        public String[] getOptions() {
                return _options;
  +     }
  +
  +
  +     /**
  +      * return default value if configured or first option
  +      *
  +      * @return The Default value
  +      */
  +     public String getDefault() {
  +             if (_default != null) {
  +                     return _default;
  +             }
  +             else {
  +                     if (_options.length > 0) {
  +                             return _options[0];
  +                     }
  +                     else {
  +                             return "";
  +                     }
  +             }
        }
   
   
  
  
  
  1.8       +3 -20     xdocletgui/src/java/xtags/Tag.java
  
  Index: Tag.java
  ===================================================================
  RCS file: /cvsroot/xdoclet/xdocletgui/src/java/xtags/Tag.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -w -r1.7 -r1.8
  --- Tag.java  17 Apr 2002 15:10:27 -0000      1.7
  +++ Tag.java  18 Apr 2002 11:42:40 -0000      1.8
  @@ -264,12 +264,8 @@
        /**
         * Only allowed to be called by ConditionFactory
         *
  -      * @param tagParameterName Describe the method parameter
  -      * @param tagParameterUsage Describe the method parameter
  -      * @param tagParameterType Describe the method parameter
  -      * @param mandatory Describe the method parameter
  -      * @param condition Describe the method parameter
  -      * @return Describe the return value
  +      * @param tagParameter Describe the method parameter
  +      * @todo-javadoc Describe the method parameter
         * @todo-javadoc Write javadocs for return value
         * @todo-javadoc Describe the method parameter
         * @todo-javadoc Describe the method parameter
  @@ -278,21 +274,8 @@
         * @todo-javadoc Describe the method parameter
         * @todo-javadoc Describe the method parameter
         */
  -     TagParameter addTagParameter(String tagParameterName,
  -                     String tagParameterUsage,
  -                     String tagParameterType,
  -                     boolean mandatory,
  -                     Condition condition) {
  -             TagParameter tagParameter = new TagParameter(
  -                             tagParameterName,
  -                             tagParameterUsage,
  -                             tagParameterType,
  -                             mandatory,
  -                             condition
  -                             );
  +     void addTagParameter(TagParameter tagParameter) {
                _tagParameters.add(tagParameter);
  -             //_or.addCondition(condition);
                _parameterMap.put(tagParameter.getName(), tagParameter);
  -             return tagParameter;
        }
   }
  
  
  
  1.7       +26 -1     xdocletgui/src/java/xtags/TagParameter.java
  
  Index: TagParameter.java
  ===================================================================
  RCS file: /cvsroot/xdoclet/xdocletgui/src/java/xtags/TagParameter.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -w -r1.6 -r1.7
  --- TagParameter.java 17 Apr 2002 15:10:27 -0000      1.6
  +++ TagParameter.java 18 Apr 2002 11:42:40 -0000      1.7
  @@ -59,7 +59,6 @@
    * @author Aslak Helles�y
    * @created 20. desember 2001
    * @todo implement DocumentedSupporter.supports( Documented )
  - * @todo do something to provide default value for parameter upon creation
    */
   public class TagParameter {
   
  @@ -79,6 +78,10 @@
        private final boolean _mandatory;
   
        /**
  +      * default value for this tag. if any
  +      */
  +     private final String _default;
  +     /**
         * The class of the objects that can be used to set values. Typically
         * java.lang.Integer, java.lang.Boolean or java.lang.String. Can be used to
         * create a proper gui editor.
  @@ -121,6 +124,8 @@
         * @param mandatory whether or not we're mandatory
         * @param type Describe what the parameter does
         * @param condition Describe what the parameter does
  +      * @param def Describe what the parameter does
  +      * @todo-javadoc Write javadocs for method parameter
         * @todo-javadoc Write javadocs for method parameter
         * @todo-javadoc Write javadocs for method parameter
         * @todo-javadoc Write javadocs for method parameter
  @@ -129,6 +134,7 @@
                        String name,
                        String usage,
                        String type,
  +                     String def,
                        boolean mandatory,
                        Condition condition
                        ) {
  @@ -139,6 +145,7 @@
                } catch (Exception e) {
                        throw new IllegalArgumentException("Unknown type:" + type);
                }
  +             _default = def;
                _mandatory = mandatory;
                _condition = condition;
        }
  @@ -171,6 +178,24 @@
         */
        public String getUsage() {
                return _usage;
  +     }
  +
  +
  +     /**
  +      * return default value configured. If there are options, delegate to them
  +      *
  +      * @return default tag value
  +      */
  +     public String getDefault(XProgramElement xprogramelement) {
  +         if(hasOptions()) {
  +             for (int i = 0; i < _optionSets.size(); i++) {
  +                 OptionSet optionSet = (OptionSet)_optionSets.get(i);
  +                 if (optionSet.eval(xprogramelement)) {
  +                     return optionSet.getDefault();
  +                 }
  +             }       
  +         }
  +         return _default;
        }
   
   
  
  
  

_______________________________________________
Xdoclet-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/xdoclet-devel

Reply via email to