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;
20:
21: import org.apache.beehive.netui.compiler.grammar.CommandHandlerGrammar;
22: import org.apache.beehive.netui.compiler.typesystem.declaration.ClassDeclaration;
23: import org.apache.beehive.netui.compiler.typesystem.declaration.MethodDeclaration;
24: import org.apache.beehive.netui.compiler.typesystem.env.CoreAnnotationProcessorEnv;
25:
26: import java.util.HashMap;
27: import java.util.Map;
28:
29: public class FacesBackingChecker extends BaseChecker implements
30: JpfLanguageConstants {
31: public FacesBackingChecker(CoreAnnotationProcessorEnv env,
32: FacesBackingInfo fbInfo, Diagnostics diags) {
33: super (env, fbInfo, diags);
34: }
35:
36: public Map onCheck(ClassDeclaration jclass)
37: throws FatalCompileTimeException {
38: if (!CompilerUtils.isAssignableFrom(FACES_BACKING_BEAN_CLASS,
39: jclass, getEnv())) {
40: getDiagnostics().addError(jclass,
41: "error.does-not-extend-base",
42: FACES_BACKING_BEAN_CLASS);
43: return null;
44: }
45:
46: ClassDeclaration[] packageClasses = jclass.getPackage()
47: .getClasses();
48: ClassDeclaration jpfClass = null;
49:
50: for (int i = 0; i < packageClasses.length; i++) {
51: ClassDeclaration classDecl = packageClasses[i];
52: if (CompilerUtils.isPageFlowClass(classDecl, getEnv()))
53: jpfClass = classDecl;
54: }
55:
56: // Don't run these checks if there's no associated page flow controller (or if it's in error).
57: if (jpfClass != null) {
58: FlowControllerInfo fcInfo = new FlowControllerInfo(jpfClass);
59: fcInfo.startBuild(getEnv(), jpfClass);
60:
61: CommandHandlerGrammar chg = new CommandHandlerGrammar(
62: getEnv(), getDiagnostics(),
63: getRuntimeVersionChecker(), jpfClass, fcInfo);
64: MethodDeclaration[] methods = CompilerUtils
65: .getClassMethods(jclass, COMMAND_HANDLER_TAG_NAME);
66:
67: for (int i = 0; i < methods.length; i++) {
68: MethodDeclaration method = methods[i];
69: getFBSourceFileInfo().addCommandHandler(
70: method.getSimpleName());
71: chg.check(CompilerUtils.getAnnotation(method,
72: COMMAND_HANDLER_TAG_NAME), null, method);
73: }
74:
75: Map checkResultMap = new HashMap();
76: checkResultMap
77: .put(
78: JpfLanguageConstants.ExtraInfoKeys.facesBackingInfo,
79: getSourceFileInfo());
80: return checkResultMap;
81: }
82:
83: return null;
84: }
85:
86: protected FacesBackingInfo getFBSourceFileInfo() {
87: return (FacesBackingInfo) super.getSourceFileInfo();
88: }
89: }
|