Coverage Report - org.seasar.uruma.component.base.AbstractUIComponent
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractUIComponent
88%
38/43
71%
10/14
0
 
 1  
 /*
 2  
  * Copyright 2004-2008 the Seasar Foundation and the Others.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
 13  
  * either express or implied. See the License for the specific language
 14  
  * governing permissions and limitations under the License.
 15  
  */
 16  
 package org.seasar.uruma.component.base;
 17  
 
 18  
 import org.seasar.uruma.annotation.ComponentAttribute;
 19  
 import org.seasar.uruma.component.UIComponent;
 20  
 import org.seasar.uruma.component.UIComponentContainer;
 21  
 import org.seasar.uruma.context.PartContext;
 22  
 import org.seasar.uruma.context.WidgetHandle;
 23  
 import org.seasar.uruma.context.WindowContext;
 24  
 import org.seasar.uruma.core.UrumaConstants;
 25  
 import org.seasar.uruma.core.UrumaMessageCodes;
 26  
 import org.seasar.uruma.log.UrumaLogger;
 27  
 import org.seasar.uruma.renderer.Renderer;
 28  
 import org.seasar.uruma.renderer.RendererExtender;
 29  
 import org.seasar.uruma.util.AssertionUtil;
 30  
 
 31  
 /**
 32  
  * {@link UIComponent} を表す基底クラスです。<br />
 33  
  * 
 34  
  * @author y-komori
 35  
  */
 36  1852
 public abstract class AbstractUIComponent extends AbstractUIElement implements
 37  
         UIComponent {
 38  1852
     private UrumaLogger logger = UrumaLogger.getLogger(getClass());
 39  
 
 40  
     private UIComponentContainer parent;
 41  
 
 42  
     @ComponentAttribute
 43  
     private String id;
 44  
 
 45  
     @ComponentAttribute
 46  
     private String style;
 47  
 
 48  
     private Renderer renderer;
 49  
 
 50  
     /**
 51  
      * レンダラ呼び出し中に独自のレンダリング処理を追加するためのメソッドです。<br />
 52  
      * <p>
 53  
      * 本メソッドは {@link AbstractUIComponent#preRender(WidgetHandle, WindowContext)}
 54  
      * メソッドの中で、{@link Renderer レンダラ} の
 55  
      * {@link Renderer#preRender(UIComponent, WidgetHandle, WindowContext)}
 56  
      * メソッドを呼び出した後に呼び出されます。<br />
 57  
      * </p>
 58  
      * <p>
 59  
      * このタイミングでサブクラスで独自のレンダリング処理を行う場合、本メソッドをオーバーライドしてください。<br />
 60  
      * </p>
 61  
      * 
 62  
      * @param parent
 63  
      *            親 {@link WidgetHandle} オブジェクト
 64  
      * @param context
 65  
      *            {@link WindowContext} オブジェクト
 66  
      */
 67  
     protected void doPreRender(final WidgetHandle parent,
 68  
             final WindowContext context) {
 69  1176
     }
 70  
 
 71  
     /**
 72  
      * レンダラ呼び出し中に独自のレンダリング処理を追加するためのメソッドです。<br />
 73  
      * <p>
 74  
      * 本メソッドは {@link AbstractUIComponent#renderer} メソッドの中で、{@link Renderer レンダラ}
 75  
      * の
 76  
      * {@link Renderer#render(UIComponent, WidgetHandle, PartContext) render()}
 77  
      * メソッドと
 78  
      * {@link Renderer#renderAfter(WidgetHandle, UIComponent, WidgetHandle, PartContext) renderAfter()}
 79  
      * メソッドを呼び出す間に呼び出されます。<br />
 80  
      * </p>
 81  
      * <p>
 82  
      * このタイミングでサブクラスで独自のレンダリング処理を行う場合、本メソッドをオーバーライドしてください。<br />
 83  
      * </p>
 84  
      * 
 85  
      * @param parent
 86  
      *            親 {@link WidgetHandle} オブジェクト
 87  
      * @param context
 88  
      *            {@link PartContext} オブジェクト
 89  
      */
 90  
     protected void doRender(final WidgetHandle parent, final PartContext context) {
 91  1004
     }
 92  
 
 93  
     /*
 94  
      * @see org.seasar.uruma.component.UIComponent#preRender(org.seasar.uruma.context.WidgetHandle,
 95  
      *      org.seasar.uruma.context.WindowContext)
 96  
      */
 97  
     public void preRender(final WidgetHandle parent, final WindowContext context) {
 98  1712
         if (logger.isDebugEnabled()) {
 99  0
             logger.log(UrumaMessageCodes.PRE_RENDER_START, this);
 100  
         }
 101  
 
 102  1712
         setupId();
 103  
 
 104  1712
         WidgetHandle handle = getRenderer().preRender(this, parent, context);
 105  1712
         if (handle != null) {
 106  168
             context.putWidgetHandle(handle);
 107  
         }
 108  
 
 109  1712
         doPreRender(parent, context);
 110  
 
 111  1712
         if (logger.isDebugEnabled()) {
 112  0
             logger.log(UrumaMessageCodes.PRE_RENDER_END, this);
 113  
         }
 114  1712
     }
 115  
 
 116  
     /*
 117  
      * @see org.seasar.uruma.component.UIComponent#render(org.seasar.uruma.context.WidgetHandle,
 118  
      *      org.seasar.uruma.context.PartContext)
 119  
      */
 120  
     public void render(final WidgetHandle parent, final PartContext context) {
 121  1640
         if (logger.isDebugEnabled()) {
 122  0
             logger.log(UrumaMessageCodes.RENDER_START, this);
 123  
         }
 124  
 
 125  1640
         setupId();
 126  
 
 127  1640
         WidgetHandle handle = getRenderer().render(this, parent, context);
 128  1640
         if (handle != null) {
 129  1624
             context.putWidgetHandle(handle);
 130  
         }
 131  
 
 132  1640
         doRender(parent, context);
 133  
 
 134  1640
         RendererExtender.doExtRender(this, handle, context);
 135  
 
 136  1640
         getRenderer().renderAfter(handle, this, parent, context);
 137  
 
 138  1640
         if (logger.isDebugEnabled()) {
 139  0
             logger.log(UrumaMessageCodes.RENDER_END, this);
 140  
         }
 141  1640
     }
 142  
 
 143  
     /*
 144  
      * @see org.seasar.uruma.component.UIComponent#getId()
 145  
      */
 146  
     public String getId() {
 147  4308
         return this.id;
 148  
     }
 149  
 
 150  
     /*
 151  
      * @see org.seasar.uruma.component.UIComponent#getParent()
 152  
      */
 153  
     public UIComponentContainer getParent() {
 154  4520
         return parent;
 155  
     }
 156  
 
 157  
     /*
 158  
      * @see org.seasar.uruma.component.UIComponent#getRenderer()
 159  
      */
 160  
     public Renderer getRenderer() {
 161  5112
         return this.renderer;
 162  
     }
 163  
 
 164  
     /*
 165  
      * @see org.seasar.uruma.component.UIComponent#getStyle()
 166  
      */
 167  
     public String getStyle() {
 168  1844
         return this.style;
 169  
     }
 170  
 
 171  
     /*
 172  
      * @see org.seasar.uruma.component.UIComponent#setId(java.lang.String)
 173  
      */
 174  
     public void setId(final String id) {
 175  1828
         this.id = id;
 176  1828
     }
 177  
 
 178  
     /*
 179  
      * @see org.seasar.uruma.component.UIComponent#setParent(org.seasar.uruma.component.UIContainer)
 180  
      */
 181  
     public void setParent(final UIComponentContainer parent) {
 182  1560
         this.parent = parent;
 183  1560
     }
 184  
 
 185  
     /*
 186  
      * @see org.seasar.uruma.component.UIComponent#setRenderer(org.seasar.uruma.renderer.Renderer)
 187  
      */
 188  
     public void setRenderer(final Renderer renderer) {
 189  1852
         AssertionUtil.assertNotNull("renderer", renderer);
 190  1852
         this.renderer = renderer;
 191  1852
     }
 192  
 
 193  
     /*
 194  
      * @see org.seasar.uruma.component.UIComponent#setStyle(java.lang.String)
 195  
      */
 196  
     public void setStyle(final String style) {
 197  532
         this.style = style;
 198  532
     }
 199  
 
 200  
     private void setupId() {
 201  3352
         if (this.id == null) {
 202  1220
             setId(getClass().getName() + UrumaConstants.AT_MARK
 203  
                     + Integer.toHexString(hashCode()));
 204  
         }
 205  3352
     }
 206  
 
 207  
     /*
 208  
      * @see org.seasar.uruma.component.base.AbstractUIElement#toString()
 209  
      */
 210  
     @Override
 211  
     public String toString() {
 212  0
         return getPath() + " id:" + getId();
 213  
     }
 214  
 }