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.grammar;
20:
21: import org.apache.beehive.netui.compiler.RuntimeVersionChecker;
22: import org.apache.beehive.netui.compiler.Diagnostics;
23: import org.apache.beehive.netui.compiler.CompilerUtils;
24: import org.apache.beehive.netui.compiler.FlowControllerInfo;
25: import org.apache.beehive.netui.compiler.typesystem.env.CoreAnnotationProcessorEnv;
26: import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationInstance;
27: import org.apache.beehive.netui.compiler.typesystem.declaration.MemberDeclaration;
28:
29: import java.util.Map;
30: import java.util.List;
31: import java.util.Iterator;
32:
33: public class MessageBundleGrammar extends BaseFlowControllerGrammar {
34: private static final String[][] REQUIRED_ATTRS = { { BUNDLE_PATH_ATTR } };
35:
36: public MessageBundleGrammar(CoreAnnotationProcessorEnv env,
37: Diagnostics diags, String requiredRuntimeVersion,
38: RuntimeVersionChecker runtimeVersionChecker,
39: FlowControllerInfo fcInfo) {
40: super (env, diags, requiredRuntimeVersion,
41: runtimeVersionChecker, fcInfo);
42:
43: addMemberType(BUNDLE_PATH_ATTR, new UniqueValueType(
44: MESSAGE_BUNDLES_ATTR, false, false, null, this ));
45: addMemberType(BUNDLE_NAME_ATTR, new UniqueValueType(
46: MESSAGE_BUNDLES_ATTR, true, true, null, this ));
47: }
48:
49: public String[][] getRequiredAttrs() {
50: return REQUIRED_ATTRS;
51: }
52:
53: protected Object onEndCheck(AnnotationInstance annotation,
54: AnnotationInstance[] parentAnnotations,
55: MemberDeclaration classMember, Map checkResults) {
56: String bundlePath = CompilerUtils.getString(annotation,
57: BUNDLE_PATH_ATTR, false);
58: String bundleName = CompilerUtils.getString(annotation,
59: BUNDLE_NAME_ATTR, false);
60:
61: if (bundleName.length() == 0) {
62: AnnotationInstance immediateParent = parentAnnotations[parentAnnotations.length - 1];
63: List peerAnnotations = CompilerUtils.getAnnotationArray(
64: immediateParent, MESSAGE_BUNDLES_ATTR, false);
65:
66: for (Iterator ii = peerAnnotations.iterator(); ii.hasNext();) {
67: AnnotationInstance peerAnnotation = (AnnotationInstance) ii
68: .next();
69: if (!CompilerUtils.annotationsAreEqual(annotation,
70: peerAnnotation, false, getEnv())
71: && CompilerUtils.getString(peerAnnotation,
72: BUNDLE_NAME_ATTR, false).length() == 0) {
73: addError(annotation,
74: "error.multiple-default-message-resources",
75: BUNDLE_NAME_ATTR);
76: }
77: }
78: }
79:
80: getFlowControllerInfo()
81: .addMessageBundle(bundleName, bundlePath);
82:
83: return null;
84: }
85: }
|