Coverage Report - org.seasar.uruma.component.EnablesDependableVisitor
 
Classes in this File Line Coverage Branch Coverage Complexity
EnablesDependableVisitor
0%
0/24
0%
0/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;
 17  
 
 18  
 import org.seasar.framework.util.StringUtil;
 19  
 import org.seasar.uruma.binding.enables.EnablesDependingDef;
 20  
 import org.seasar.uruma.binding.enables.EnablesForType;
 21  
 import org.seasar.uruma.context.WidgetHandle;
 22  
 import org.seasar.uruma.context.WindowContext;
 23  
 import org.seasar.uruma.core.UrumaMessageCodes;
 24  
 import org.seasar.uruma.exception.NotFoundException;
 25  
 
 26  
 /**
 27  
  * コンポーネントツリーを走査して、 {@link EnablesDependable} の登録を行うための {@link UIElementVisitor}
 28  
  * です。<br />
 29  
  * 
 30  
  * @author y-komori
 31  
  */
 32  
 public class EnablesDependableVisitor implements UIElementVisitor,
 33  
         UrumaMessageCodes {
 34  
     private WindowContext context;
 35  
 
 36  
     /**
 37  
      * {@link EnablesDependableVisitor} を構築します。<br />
 38  
      * 
 39  
      * @param context
 40  
      */
 41  0
     public EnablesDependableVisitor(final WindowContext context) {
 42  0
         this.context = context;
 43  0
     }
 44  
 
 45  
     /*
 46  
      * @see org.seasar.uruma.component.UIElementVisitor#visit(org.seasar.uruma.component.UIElement)
 47  
      */
 48  
     public void visit(final UIElement element) {
 49  0
         if ((element instanceof UIComponent)
 50  
                 && (element instanceof EnablesDependable)) {
 51  0
             EnablesDependable dependable = (EnablesDependable) element;
 52  0
             String id = ((UIComponent) element).getId();
 53  
 
 54  0
             if (id != null) {
 55  
 
 56  0
                 String enablesDependingId = dependable.getEnablesDependingId();
 57  0
                 String enablesForType = dependable.getEnablesFor();
 58  
 
 59  0
                 if (!StringUtil.isEmpty(enablesDependingId)) {
 60  0
                     EnablesForType type = EnablesForType.SELECTION;
 61  0
                     if (!StringUtil.isEmpty(enablesForType)) {
 62  0
                         type = EnablesForType.valueOf(enablesForType);
 63  
                     }
 64  
 
 65  0
                     WidgetHandle handle = context.getWidgetHandle(id);
 66  0
                     if (handle != null) {
 67  0
                         EnablesDependingDef def = new EnablesDependingDef(
 68  
                                 handle, enablesDependingId, type);
 69  0
                         context.addEnablesDependingDef(def);
 70  0
                     } else {
 71  0
                         throw new NotFoundException(UICOMPONENT_NOT_FOUND, id);
 72  
                     }
 73  
                 }
 74  
             }
 75  
         }
 76  0
     }
 77  
 
 78  
     /*
 79  
      * @see org.seasar.uruma.component.UIElementVisitor#visit(org.seasar.uruma.component.UIElementContainer)
 80  
      */
 81  
     public void visit(final UIElementContainer container) {
 82  0
         for (UIElement element : container.getChildren()) {
 83  0
             element.accept(this);
 84  
         }
 85  0
     }
 86  
 
 87  
     /*
 88  
      * @see org.seasar.uruma.component.UIElementVisitor#visit(org.seasar.uruma.component.Template)
 89  
      */
 90  
     public void visit(final Template template) {
 91  
         // Do nothing.
 92  0
     }
 93  
 }