KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > compiler > model > AbstractForwardContainer


1 /*
2  * Copyright 2004 The Apache Software Foundation.
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, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * $Header:$
17  */

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 JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import java.util.List JavaDoc;
26 import java.util.ArrayList JavaDoc;
27
28
29 abstract class AbstractForwardContainer
30         extends StrutsElementSupport
31         implements ForwardContainer
32 {
33     private LinkedHashMap JavaDoc _forwards = new LinkedHashMap JavaDoc();
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 JavaDoc ) src._forwards.clone();
45     }
46     
47     /**
48       * Implemented for {@link ForwardContainer}.
49       */

50      public void addForward( ForwardModel newActionForward )
51      {
52          if ( _forwards.containsKey( newActionForward.getName() ) )
53          {
54                  // TODO: Rich - replace this with something other than the knex logger so that the xdoclet compiler
55
// won't require knex
56
// if ( ! fwd.getPath().equals( newActionForward.getPath() ) )
57
// {
58
// logger.warn( "Could not add forward \"" + newActionForward.getName() + "\", path=\""
59
// + newActionForward.getPath() + "\" because there is already a forward with"
60
// + " the same name (path=\"" + fwd.getPath() + "\")." );
61
// }
62

63                  return;
64          }
65         
66          _forwards.put( newActionForward.getName(), newActionForward );
67      }
68     
69     public ForwardModel findForward( String JavaDoc forwardName )
70     {
71         return ( ForwardModel ) _forwards.get( forwardName );
72     }
73     
74     public void writeForwards( ForwardDocument.Forward[] existingForwards, XmlObject xmlForwardContainer )
75     {
76         for ( Iterator JavaDoc 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 JavaDoc getForwardsAsList()
105     {
106         List JavaDoc ret = new ArrayList JavaDoc();
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