001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: * $Header:$
018: */
019: package org.apache.beehive.netui.compiler.model;
020:
021: import org.apache.beehive.netui.compiler.JpfLanguageConstants;
022: import org.w3c.dom.Element;
023:
024: public class ExceptionModel extends StrutsElementSupport implements
025: JpfLanguageConstants {
026: private String _type;
027: private String _path;
028: private String _handlerMethod;
029: private String _message;
030: private String _messageKey;
031: private String _handlerClass;
032: private boolean _readonly = false;
033:
034: private static final String EXCEPTION_CONFIG_CLASSNAME = PAGEFLOW_PACKAGE
035: + ".config.PageFlowExceptionConfig";
036:
037: protected ExceptionModel(StrutsApp parentApp) {
038: super (parentApp);
039: }
040:
041: public ExceptionModel(String type, String path,
042: String handlerMethod, String message, String messageKey,
043: StrutsApp parentApp) {
044: super (parentApp);
045:
046: _type = type;
047: _path = path;
048: _handlerMethod = handlerMethod;
049: _message = message;
050: _messageKey = messageKey;
051: }
052:
053: public String getType() {
054: return _type;
055: }
056:
057: public void setType(String type) {
058: _type = type;
059: }
060:
061: public String getPath() {
062: return _path;
063: }
064:
065: public void setPath(String path) {
066: _path = path;
067: }
068:
069: public String getHandlerMethod() {
070: return _handlerMethod;
071: }
072:
073: public void setHandlerMethod(String handlerMethod) {
074: _handlerMethod = handlerMethod;
075: }
076:
077: public String getMessage() {
078: return _message;
079: }
080:
081: public void setMessage(String message) {
082: _message = message;
083: }
084:
085: public String getMessageKey() {
086: return _messageKey;
087: }
088:
089: public void setMessageKey(String messageKey) {
090: _messageKey = messageKey;
091: }
092:
093: public String getHandlerClass() {
094: return _handlerClass;
095: }
096:
097: public void setHandlerClass(String handlerClass) {
098: _handlerClass = handlerClass;
099: }
100:
101: protected void writeToElement(XmlModelWriter xw, Element element) {
102: element.setAttribute("type", _type);
103:
104: if (_path != null) {
105: boolean relativeToModule = !_path.startsWith("/");
106:
107: if (relativeToModule) {
108: // struts wants "/" -- assumes this is module-relative path
109: setElementAttribute(element, "path", '/' + _path);
110: } else {
111: setElementAttributeMayBeEmpty(element, "path", _path);
112: addSetProperty(xw, element, "isPathContextRelative",
113: "true");
114: }
115: }
116:
117: //
118: // Set the message key. If there isn't one, use the typename as the message key.
119: setElementAttribute(element, "key", _messageKey);
120: if (_messageKey == null)
121: setElementAttribute(element, "key", _type);
122:
123: //
124: // Struts doesn't support "message" directly -- we'll add this as a custom property.
125: //
126: addSetProperty(xw, element, "defaultMessage", _message);
127:
128: //
129: // Note that we're setting the handler *method* as the handler. This would break Struts.
130: //
131: if (_handlerMethod != null && _handlerClass == null) {
132: setElementAttribute(element, "handler", _handlerMethod);
133: addSetProperty(xw, element, "isHandlerMethod", "true");
134: } else {
135: setElementAttribute(element, "handler", _handlerClass);
136: }
137:
138: if (_readonly)
139: addSetProperty(xw, element, "readonly", "true");
140:
141: writeAdditionalSetProperties(xw, element);
142: }
143:
144: protected void addSetProperty(XmlModelWriter xw, Element element,
145: String propertyName, String propertyValue) {
146: setCustomProperty(xw, element, propertyName, propertyValue,
147: EXCEPTION_CONFIG_CLASSNAME);
148: }
149:
150: public boolean isReadonly() {
151: return _readonly;
152: }
153:
154: public void setReadonly(boolean readonly) {
155: _readonly = readonly;
156: }
157: }
|