01: /*
02: * Copyright 2006 Luca Garulli (luca.garulli@assetdata.it)
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.romaframework.aspect.i18n;
18:
19: import java.lang.annotation.Annotation;
20:
21: import org.romaframework.aspect.core.annotation.AnnotationConstants;
22: import org.romaframework.aspect.i18n.annotation.I18nField;
23: import org.romaframework.aspect.i18n.feature.I18NFieldFeatures;
24: import org.romaframework.core.aspect.SelfRegistrantConfigurableAspect;
25: import org.romaframework.core.schema.SchemaField;
26: import org.romaframework.core.util.DynaBean;
27: import org.romaframework.xml.config.XmlConfigFieldType;
28:
29: /**
30: * I18N Aspect abstract implementation handle the aspect configuration. Extend this if you want to write your own Aspect
31: * implementation.
32: *
33: * @author Luca Garulli (luca.garulli@assetdata.it)
34: */
35: public abstract class I18NAspectAbstract extends
36: SelfRegistrantConfigurableAspect<String> implements I18NAspect {
37:
38: @Override
39: public void configField(SchemaField iField,
40: Annotation iFieldAnnotation, Annotation iGenericAnnotation,
41: Annotation iGetterAnnotation, XmlConfigFieldType iXmlNode) {
42: DynaBean features = iField.getFeatures(ASPECT_NAME);
43: if (features == null) {
44: // CREATE EMPTY FEATURES
45: features = new I18NFieldFeatures();
46: iField.setFeatures(ASPECT_NAME, features);
47: }
48:
49: readFieldAnnotation(iField, iFieldAnnotation, features);
50: readFieldAnnotation(iField, iGetterAnnotation, features);
51: }
52:
53: private void readFieldAnnotation(SchemaField iField,
54: Annotation iAnnotation, DynaBean features) {
55: I18nField annotation = (I18nField) iAnnotation;
56:
57: if (annotation != null) {
58: // PROCESS ANNOTATIONS
59: // ANNOTATION ATTRIBUTES (IF DEFINED) OVERWRITE DEFAULT VALUES
60: if (!annotation.key().equals(AnnotationConstants.DEF_VALUE))
61: features.setAttribute(I18NFieldFeatures.KEY, annotation
62: .key());
63: else
64: features.setAttribute(I18NFieldFeatures.KEY,
65: DEFAULT_VALUE_KEY);
66: }
67: }
68:
69: public String aspectName() {
70: return ASPECT_NAME;
71: }
72: }
|