KickJava   Java API By Example, From Geeks To Geeks.

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


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.SetPropertyDocument.SetProperty;
21 import org.apache.beehive.netui.compiler.model.schema.struts11.ExceptionDocument;
22 import org.apache.beehive.netui.compiler.model.validation.ValidatorConstants;
23 import org.apache.beehive.netui.compiler.JpfLanguageConstants;
24
25 public class ExceptionModel
26         extends StrutsElementSupport
27         implements JpfLanguageConstants
28 {
29     private String JavaDoc _type;
30     private String JavaDoc _path;
31     private String JavaDoc _handlerMethod;
32     private String JavaDoc _message;
33     private String JavaDoc _messageKey;
34     private String JavaDoc _handlerClass;
35     private boolean _readonly = false;
36
37     private static final String JavaDoc JPF_EXCEPTION_CONFIG_CLASSNAME = PAGEFLOW_PACKAGE + ".config.PageFlowExceptionConfig";
38     
39     
40     protected ExceptionModel( StrutsApp parentApp )
41     {
42         super( parentApp );
43     }
44     
45     public ExceptionModel( String JavaDoc type, String JavaDoc path, String JavaDoc handlerMethod, String JavaDoc message,
46                            String JavaDoc messageKey, StrutsApp parentApp )
47     {
48         super( parentApp );
49         
50         _type = type;
51         _path = path;
52         _handlerMethod = handlerMethod;
53         _message = message;
54         _messageKey = messageKey;
55     }
56
57     public String JavaDoc getType()
58     {
59         return _type;
60     }
61
62     public void setType( String JavaDoc type )
63     {
64         _type = type;
65     }
66
67     public String JavaDoc getPath()
68     {
69         return _path;
70     }
71
72     public void setPath( String JavaDoc path )
73     {
74         _path = path;
75     }
76
77     public String JavaDoc getHandlerMethod()
78     {
79         return _handlerMethod;
80     }
81
82     public void setHandlerMethod( String JavaDoc handlerMethod )
83     {
84         _handlerMethod = handlerMethod;
85     }
86
87     public String JavaDoc getMessage()
88     {
89         return _message;
90     }
91
92     public void setMessage( String JavaDoc message )
93     {
94         _message = message;
95     }
96
97     public String JavaDoc getMessageKey()
98     {
99         return _messageKey;
100     }
101
102     public void setMessageKey( String JavaDoc messageKey )
103     {
104         _messageKey = messageKey;
105     }
106
107     public String JavaDoc getHandlerClass()
108     {
109         return _handlerClass;
110     }
111
112     public void setHandlerClass( String JavaDoc handlerClass )
113     {
114         _handlerClass = handlerClass;
115     }
116
117     public void writeToXMLBean( ExceptionDocument.Exception xb )
118
119     {
120         xb.setType( _type );
121
122         if ( xb.getPath() == null && _path != null )
123         {
124             boolean relativeToModule = ! _path.startsWith( "/" );
125             
126             if ( relativeToModule )
127             {
128                 xb.setPath( "/" + _path ); // struts wants "/" -- assumes this is module-relative path
129
}
130             else
131             {
132                 xb.setPath( _path );
133                 addSetProperty( xb, "isPathContextRelative", "true" );
134             }
135         }
136         
137         if ( xb.getKey() == null && _messageKey != null ) xb.setKey( _messageKey );
138         
139         //
140
// Struts doesn't support "message" directly -- we'll add this as a custom property.
141
//
142
if ( _message != null ) addSetProperty( xb, "defaultMessage", _message );
143         
144         if ( xb.getKey() == null ) xb.setKey( _type );
145         
146         //
147
// Note that we're setting the handler *method* as the handler. This would break Struts.
148
//
149
if ( xb.getHandler() == null && _handlerMethod != null && _handlerClass == null )
150         {
151             xb.setHandler( _handlerMethod );
152             addSetProperty( xb, "isHandlerMethod", "true" );
153         }
154         
155         if ( _readonly ) addSetProperty( xb, "readonly", "true" );
156         if ( xb.getHandler() == null && _handlerClass != null ) xb.setHandler( _handlerClass );
157     }
158     
159     private void addSetProperty( ExceptionDocument.Exception xb, String JavaDoc propertyName, String JavaDoc propertyValue )
160     {
161         SetProperty prop = xb.addNewSetProperty();
162         prop.setProperty( propertyName );
163         prop.setValue( propertyValue );
164         if ( xb.getClassName() == null ) xb.setClassName( JPF_EXCEPTION_CONFIG_CLASSNAME );
165     }
166
167     public boolean isReadonly()
168     {
169         return _readonly;
170     }
171
172     public void setReadonly( boolean readonly )
173     {
174         _readonly = readonly;
175     }
176 }
177
Popular Tags