001: /*
002: * Copyright 2006 Giordano Maestro (giordano.maestro@assetdata.it)
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License. You may obtain a copy of
006: * the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013: * License for the specific language governing permissions and limitations under
014: * the License.
015: */
016:
017: package org.romaframework.aspect.reporting;
018:
019: import java.lang.annotation.Annotation;
020:
021: import org.romaframework.aspect.core.CoreAspect;
022: import org.romaframework.aspect.core.annotation.AnnotationConstants;
023: import org.romaframework.aspect.core.feature.CoreFieldFeatures;
024: import org.romaframework.aspect.reporting.annotation.ReportingClass;
025: import org.romaframework.aspect.reporting.annotation.ReportingField;
026: import org.romaframework.aspect.reporting.feature.ReportingClassFeatures;
027: import org.romaframework.aspect.reporting.feature.ReportingFieldFeatures;
028: import org.romaframework.core.Utility;
029: import org.romaframework.core.aspect.SelfRegistrantConfigurableAspect;
030: import org.romaframework.core.config.RomaApplicationContext;
031: import org.romaframework.core.schema.SchemaClassDefinition;
032: import org.romaframework.core.schema.SchemaClassResolver;
033: import org.romaframework.core.schema.SchemaElement;
034: import org.romaframework.core.schema.SchemaEvent;
035: import org.romaframework.core.schema.SchemaField;
036: import org.romaframework.core.schema.SchemaManager;
037: import org.romaframework.core.util.DynaBean;
038: import org.romaframework.xml.config.XmlConfigActionType;
039: import org.romaframework.xml.config.XmlConfigAspectClassTypeReporting;
040: import org.romaframework.xml.config.XmlConfigAspectFieldTypeReporting;
041: import org.romaframework.xml.config.XmlConfigClassType;
042: import org.romaframework.xml.config.XmlConfigFieldType;
043:
044: /**
045: * The abstract class for the reporting aspect
046: *
047: * @author Luca Garulli (luca.garulli@assetdata.it)
048: */
049: public abstract class ReportingAspectAbstract extends
050: SelfRegistrantConfigurableAspect<String> implements
051: ReportingAspect {
052:
053: public static final String ASPECT_NAME = "reporting";
054:
055: public void startup() {
056: // REGISTER THE VIEW DOMAIN TO SCHEMA CLASS RESOLVER
057: RomaApplicationContext.getInstance().getBean(
058: SchemaClassResolver.class).addDomainPackage(
059: Utility.getApplicationAspectPackage(aspectName()));
060: RomaApplicationContext.getInstance().getBean(
061: SchemaClassResolver.class).addDomainPackage(
062: Utility.getRomaAspectPackage(aspectName()));
063: }
064:
065: protected abstract void refresh(SchemaClassDefinition updatedClass);
066:
067: @Override
068: public void configClass(SchemaClassDefinition iClass,
069: Annotation iAnnotation, XmlConfigClassType iXmlNode) {
070:
071: DynaBean features = iClass
072: .getFeatures(ReportingAspect.ASPECT_NAME);
073: if (features == null) {
074: // CREATE EMPTY FEATURES
075: features = new ReportingClassFeatures();
076: iClass.setFeatures(ReportingAspect.ASPECT_NAME, features);
077: }
078:
079: readClassAnnotation(iAnnotation, features);
080: readClassXml(iClass, iXmlNode);
081: refresh(iClass);
082: }
083:
084: @Override
085: public void configField(SchemaField iField,
086: Annotation iFieldAnnotation, Annotation iGenericAnnotation,
087: Annotation iGetterAnnotation, XmlConfigFieldType iXmlNode) {
088: DynaBean features = iField
089: .getFeatures(ReportingAspect.ASPECT_NAME);
090: if (features == null) {
091: // CREATE EMPTY FEATURES
092: features = new ReportingFieldFeatures();
093: iField.setFeatures(ReportingAspect.ASPECT_NAME, features);
094: }
095:
096: readFieldAnnotation(iFieldAnnotation, features);
097: readFieldAnnotation(iGetterAnnotation, features);
098: readFieldXml(iField, iXmlNode);
099: setFieldDefaults(iField);
100: }
101:
102: @Override
103: public void configAction(SchemaElement iAction,
104: Annotation iActionAnnotation,
105: Annotation iGenericAnnotation, XmlConfigActionType iNode) {
106: // Reporting caanot be used on actions
107: }
108:
109: public String aspectName() {
110: return ASPECT_NAME;
111: }
112:
113: private void readClassAnnotation(Annotation iAnnotation,
114: DynaBean features) {
115: ReportingClass annotation = (ReportingClass) iAnnotation;
116: if (annotation != null) {
117: // PROCESS ANNOTATIONS
118: if (!annotation.entity().equals(Object.class)) {
119: features.setAttribute(ReportingClassFeatures.ENTITY,
120: annotation.entity());
121: }
122: if (!annotation.render().equals(
123: AnnotationConstants.DEF_VALUE)) {
124: features.setAttribute(ReportingClassFeatures.RENDER,
125: annotation.render());
126: }
127: if (!annotation.layout().equals(
128: AnnotationConstants.DEF_VALUE)) {
129: features.setAttribute(ReportingClassFeatures.LAYOUT,
130: annotation.layout());
131: }
132: if (annotation.explicitElements() != AnnotationConstants.UNSETTED) {
133: features.setAttribute(
134: ReportingClassFeatures.EXPLICIT_ELEMENTS,
135: annotation.explicitElements());
136: }
137: if (!annotation.label().equals(
138: AnnotationConstants.DEF_VALUE)) {
139: features.setAttribute(ReportingClassFeatures.LABEL,
140: annotation.label());
141: }
142:
143: if (annotation.inheritViewConfiguration() != AnnotationConstants.UNSETTED) {
144: features
145: .setAttribute(
146: ReportingClassFeatures.INHERIT_VIEW_CONFIGURATION,
147: Boolean.FALSE);
148: }
149:
150: if (!annotation.documentType().equals(
151: AnnotationConstants.DEF_VALUE)) {
152: features.setAttribute(
153: ReportingClassFeatures.DOCUMENT_TYPE,
154: annotation.documentType());
155: }
156:
157: }
158: }
159:
160: private void readClassXml(SchemaClassDefinition iClass,
161: XmlConfigClassType iXmlNode) {
162: if (iXmlNode == null || iXmlNode.getAspects() == null)
163: return;
164:
165: DynaBean features = iClass
166: .getFeatures(ReportingAspect.ASPECT_NAME);
167:
168: XmlConfigAspectClassTypeReporting featureDescriptor = null;
169:
170: if (iXmlNode.getAspects() != null) {
171: featureDescriptor = iXmlNode.getAspects().getReporting();
172: }
173: if (featureDescriptor != null) {
174:
175: // PROCESS DESCRIPTOR CFG
176: if (featureDescriptor != null) {
177:
178: if (featureDescriptor.isSetLabel()) {
179: features.setAttribute(ReportingClassFeatures.LABEL,
180: featureDescriptor.getLabel());
181: }
182: if (featureDescriptor.isSetEntity()) {
183: features.setAttribute(
184: ReportingClassFeatures.ENTITY,
185: RomaApplicationContext.getInstance()
186: .getBean(SchemaManager.class)
187: .getClassInfo(
188: featureDescriptor
189: .getEntity())
190: .getClazz());
191: }
192: if (featureDescriptor.isSetRender()) {
193: features.setAttribute(
194: ReportingClassFeatures.RENDER,
195: featureDescriptor.getRender());
196: }
197: if (featureDescriptor.isSetLayout()) {
198: features.setAttribute(
199: ReportingClassFeatures.LAYOUT,
200: featureDescriptor.getLayout());
201: }
202: if (featureDescriptor.isSetExplicitElements()) {
203: features.setAttribute(
204: ReportingClassFeatures.EXPLICIT_ELEMENTS,
205: featureDescriptor.getExplicitElements());
206: }
207:
208: if (featureDescriptor.isSetInheritViewConfiguration()) {
209: features
210: .setAttribute(
211: ReportingClassFeatures.INHERIT_VIEW_CONFIGURATION,
212: featureDescriptor
213: .getInheritViewConfiguration());
214: }
215:
216: if (featureDescriptor.isSetDocumentType()) {
217: features.setAttribute(
218: ReportingClassFeatures.DOCUMENT_TYPE,
219: featureDescriptor.getDocumentType());
220: }
221:
222: }
223: }
224: }
225:
226: private void readFieldAnnotation(Annotation iAnnotation,
227: DynaBean iFeatures) {
228: ReportingField annotation = (ReportingField) iAnnotation;
229:
230: if (annotation != null) {
231: if (!annotation.label().equals(
232: AnnotationConstants.DEF_VALUE)) {
233: iFeatures.setAttribute(ReportingFieldFeatures.LABEL,
234: annotation.label());
235: }
236:
237: if (annotation.visible() != AnnotationConstants.UNSETTED) {
238: iFeatures
239: .setAttribute(
240: ReportingFieldFeatures.VISIBLE,
241: annotation.visible() == AnnotationConstants.TRUE);
242: }
243:
244: if (!annotation.render().equals(
245: AnnotationConstants.DEF_VALUE)) {
246: iFeatures.setAttribute(ReportingFieldFeatures.RENDER,
247: annotation.render());
248: }
249: if (!annotation.layout().equals(
250: AnnotationConstants.DEF_VALUE)) {
251: iFeatures.setAttribute(ReportingFieldFeatures.LAYOUT,
252: annotation.layout());
253: }
254: }
255: }
256:
257: private void readFieldXml(SchemaField iField,
258: XmlConfigFieldType iXmlNode) {
259: // PROCESS DESCRIPTOR CFG
260: // DESCRIPTOR ATTRIBUTES (IF DEFINED) OVERWRITE DEFAULT AND ANNOTATION
261: // VALUES
262: if (iXmlNode == null)
263: return;
264:
265: DynaBean features = iField.getFeatures(ASPECT_NAME);
266:
267: // FIELD FOUND IN DESCRIPTOR: ASSUME ITS VISIBILITY
268: // features.setAttribute(ReportingFieldFeatures.VISIBLE, true);
269:
270: if (iXmlNode.getAspects() == null)
271: return;
272:
273: XmlConfigAspectFieldTypeReporting descriptor = iXmlNode
274: .getAspects().getReporting();
275:
276: if (descriptor != null) {
277:
278: XmlConfigAspectFieldTypeReporting featureDescriptor = descriptor;
279:
280: if (featureDescriptor.isSetLabel()) {
281: features.setAttribute(ReportingFieldFeatures.LABEL,
282: featureDescriptor.getLabel());
283: }
284:
285: if (featureDescriptor.isSetVisible()) {
286: features.setAttribute(ReportingFieldFeatures.VISIBLE,
287: featureDescriptor.getVisible());
288: }
289:
290: if (featureDescriptor.isSetRender()) {
291: features.setAttribute(ReportingFieldFeatures.RENDER,
292: featureDescriptor.getRender());
293: }
294: if (featureDescriptor.isSetLayout()) {
295: features.setAttribute(ReportingFieldFeatures.LAYOUT,
296: featureDescriptor.getLayout());
297: }
298: }
299:
300: }
301:
302: public void setFieldDefaults(SchemaField iField) {
303: if ((Boolean) iField.getFeature(CoreAspect.ASPECT_NAME,
304: CoreFieldFeatures.EMBEDDED)) {
305: if (iField.getFeature(ASPECT_NAME,
306: ReportingFieldFeatures.RENDER) == null)
307: // IF THE FIELD IS EMBEDDED, THEN THE DEFAULT RENDER IS OBJECTEMBEDDED
308: iField.setFeature(ASPECT_NAME,
309: ReportingFieldFeatures.RENDER,
310: ReportingConstants.RENDER_OBJECTEMBEDDED);
311: }
312: }
313:
314: public void configEvent(SchemaEvent iEvent, Annotation iAnnotation,
315: XmlConfigActionType iNode) {
316: // TODO Auto-generated method stub
317:
318: }
319: }
|