Coverage Report - net.wotonomy.web.WOSwitchComponent
 
Classes in this File Line Coverage Branch Coverage Complexity
WOSwitchComponent
0% 
0% 
2.571
 
 1  
 /*
 2  
  Wotonomy: OpenStep design patterns for pure Java applications.
 3  
  Copyright (C) 2000 Blacksmith, Inc.
 4  
 
 5  
  This library is free software; you can redistribute it and/or
 6  
  modify it under the terms of the GNU Lesser General Public
 7  
  License as published by the Free Software Foundation; either
 8  
  version 2.1 of the License, or (at your option) any later version.
 9  
 
 10  
  This library is distributed in the hope that it will be useful,
 11  
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 13  
  Lesser General Public License for more details.
 14  
 
 15  
  You should have received a copy of the GNU Lesser General Public
 16  
  License along with this library; if not, see http://www.gnu.org
 17  
  */
 18  
 
 19  
 package net.wotonomy.web;
 20  
 
 21  
 import net.wotonomy.foundation.NSDictionary;
 22  
 import net.wotonomy.foundation.NSMutableDictionary;
 23  
 
 24  
 public class WOSwitchComponent extends WODynamicElement {
 25  
 
 26  
     private NSMutableDictionary elements;
 27  
     private String currentName;
 28  
     private WOElement currentElement;
 29  
 
 30  
     protected WOSwitchComponent() 
 31  
     {
 32  0
         super();
 33  0
         elements = new NSMutableDictionary();
 34  0
     }
 35  
 
 36  
     public WOSwitchComponent(String aName, NSDictionary aMap, WOElement template) 
 37  
     {
 38  0
         super(aName, aMap, template);
 39  0
         elements = new NSMutableDictionary();
 40  0
     }
 41  
     
 42  
     private WOElement getCurrentElement( WOContext c )
 43  
     {
 44  0
         String name = stringForProperty( "WOComponentName", c.component() );
 45  0
         if ( name == null ) return null;
 46  
         
 47  0
         if ( currentElement != null && name.equals( currentName ) ) return currentElement;
 48  
         
 49  0
         currentName = name;
 50  0
         currentElement = (WOElement) elements.objectForKey( name );
 51  0
         if ( currentElement == null )
 52  
         {
 53  0
             currentElement = WOApplication.application().pageWithName( name, c );
 54  0
             if ( currentElement != null )
 55  
             {
 56  0
                 currentElement.associations = associations;
 57  0
                 elements.setObjectForKey( currentElement, name );
 58  
             }
 59  
         }
 60  
         
 61  0
         return currentElement;
 62  
     }
 63  
 
 64  
     void ensureAwakeInContext (WOContext aContext)
 65  
     {
 66  0
         if ( aContext != null )
 67  
         {
 68  0
             WOElement element = getCurrentElement( aContext );
 69  0
             if ( element != null )
 70  
             {
 71  0
                 aContext.pushElement( element );
 72  0
                 element.ensureAwakeInContext( aContext );
 73  0
                 aContext.popElement();
 74  
             }
 75  
         }
 76  0
     }
 77  
 
 78  
     public void takeValuesFromRequest(WORequest r, WOContext c) 
 79  
     {
 80  0
         WOElement element = getCurrentElement( c );
 81  0
         if ( element != null )
 82  
         {
 83  0
             c.pushElement( element );
 84  0
             element.takeValuesFromRequest( r, c );
 85  0
             c.popElement();
 86  
         }
 87  0
     }
 88  
 
 89  
     public WOActionResults invokeAction(WORequest r, WOContext c) 
 90  
     {
 91  0
         WOActionResults result = null;
 92  0
         WOElement element = getCurrentElement( c );
 93  0
         if ( element != null )
 94  
         {
 95  0
             c.pushElement( element );
 96  0
             result = element.invokeAction( r, c );
 97  0
             c.popElement();
 98  
         }
 99  0
         return result;
 100  
     }
 101  
 
 102  
     public void appendToResponse(WOResponse r, WOContext c) 
 103  
     {
 104  0
         WOElement element = getCurrentElement( c );
 105  0
         if ( element != null )
 106  
         {
 107  0
             c.pushElement( element );
 108  0
             element.appendToResponse( r, c );
 109  0
             c.popElement();
 110  
         }
 111  0
     }
 112  
 }