1 18 package org.apache.beehive.netui.compiler.model; 19 20 import org.apache.beehive.netui.compiler.model.schema.struts11.ForwardDocument; 21 import org.apache.xmlbeans.XmlObject; 22 23 import java.util.LinkedHashMap ; 24 import java.util.Iterator ; 25 import java.util.List ; 26 import java.util.ArrayList ; 27 28 29 abstract class AbstractForwardContainer 30 extends StrutsElementSupport 31 implements ForwardContainer 32 { 33 private LinkedHashMap _forwards = new LinkedHashMap (); 34 35 36 public AbstractForwardContainer( StrutsApp parentApp ) 37 { 38 super( parentApp ); 39 } 40 41 public AbstractForwardContainer( AbstractForwardContainer src ) 42 { 43 super( src.getParentApp() ); 44 _forwards = ( LinkedHashMap ) src._forwards.clone(); 45 } 46 47 50 public void addForward( ForwardModel newActionForward ) 51 { 52 if ( _forwards.containsKey( newActionForward.getName() ) ) 53 { 54 63 return; 64 } 65 66 _forwards.put( newActionForward.getName(), newActionForward ); 67 } 68 69 public ForwardModel findForward( String forwardName ) 70 { 71 return ( ForwardModel ) _forwards.get( forwardName ); 72 } 73 74 public void writeForwards( ForwardDocument.Forward[] existingForwards, XmlObject xmlForwardContainer ) 75 { 76 for ( Iterator i = _forwards.values().iterator(); i.hasNext(); ) 77 { 78 ForwardModel fwd = ( ForwardModel ) i.next(); 79 ForwardDocument.Forward fwdToEdit = null; 80 81 for ( int j = 0; j < existingForwards.length; ++j ) 82 { 83 if ( fwd.getName().equals( existingForwards[j].getName() ) ) 84 { 85 fwdToEdit = existingForwards[j]; 86 break; 87 } 88 } 89 90 if ( fwdToEdit == null ) 91 { 92 fwdToEdit = addNewForward( xmlForwardContainer ); 93 } 94 95 fwd.writeToXMLBean( fwdToEdit ); 96 } 97 } 98 99 public ForwardModel[] getForwards() 100 { 101 return ( ForwardModel[] ) _forwards.values().toArray( new ForwardModel[ _forwards.size() ] ); 102 } 103 104 public List getForwardsAsList() 105 { 106 List ret = new ArrayList (); 107 ret.addAll( _forwards.values() ); 108 return ret; 109 } 110 111 public void deleteForward( ForwardModel forward ) 112 { 113 _forwards.remove( forward.getName() ); 114 } 115 116 protected abstract ForwardDocument.Forward addNewForward( XmlObject xmlForwardContainer ); 117 } 118 | Popular Tags |