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.genmodel;
020:
021: import org.apache.beehive.netui.compiler.model.ExceptionModel;
022: import org.apache.beehive.netui.compiler.model.ForwardContainer;
023: import org.apache.beehive.netui.compiler.model.ExceptionContainer;
024: import org.apache.beehive.netui.compiler.JpfLanguageConstants;
025: import org.apache.beehive.netui.compiler.CompilerUtils;
026: import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationInstance;
027: import org.apache.beehive.netui.compiler.typesystem.declaration.MethodDeclaration;
028: import org.apache.beehive.netui.compiler.typesystem.declaration.ClassDeclaration;
029: import org.apache.beehive.netui.compiler.typesystem.declaration.TypeDeclaration;
030:
031: import java.util.Collection;
032: import java.util.Iterator;
033:
034: public class GenExceptionModel extends ExceptionModel implements
035: JpfLanguageConstants {
036: public GenExceptionModel(GenStrutsApp parentApp,
037: AnnotationInstance annotation, ClassDeclaration jclass,
038: ForwardContainer forwardContainer) {
039: super (parentApp);
040:
041: setType(CompilerUtils.getLoadableName(CompilerUtils
042: .getDeclaredType(annotation, TYPE_ATTR, true)));
043: setMessage(CompilerUtils.getString(annotation, MESSAGE_ATTR,
044: true));
045: setMessageKey(CompilerUtils.getString(annotation,
046: MESSAGE_KEY_ATTR, true));
047: String path = CompilerUtils.getString(annotation, PATH_ATTR,
048: true);
049: String methodName = CompilerUtils.getString(annotation,
050: METHOD_ATTR, true);
051:
052: //
053: // Now get the forwards (@Jpf.Forward) from the handler method, and add them as global or local
054: // forwards, as appropriate.
055: //
056: if (methodName != null) {
057: setHandlerMethod(methodName);
058: MethodDeclaration method = CompilerUtils.getClassMethod(
059: jclass, methodName, EXCEPTION_HANDLER_TAG_NAME);
060: AnnotationInstance exHandlerAnnotation = CompilerUtils
061: .getAnnotation(method, EXCEPTION_HANDLER_TAG_NAME);
062: GenForwardModel.addForwards(exHandlerAnnotation,
063: forwardContainer, jclass, parentApp,
064: " from exception-handler " + methodName); // @TODO I18N the comment
065:
066: //
067: // Also, if the exception-handler was marked "read-only", note this on the tag.
068: //
069: Boolean readOnly = CompilerUtils.getBoolean(
070: exHandlerAnnotation, READONLY_ATTR, true);
071: if (readOnly == null) {
072: readOnly = parentApp.getFlowControllerInfo()
073: .getMergedControllerAnnotation().isReadOnly();
074: }
075: setReadonly(readOnly != null && readOnly.booleanValue());
076: } else {
077: assert path != null;
078: setPath(path);
079: }
080: }
081:
082: static void addCatches(Collection catches,
083: ExceptionContainer container, ClassDeclaration jclass,
084: GenStrutsApp strutsApp, ForwardContainer forwardContainer) {
085: if (catches != null) {
086: for (Iterator i = catches.iterator(); i.hasNext();) {
087: AnnotationInstance ann = (AnnotationInstance) i.next();
088: TypeDeclaration containingType = ann
089: .getContainingType();
090:
091: // If this is an inherited exception-catch, add a delegating exception config.
092: if (CompilerUtils.typesAreEqual(containingType, jclass)) {
093: container.addException(new GenExceptionModel(
094: strutsApp, ann, jclass, forwardContainer));
095: } else {
096: container
097: .addException(new DelegatingExceptionModel(
098: container, strutsApp, ann,
099: containingType));
100: }
101: }
102: }
103: }
104: }
|