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.Map;
26:
27: /**
28: * Defines general support for elements that
29: */
30: public abstract class StrutsElementSupport extends XmlElementSupport {
31: private StrutsApp _parentApp;
32: private String _className;
33: private LinkedHashMap _additionalSetProperties = null;
34:
35: public StrutsElementSupport(StrutsApp parentApp) {
36: _parentApp = parentApp;
37: }
38:
39: protected StrutsApp getParentApp() {
40: return _parentApp;
41: }
42:
43: public String getClassName() {
44: return _className;
45: }
46:
47: public void setClassName(String className) {
48: _className = className;
49: }
50:
51: protected void setParentApp(StrutsApp parentApp) {
52: _parentApp = parentApp;
53: }
54:
55: protected final void setCustomProperty(XmlModelWriter xw,
56: Element element, String propertyName, String value,
57: String changeElementClassName) {
58: if (value != null) {
59: Element setPropertyElement = findChildElement(xw, element,
60: "set-property", "property", propertyName, true,
61: null);
62: setPropertyElement.setAttribute("property", propertyName);
63: setElementAttributeMayBeEmpty(setPropertyElement, "value",
64: value);
65: setElementAttribute(element, "className",
66: changeElementClassName);
67: }
68: }
69:
70: protected void addSetProperty(String name, String value) {
71: if (_additionalSetProperties == null)
72: _additionalSetProperties = new LinkedHashMap();
73: _additionalSetProperties.put(name, value);
74: }
75:
76: protected void writeAdditionalSetProperties(XmlModelWriter xw,
77: Element element) {
78: // Add additional set-property elements.
79: if (_additionalSetProperties != null) {
80: for (Iterator i = _additionalSetProperties.entrySet()
81: .iterator(); i.hasNext();) {
82: Map.Entry entry = (Map.Entry) i.next();
83: addSetProperty(xw, element, (String) entry.getKey(),
84: (String) entry.getValue());
85: }
86: }
87: }
88:
89: protected abstract void addSetProperty(XmlModelWriter xw,
90: Element element, String propertyName, String propertyValue);
91: }
|