KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > compiler > genmodel > GenExceptionModel


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.genmodel;
19
20 import org.apache.beehive.netui.compiler.model.ExceptionModel;
21 import org.apache.beehive.netui.compiler.model.ForwardContainer;
22 import org.apache.beehive.netui.compiler.model.ExceptionContainer;
23 import org.apache.beehive.netui.compiler.JpfLanguageConstants;
24 import org.apache.beehive.netui.compiler.CompilerUtils;
25 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationInstance;
26 import org.apache.beehive.netui.compiler.typesystem.declaration.MethodDeclaration;
27 import org.apache.beehive.netui.compiler.typesystem.declaration.ClassDeclaration;
28
29 import java.util.List JavaDoc;
30 import java.util.Collection JavaDoc;
31 import java.util.Iterator JavaDoc;
32
33
34 public class GenExceptionModel
35         extends ExceptionModel
36         implements JpfLanguageConstants
37 {
38     public GenExceptionModel( GenStrutsApp parentApp, AnnotationInstance annotation, ClassDeclaration jclass,
39                               ForwardContainer forwardContainer )
40     {
41         super( parentApp );
42         
43         setType( CompilerUtils.getLoadableName( CompilerUtils.getDeclaredType( annotation, TYPE_ATTR, true ) ) );
44         setPath( CompilerUtils.getString( annotation, PATH_ATTR, true ) );
45         setMessage( CompilerUtils.getString( annotation, MESSAGE_ATTR, true ) );
46         setMessageKey( CompilerUtils.getString( annotation, MESSAGE_KEY_ATTR, true ) );
47         String JavaDoc methodName = CompilerUtils.getString( annotation, METHOD_ATTR, true );
48         setHandlerMethod( methodName );
49         
50             
51         //
52
// Now get the forwards (@Jpf.Forward) from the handler method, and add them as global or local
53
// forwards, as appropriate.
54
//
55
if ( methodName != null )
56         {
57             MethodDeclaration method = CompilerUtils.getClassMethod( jclass, methodName, EXCEPTION_HANDLER_TAG_NAME );
58             AnnotationInstance exHandlerAnnotation = CompilerUtils.getAnnotation( method, EXCEPTION_HANDLER_TAG_NAME );
59             GenForwardModel.addForwards( exHandlerAnnotation, forwardContainer, jclass, parentApp,
60                                          " from exception-handler " + methodName ); // @TODO I18N the comment
61

62             //
63
// Also, if the exception-handler was marked "read-only", note this on the tag.
64
//
65
Boolean JavaDoc readOnly = CompilerUtils.getBoolean( exHandlerAnnotation, READONLY_ATTR, true );
66             if ( readOnly == null )
67             {
68                 readOnly = Boolean.valueOf( parentApp.getFlowControllerInfo().getMergedControllerAnnotation().isReadOnly() );
69             }
70             setReadonly( readOnly.booleanValue() );
71         }
72     }
73     
74     static void addCatches( AnnotationInstance annotation, ExceptionContainer container, ClassDeclaration jclass,
75                             GenStrutsApp strutsApp, ForwardContainer forwardContainer )
76     {
77         List JavaDoc catches = CompilerUtils.getAnnotationArray( annotation, CATCHES_ATTR, true );
78         addCatches( catches, container, jclass, strutsApp, forwardContainer );
79     }
80     static void addCatches( Collection JavaDoc catches, ExceptionContainer container,
81                             ClassDeclaration jclass, GenStrutsApp strutsApp, ForwardContainer forwardContainer )
82     {
83         if ( catches != null )
84         {
85             for ( Iterator JavaDoc ii = catches.iterator(); ii.hasNext(); )
86             {
87                 AnnotationInstance i = ( AnnotationInstance ) ii.next();
88                 container.addException( new GenExceptionModel( strutsApp, i, jclass, forwardContainer ) );
89             }
90         }
91     }
92 }
93
Popular Tags