01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: * $Header:$
18: */
19: package org.apache.beehive.netui.compiler.model;
20:
21: import org.w3c.dom.Element;
22:
23: import java.util.LinkedHashMap;
24: import java.util.Iterator;
25: import java.util.List;
26: import java.util.ArrayList;
27:
28: abstract class AbstractForwardContainer extends StrutsElementSupport
29: implements ForwardContainer {
30: private LinkedHashMap _forwards = new LinkedHashMap();
31:
32: public AbstractForwardContainer(StrutsApp parentApp) {
33: super (parentApp);
34: }
35:
36: public AbstractForwardContainer(AbstractForwardContainer src) {
37: super (src.getParentApp());
38: _forwards = (LinkedHashMap) src._forwards.clone();
39: }
40:
41: /**
42: * Implemented for {@link ForwardContainer}.
43: */
44: public void addForward(ForwardModel newActionForward) {
45: if (_forwards.containsKey(newActionForward.getName())) {
46: // TODO: Rich - replace this with something other than the knex logger so that the xdoclet compiler
47: // won't require knex
48: // if ( ! fwd.getPath().equals( newActionForward.getPath() ) )
49: // {
50: // logger.warn( "Could not add forward \"" + newActionForward.getName() + "\", path=\""
51: // + newActionForward.getPath() + "\" because there is already a forward with"
52: // + " the same name (path=\"" + fwd.getPath() + "\")." );
53: // }
54:
55: return;
56: }
57:
58: _forwards.put(newActionForward.getName(), newActionForward);
59: }
60:
61: public ForwardModel findForward(String forwardName) {
62: return (ForwardModel) _forwards.get(forwardName);
63: }
64:
65: public void writeForwards(XmlModelWriter xw,
66: Element forwardsParentElement) {
67: for (Iterator i = _forwards.values().iterator(); i.hasNext();) {
68: ForwardModel fwd = (ForwardModel) i.next();
69: Element fwdToEdit = findChildElement(xw,
70: forwardsParentElement, "forward", "name", fwd
71: .getName(), true, null);
72: fwd.writeXML(xw, fwdToEdit);
73: }
74: }
75:
76: public ForwardModel[] getForwards() {
77: return (ForwardModel[]) _forwards.values().toArray(
78: new ForwardModel[_forwards.size()]);
79: }
80:
81: public List getForwardsAsList() {
82: List ret = new ArrayList();
83: ret.addAll(_forwards.values());
84: return ret;
85: }
86:
87: public void deleteForward(ForwardModel forward) {
88: _forwards.remove(forward.getName());
89: }
90:
91: }
|