001: /*
002: * Copyright 2006 Luca Garulli (luca.garulli@assetdata.it)
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of 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,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.romaframework.aspect.persistence;
018:
019: import java.lang.annotation.Annotation;
020:
021: import org.romaframework.aspect.persistence.annotation.Persistence;
022: import org.romaframework.aspect.persistence.feature.PersistenceFeatures;
023: import org.romaframework.core.aspect.SelfRegistrantConfigurableAspect;
024: import org.romaframework.core.schema.SchemaElement;
025: import org.romaframework.core.schema.SchemaEvent;
026: import org.romaframework.core.schema.SchemaField;
027: import org.romaframework.core.util.DynaBean;
028: import org.romaframework.xml.config.XmlConfigActionType;
029: import org.romaframework.xml.config.XmlConfigAspectTypePersistence;
030: import org.romaframework.xml.config.XmlConfigFieldType;
031:
032: /**
033: * Persistence aspect. Manage application objects in datastore.
034: *
035: * @author Luca Garulli (luca.garulli@assetdata.it)
036: */
037: public abstract class PersistenceAspectAbstract extends
038: SelfRegistrantConfigurableAspect<String> implements
039: PersistenceAspect {
040:
041: @Override
042: public void configField(SchemaField iField, Annotation iAnnotation,
043: Annotation iGenericAnnotation, Annotation getterAnnotation,
044: XmlConfigFieldType iXmlNode) {
045: configCommonAnnotations(iField, iAnnotation, iGenericAnnotation);
046: readFieldXml(iField, iXmlNode);
047: }
048:
049: @Override
050: public void configAction(SchemaElement iAction,
051: Annotation iActionAnnotation,
052: Annotation iGenericAnnotation, XmlConfigActionType iXmlNode) {
053: configCommonAnnotations(iAction, iActionAnnotation,
054: iGenericAnnotation);
055: readActionXml(iAction, iXmlNode);
056: }
057:
058: private void configCommonAnnotations(SchemaElement iElement,
059: Annotation iAnnotation, Annotation iGenericAnnotation) {
060: DynaBean features = iElement.getFeatures(ASPECT_NAME);
061: if (features == null) {
062: // CREATE EMPTY FEATURES
063: features = new PersistenceFeatures();
064: iElement.setFeatures(ASPECT_NAME, features);
065: }
066:
067: readAnnotation(iElement, iGenericAnnotation, features);
068: readAnnotation(iElement, iAnnotation, features);
069: }
070:
071: private void readAnnotation(SchemaElement iElement,
072: Annotation iAnnotation, DynaBean features) {
073: Persistence annotation = (Persistence) iAnnotation;
074:
075: if (annotation != null) {
076: // PROCESS ANNOTATIONS
077: // ANNOTATION ATTRIBUTES (IF DEFINED) OVERWRITE DEFAULT VALUES
078: if (annotation != null) {
079: if (!annotation.mode().equals(
080: PersistenceConstants.MODE_NOTHING))
081: features.setAttribute(PersistenceFeatures.MODE,
082: annotation.mode());
083: }
084: }
085: }
086:
087: private void readFieldXml(SchemaElement iElement,
088: XmlConfigFieldType iXmlNode) {
089: // PROCESS DESCRIPTOR CFG DESCRIPTOR ATTRIBUTES (IF DEFINED) OVERWRITE DEFAULT AND ANNOTATION VALUES
090: if (iXmlNode == null || iXmlNode.getAspects() == null)
091: return;
092:
093: DynaBean features = iElement.getFeatures(ASPECT_NAME);
094:
095: XmlConfigAspectTypePersistence descriptor = iXmlNode
096: .getAspects().getPersistence();
097:
098: if (descriptor != null) {
099: features.setAttribute(PersistenceFeatures.MODE, descriptor
100: .getMode());
101: }
102: }
103:
104: private void readActionXml(SchemaElement iElement,
105: XmlConfigActionType iXmlNode) {
106: // PROCESS DESCRIPTOR CFG DESCRIPTOR ATTRIBUTES (IF DEFINED) OVERWRITE DEFAULT AND ANNOTATION VALUES
107: if (iXmlNode == null || iXmlNode.getAspects() == null)
108: return;
109:
110: DynaBean features = iElement.getFeatures(ASPECT_NAME);
111:
112: XmlConfigAspectTypePersistence descriptor = iXmlNode
113: .getAspects().getPersistence();
114:
115: if (descriptor != null) {
116: features.setAttribute(PersistenceFeatures.MODE, descriptor
117: .getMode());
118: }
119: }
120:
121: @Override
122: public void configEvent(SchemaEvent iEvent,
123: Annotation iEventAnnotation, Annotation iGenericAnnotation,
124: XmlConfigActionType iXmlNode) {
125: configAction(iEvent, iEventAnnotation, iGenericAnnotation,
126: iXmlNode);
127: }
128:
129: public String aspectName() {
130: return ASPECT_NAME;
131: }
132: }
|