mpo         2004/04/21 06:33:37

  Modified:    src/blocks/forms/java/org/apache/cocoon/forms/formmodel
                        AbstractWidget.java Repeater.java Widget.java
               src/blocks/forms/java/org/apache/cocoon/forms/flow/javascript/v2
                        ScriptableWidget.java
  Log:
  Removing getNamespace since it has become the duplicate of getFullQualifiedId.
  Adding javadoc towards expected getDefinition() and effects on other methods.
  More clean-up and making the getFullQualifiedId() to work correctly with 
possible overloaded getParent() 
  (needed for repeater-rows!)
  
  Revision  Changes    Path
  1.8       +76 -22    
cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidget.java
  
  Index: AbstractWidget.java
  ===================================================================
  RCS file: 
/home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidget.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- AbstractWidget.java       20 Apr 2004 22:19:27 -0000      1.7
  +++ AbstractWidget.java       21 Apr 2004 13:33:37 -0000      1.8
  @@ -37,11 +37,29 @@
    * @version $Id$
    */
   public abstract class AbstractWidget implements Widget {
  +    
  +    /** 
  +     * Containing parent-widget to this widget.
  +     * NOTE: avoid directly accessing this member since subclasses can mask 
this
  +     * property through own implemented getParent()
  +     */
       private Widget parent;
  +    
  +    /**
  +     * Lazy loaded reference to the top-level form.
  +     */
       private Form form;
           
  +    /**
  +     * Validation-rules local to the widget instance
  +     */
       private List validators;
  +
  +    /**
  +     * Storage for the widget allocated attributes
  +     */
       private Map attributes;
  + 
       
       /**
        * Gets the id of this widget.
  @@ -53,7 +71,12 @@
       /** 
        * Concrete subclasses should allow access to their underlaying 
Definition
        * through this method.
  -     *  
  +     *
  +     * If subclasses decide to return <code>null</code> they should also 
organize 
  +     * own implementations of [EMAIL PROTECTED] #getId()}, [EMAIL PROTECTED] 
#getLocation()},
  +     * [EMAIL PROTECTED] #validate(FormContext)}, [EMAIL PROTECTED] 
#generateLabel} and
  +     * [EMAIL PROTECTED] #generateDisplayData} to avoid NPE's.
  +     * 
        * @return the widgetDefinition from which this widget was instantiated. 
        *        (@link WidgetDefinition#createInstance()}
        */
  @@ -88,11 +111,12 @@
        * @return the form where this widget belongs to.  
        */
       public Form getForm() {
  +        Widget myParent = getParent();
           if (this.form == null) {
  -            if (parent == null) {
  +            if (myParent == null) {
                   this.form = (Form)this;
               } else {
  -                this.form = parent.getForm();
  +                this.form = myParent.getForm();
               }
           }
           return this.form;
  @@ -102,19 +126,21 @@
       //TODO: check why this namespace property exists, it seems to be 
       // deceptively resemblant to the getFullyQualifiedId, 
       // looks like it can be removed, no?
  -    public String getNamespace() {    
  -        if (getParent() != null && getParent().getNamespace().length() > 0) {
  -            return getParent().getNamespace() + "." + getId();
  -        } else {
  -            return getId();
  -        }
  -    }
  +//    public String getNamespace() {    
  +//        if (getParent() != null && getParent().getNamespace().length() > 
0) {
  +//            return getParent().getNamespace() + "." + getId();
  +//        } else {
  +//            return getId();
  +//        }
  +//    }
   
       public String getFullyQualifiedId() {
  -        if (parent != null) {
  -            String namespace = parent.getNamespace();
  -            if (namespace.length() > 0) {
  -                return namespace + "." + getId();
  +        Widget myParent = getParent();
  +        if (myParent != null) {
  +            String parentFullId = myParent.getFullyQualifiedId();
  +            // the top level form returns an id == ""
  +            if (parentFullId.length() > 0) {
  +                return parentFullId + "." + getId();
               }
           }
           return getId();
  @@ -199,11 +225,21 @@
               }
           }
       }
  -    
  +
  +    /**
  +     * @inheritDoc
  +     * 
  +     * Delegates to the [EMAIL PROTECTED] #getDefinition()} to generate the 
'label' part of
  +     * the display-data of this widget.  
  +     * 
  +     * Subclasses should override if the getDefinition can return 
<code>null</code>
  +     * to avoid NPE's
  +     * 
  +     * @param contentHandler
  +     * @throws SAXException
  +     */
       public void generateLabel(ContentHandler contentHandler) throws 
SAXException {
  -        if (getDefinition() != null) {
  -            getDefinition().generateDisplayData("label", contentHandler);
  -        }
  +        getDefinition().generateDisplayData("label", contentHandler);
       }
   
       
  @@ -212,6 +248,7 @@
        * widget which is generated by [EMAIL PROTECTED] 
#generateSaxFragment(ContentHandler, Locale)}
        * 
        * The implementation on the AbstractWidget level inserts no additional 
XML.
  +     * Subclasses need to override to insert widget specific content.
        * 
        * @param contentHandler to send the SAX events to
        * @param locale in which context potential content needs to be put.
  @@ -244,7 +281,23 @@
           attrs.addCDATAAttribute("id", getFullyQualifiedId());
           return attrs;
       }
  -    
  +
  +    /**
  +     * Delegates to the [EMAIL PROTECTED] #getDefinition()} of this widget 
to generate a common
  +     * set of 'display' data.
  +     * 
  +     * Subclasses should override if the getDefinition can return 
<code>null</code>
  +     * to avoid NPE's
  +     * 
  +     * @param contentHandler where to send the SAX events to.
  +     * @throws SAXException
  +     * 
  +     * @see WidgetDefinition#generateDisplayData(ContentHandler) 
  +     */
  +    public void generateDisplayData(ContentHandler contentHandler) throws 
SAXException {
  +        getDefinition().generateDisplayData(contentHandler);
  +    }
  +
       /**
        * @inheritDoc
        * 
  @@ -268,13 +321,14 @@
           AttributesImpl attrs = getXMLElementAttributes();
           contentHandler.startElement(Constants.INSTANCE_NS, element, 
Constants.INSTANCE_PREFIX_COLON + element, attrs);
   
  +        generateDisplayData(contentHandler);
  +        
           generateItemSaxFragment(contentHandler, locale);
           
           contentHandler.endElement(Constants.INSTANCE_NS, element, 
Constants.INSTANCE_PREFIX_COLON + element);
       }
   
  -
  -    public Object getAttribute(String name) {
  +     public Object getAttribute(String name) {
           if (this.attributes != null){
               return this.attributes.get(name);
           } else{
  
  
  
  1.8       +8 -8      
cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Repeater.java
  
  Index: Repeater.java
  ===================================================================
  RCS file: 
/home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Repeater.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Repeater.java     20 Apr 2004 22:19:27 -0000      1.7
  +++ Repeater.java     21 Apr 2004 13:33:37 -0000      1.8
  @@ -334,13 +334,13 @@
               return Repeater.this.getForm();
           }
   
  -        public String getNamespace() {
  -            return getParent().getNamespace() + "." + getId();
  -        }
  -
  -        public String getFullyQualifiedId() {
  -            return getParent().getNamespace() + "." + getId();
  -        }
  +//        public String getNamespace() {
  +//            return getParent().getNamespace() + "." + getId();
  +//        }
  +//
  +//        public String getFullyQualifiedId() {
  +//            return getParent().getNamespace() + "." + getId();
  +//        }
   
           public void setParent(Widget widget) {
               throw new RuntimeException("Parent of RepeaterRow is fixed, and 
cannot be set.");
  
  
  
  1.5       +8 -8      
cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Widget.java
  
  Index: Widget.java
  ===================================================================
  RCS file: 
/home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Widget.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Widget.java       20 Apr 2004 22:19:27 -0000      1.4
  +++ Widget.java       21 Apr 2004 13:33:37 -0000      1.5
  @@ -87,13 +87,13 @@
        */
       public Form getForm();
   
  -    /**
  -     * Gets the namespace of this widget. The combination of a widget's 
namespace
  -     * with its id (see [EMAIL PROTECTED] #getId()} gives the widget a 
form-wide unique name.
  -     * In practice, the namespace consists of the id's of the widget's 
parent widgets,
  -     * separated by dots.
  -     */
  -    public String getNamespace();
  +//    /**
  +//     * Gets the namespace of this widget. The combination of a widget's 
namespace
  +//     * with its id (see [EMAIL PROTECTED] #getId()} gives the widget a 
form-wide unique name.
  +//     * In practice, the namespace consists of the id's of the widget's 
parent widgets,
  +//     * separated by dots.
  +//     */
  +//    public String getNamespace();
   
       /**
        * Returns the id prefixed with the namespace, this name should be unique
  
  
  
  1.6       +4 -4      
cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/flow/javascript/v2/ScriptableWidget.java
  
  Index: ScriptableWidget.java
  ===================================================================
  RCS file: 
/home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/flow/javascript/v2/ScriptableWidget.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ScriptableWidget.java     14 Apr 2004 21:25:41 -0000      1.5
  +++ ScriptableWidget.java     21 Apr 2004 13:33:37 -0000      1.6
  @@ -471,9 +471,9 @@
           return delegate.getFullyQualifiedId();
       }
   
  -    public String jsFunction_getNamespace() {
  -        return delegate.getNamespace();
  -    }
  +//    public String jsFunction_getNamespace() {
  +//        return delegate.getNamespace();
  +//    }
   
       public Scriptable jsFunction_getParent() {
           if (delegate != null) {
  
  
  

Reply via email to