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.typesystem.declaration.ClassDeclaration;
22: import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationInstance;
23: import org.apache.beehive.netui.compiler.typesystem.declaration.MethodDeclaration;
24: import org.apache.beehive.netui.compiler.typesystem.env.CoreAnnotationProcessorEnv;
25:
26: public class FacesBackingGenerator extends BaseGenerator implements
27: JpfLanguageConstants {
28: public FacesBackingGenerator(CoreAnnotationProcessorEnv env,
29: SourceFileInfo sourceFileInfo, Diagnostics diagnostics) {
30: super (env, sourceFileInfo, diagnostics);
31: }
32:
33: public void generate(ClassDeclaration publicClass)
34: throws FatalCompileTimeException {
35: try {
36: AnnotationInstance facesBackingAnnotation = CompilerUtils
37: .getAnnotation(publicClass, FACES_BACKING_TAG_NAME);
38: assert facesBackingAnnotation != null; // checker should enforce this
39: AnnotationToXML atx = new AnnotationToXML(publicClass);
40:
41: // Add the class-level @Jpf.FacesBacking annotation.
42: atx.include(publicClass, facesBackingAnnotation);
43:
44: // For each method, add the @Jpf.CommandHandler annotation.
45: MethodDeclaration[] methods = CompilerUtils
46: .getClassMethods(publicClass,
47: COMMAND_HANDLER_TAG_NAME);
48: for (int i = 0; i < methods.length; i++) {
49: MethodDeclaration method = methods[i];
50: AnnotationInstance commandHandlerAnn = CompilerUtils
51: .getAnnotation(method, COMMAND_HANDLER_TAG_NAME);
52: atx.include(method, commandHandlerAnn);
53: }
54:
55: // Add @Jpf.SharedFlowField, @Jpf.PageFlowField, @Control.
56: FlowControllerGenerator.includeFieldAnnotations(atx,
57: publicClass, PAGE_FLOW_FIELD_TAG_NAME);
58:
59: // Write the file.
60: atx.writeXml(getDiagnostics(), getEnv());
61: } catch (Exception e) {
62: getDiagnostics().addError(publicClass,
63: "error.could-not-generate",
64: AnnotationToXML.getFilePath(publicClass),
65: e.getMessage());
66: e.printStackTrace(); // TODO: log instead
67: }
68: }
69: }
|