Coverage Report - org.seasar.uruma.context.impl.WindowContextImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
WindowContextImpl
47%
27/58
32%
7/22
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.context.impl;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.Collections;
 20  
 import java.util.HashSet;
 21  
 import java.util.List;
 22  
 import java.util.Set;
 23  
 
 24  
 import org.seasar.uruma.binding.enables.EnablesDependingDef;
 25  
 import org.seasar.uruma.context.ApplicationContext;
 26  
 import org.seasar.uruma.context.PartContext;
 27  
 import org.seasar.uruma.context.WidgetHandle;
 28  
 import org.seasar.uruma.context.WindowContext;
 29  
 import org.seasar.uruma.desc.FormDesc;
 30  
 import org.seasar.uruma.desc.PartActionDesc;
 31  
 import org.seasar.uruma.exception.DuplicateComponentIdException;
 32  
 import org.seasar.uruma.util.AssertionUtil;
 33  
 
 34  
 /**
 35  
  * {@link WindowContext} の実装クラスです。<br />
 36  
  * 
 37  
  * @author y-komori
 38  
  */
 39  
 public class WindowContextImpl extends AbstractWidgetHolder implements
 40  
         WindowContext {
 41  
 
 42  
     private String windowName;
 43  
 
 44  112
     private List<PartContext> partContextList = new ArrayList<PartContext>();
 45  
 
 46  
     private ApplicationContextImpl parent;
 47  
 
 48  112
     private List<EnablesDependingDef> enablesDependingDefList = new ArrayList<EnablesDependingDef>();
 49  
 
 50  
     private Object partActionObj;
 51  
 
 52  
     private PartActionDesc partActionDesc;
 53  
 
 54  
     /**
 55  
      * {@link WindowContextImpl} を構築します。<br />
 56  
      * 
 57  
      * @param windowName
 58  
      *            ウィンドウ名称
 59  
      * @param parent
 60  
      *            親 {@link ApplicationContext}
 61  
      */
 62  
     public WindowContextImpl(final String windowName,
 63  
             final ApplicationContext parent) {
 64  112
         super();
 65  
 
 66  112
         this.windowName = windowName;
 67  112
         this.parent = (ApplicationContextImpl) parent;
 68  112
     }
 69  
 
 70  
     /*
 71  
      * @see org.seasar.uruma.context.WindowContext#getWindowName()
 72  
      */
 73  
     public String getName() {
 74  224
         return this.windowName;
 75  
     }
 76  
 
 77  
     /*
 78  
      * @see org.seasar.uruma.context.WindowContext#getPartContext()
 79  
      */
 80  
     public PartContext getPartContext() {
 81  0
         if ((partContextList != null) && (partContextList.size() > 0)) {
 82  0
             return partContextList.get(0);
 83  
         } else {
 84  0
             return null;
 85  
         }
 86  
     }
 87  
 
 88  
     /*
 89  
      * @see org.seasar.uruma.context.WindowContext#getPartContext(java.lang.String)
 90  
      */
 91  
     public PartContext getPartContext(final String partName) {
 92  112
         for (PartContext context : partContextList) {
 93  0
             if (context.getName().equals(partName)) {
 94  0
                 return context;
 95  
             }
 96  
         }
 97  112
         return null;
 98  
     }
 99  
 
 100  
     /*
 101  
      * @see org.seasar.uruma.context.WindowContext#getPartContextList()
 102  
      */
 103  
     public List<PartContext> getPartContextList() {
 104  468
         return Collections.unmodifiableList(partContextList);
 105  
     }
 106  
 
 107  
     /*
 108  
      * @see org.seasar.uruma.context.WindowContext#getApplicationContext()
 109  
      */
 110  
     public ApplicationContext getApplicationContext() {
 111  336
         return parent;
 112  
     }
 113  
 
 114  
     /**
 115  
      * {@link PartContext} オブジェクトを追加します。<br />
 116  
      * 
 117  
      * @param context
 118  
      *            {@link PartContext} オブジェクト
 119  
      * @throws DuplicateComponentIdException
 120  
      *             パート名称が既に登録されている場合
 121  
      */
 122  
     public void addPartContext(final PartContext context) {
 123  112
         if (getPartContext(context.getName()) == null) {
 124  112
             partContextList.add(context);
 125  
         } else {
 126  0
             throw new DuplicateComponentIdException(context.getName());
 127  
         }
 128  112
     }
 129  
 
 130  
     /**
 131  
      * {@link PartContext} オブジェクトを削除します。<br />
 132  
      * 
 133  
      * @param partName
 134  
      *            パート名称
 135  
      */
 136  
     public void disposePartContext(final String partName) {
 137  0
         PartContext partContext = getPartContext(partName);
 138  0
         if (partContext != null) {
 139  0
             partContextList.remove(partContext);
 140  
         }
 141  0
     }
 142  
 
 143  
     /**
 144  
      * この {@link WindowContext} を親 {@link ApplicationContext} から削除します。<br />
 145  
      */
 146  
     public void dispose() {
 147  0
         for (PartContext part : partContextList) {
 148  0
             disposePartContext(part.getName());
 149  
         }
 150  0
         parent.disposeWindowContext(windowName);
 151  0
         parent = null;
 152  0
     }
 153  
 
 154  
     /*
 155  
      * @see org.seasar.uruma.context.WindowContext#findWidgetHandles(java.lang.String)
 156  
      */
 157  
     public Set<WidgetHandle> findWidgetHandles(final String handleId) {
 158  468
         Set<WidgetHandle> results = new HashSet<WidgetHandle>();
 159  
 
 160  468
         WidgetHandle handle = getWidgetHandle(handleId);
 161  468
         if (handle != null) {
 162  8
             results.add(handle);
 163  
         }
 164  
 
 165  468
         for (PartContext part : getPartContextList()) {
 166  468
             handle = part.getWidgetHandle(handleId);
 167  468
             if (handle != null) {
 168  468
                 results.add(handle);
 169  
             }
 170  
         }
 171  468
         return results;
 172  
     }
 173  
 
 174  
     /*
 175  
      * @see org.seasar.uruma.context.WindowContext#getAllWidgetHandles(java.lang.Class)
 176  
      */
 177  
     public Set<WidgetHandle> getAllWidgetHandles(final Class<?> clazz) {
 178  0
         Set<WidgetHandle> handles = new HashSet<WidgetHandle>();
 179  0
         handles.addAll(getWidgetHandles(clazz));
 180  
 
 181  0
         for (PartContext part : getPartContextList()) {
 182  0
             handles.addAll(part.getWidgetHandles(clazz));
 183  
         }
 184  
 
 185  0
         return handles;
 186  
     }
 187  
 
 188  
     /*
 189  
      * @see org.seasar.uruma.context.WindowContext#addEnablesDependingDef(org.seasar
 190  
      *      .uruma.binding.enables.EnablesDependingDef)
 191  
      */
 192  
     public void addEnablesDependingDef(
 193  
             final EnablesDependingDef enablesDependingDef) {
 194  40
         AssertionUtil.assertNotNull("enablesDependingDef", enablesDependingDef);
 195  40
         enablesDependingDefList.add(enablesDependingDef);
 196  40
     }
 197  
 
 198  
     /*
 199  
      * @see org.seasar.uruma.context.WindowContext#getEnablesDependingDefList()
 200  
      */
 201  
     public List<EnablesDependingDef> getEnablesDependingDefList() {
 202  112
         return Collections.unmodifiableList(enablesDependingDefList);
 203  
     }
 204  
 
 205  
     /*
 206  
      * @see org.seasar.uruma.context.PartContext#getPartActionObject()
 207  
      */
 208  
     public Object getPartActionObject() {
 209  0
         return this.partActionObj;
 210  
     }
 211  
 
 212  
     /*
 213  
      * @see org.seasar.uruma.context.PartContext#getPartActionObject()
 214  
      */
 215  
     public void setPartActionDesc(final PartActionDesc desc) {
 216  0
         this.partActionDesc = desc;
 217  0
     }
 218  
 
 219  
     /*
 220  
      * @see org.seasar.uruma.context.PartContext#setPartActionObject(java.
 221  
      *      lang.Object)
 222  
      */
 223  
     public void setPartActionObject(final Object partActionObj) {
 224  0
         this.partActionObj = partActionObj;
 225  0
     }
 226  
 
 227  
     /*
 228  
      * @see org.seasar.uruma.context.PartContext#getPartActionDesc()
 229  
      */
 230  
     public PartActionDesc getPartActionDesc() {
 231  0
         return this.partActionDesc;
 232  
     }
 233  
 
 234  
     /*
 235  
      * @see org.seasar.uruma.context.PartContext#getPartActionDesc()
 236  
      */
 237  
     public WindowContext getWindowContext() {
 238  0
         return this;
 239  
     }
 240  
 
 241  
     /*
 242  
      * @see org.seasar.uruma.context.PartContext#getFormDesc()
 243  
      */
 244  
     public FormDesc getFormDesc() {
 245  
         // Do noting
 246  0
         return null;
 247  
     }
 248  
 
 249  
     /*
 250  
      * @see org.seasar.uruma.context.PartContext#getFormObject()
 251  
      */
 252  
     public Object getFormObject() {
 253  
         // Do noting
 254  0
         return null;
 255  
     }
 256  
 
 257  
     /*
 258  
      * @see org.seasar.uruma.context.PartContext#setFormDesc()
 259  
      */
 260  
     public void setFormDesc(final FormDesc desc) {
 261  
         // Do noting
 262  0
     }
 263  
 
 264  
     /*
 265  
      * @see org.seasar.uruma.context.PartContext#setFormObject()
 266  
      */
 267  
     public void setFormObject(final Object object) {
 268  
         // Do noting
 269  0
     }
 270  
 
 271  
 }