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;
020:
021: import org.apache.beehive.netui.compiler.genmodel.GenSharedFlowStrutsApp;
022: import org.apache.beehive.netui.compiler.genmodel.GenStrutsApp;
023: import org.apache.beehive.netui.compiler.grammar.ControllerGrammar;
024: import org.apache.beehive.netui.compiler.grammar.InvalidAttributeType;
025: import org.apache.beehive.netui.compiler.typesystem.declaration.ClassDeclaration;
026: import org.apache.beehive.netui.compiler.typesystem.env.CoreAnnotationProcessorEnv;
027:
028: import java.io.File;
029: import java.io.IOException;
030:
031: public class SharedFlowChecker extends FlowControllerChecker {
032: public SharedFlowChecker(CoreAnnotationProcessorEnv env,
033: FlowControllerInfo fcInfo, Diagnostics diagnostics) {
034: super (env, fcInfo, diagnostics);
035: }
036:
037: protected void doAdditionalClassChecks(ClassDeclaration jclass) {
038: // Make sure there are no other shared flows in this package/directory.
039: checkForOverlappingClasses(jclass, SHARED_FLOW_BASE_CLASS,
040: SHARED_FLOW_FILE_EXTENSION_DOT,
041: "error.overlapping-sharedflows");
042:
043: String pkg = jclass.getPackage().getQualifiedName();
044:
045: //
046: // If it's Global.app, make sure the package is "global".
047: //
048: if (CompilerUtils.isAssignableFrom(GLOBALAPP_BASE_CLASS,
049: jclass, getEnv())) {
050: if (!pkg.equals(GLOBALAPP_PACKAGE)) {
051: getDiagnostics().addError(jclass,
052: "error.wrong-package", GLOBALAPP_PACKAGE);
053: }
054:
055: if (!jclass.getPosition().file().getParentFile().getName()
056: .endsWith(GLOBALAPP_PACKAGE)) {
057: getDiagnostics().addError(jclass,
058: "error.global-app-wrong-dir",
059: GLOBALAPP_SOURCE_NAME, GLOBALAPP_PARENT_PATH);
060: }
061: }
062: }
063:
064: protected String getDesiredBaseClass(ClassDeclaration jclass) {
065: File sourceFile = CompilerUtils.getSourceFile(jclass, true);
066: if (sourceFile.getName().endsWith(GLOBALAPP_FILE_EXTENSION_DOT))
067: return GLOBALAPP_BASE_CLASS;
068: if (sourceFile.getName().endsWith(
069: SHARED_FLOW_FILE_EXTENSION_DOT))
070: return SHARED_FLOW_BASE_CLASS;
071: return null;
072: }
073:
074: protected GenStrutsApp createStrutsApp(ClassDeclaration jclass)
075: throws IOException, FatalCompileTimeException {
076: File sourceFile = CompilerUtils.getSourceFile(jclass, true);
077: return new GenSharedFlowStrutsApp(sourceFile, jclass, getEnv(),
078: getFCSourceFileInfo(), true, getDiagnostics());
079: }
080:
081: protected AnnotationGrammar getControllerGrammar() {
082: return new SharedFlowControllerGrammar();
083: }
084:
085: private class SharedFlowControllerGrammar extends ControllerGrammar {
086: public SharedFlowControllerGrammar() {
087: super (SharedFlowChecker.this .getEnv(),
088: SharedFlowChecker.this .getDiagnostics(),
089: SharedFlowChecker.this .getRuntimeVersionChecker(),
090: SharedFlowChecker.this .getFCSourceFileInfo());
091: InvalidAttributeType type = new InvalidAttributeType(null,
092: this , "error.only-valid-on-pageflow", new Object[] {
093: NESTED_ATTR, JPF_BASE_CLASS });
094: addMemberType(NESTED_ATTR, type);
095: type = new InvalidAttributeType(null, this ,
096: "error.only-valid-on-pageflow", new Object[] {
097: LONGLIVED_ATTR, JPF_BASE_CLASS });
098: addMemberType(LONGLIVED_ATTR, type);
099: }
100: }
101: }
|