001: package org.romaframework.module.designer.serializer.xml;
002:
003: import java.util.Map;
004: import java.util.Map.Entry;
005:
006: import org.apache.xmlbeans.XmlObject;
007: import org.romaframework.aspect.flow.FlowAspect;
008: import org.romaframework.aspect.flow.annotation.FlowAction;
009: import org.romaframework.aspect.monitoring.MonitoringAspect;
010: import org.romaframework.aspect.monitoring.annotation.MonitoringAction;
011: import org.romaframework.aspect.persistence.PersistenceAspect;
012: import org.romaframework.aspect.view.ViewAspect;
013: import org.romaframework.aspect.view.annotation.ViewAction;
014: import org.romaframework.core.schema.SchemaElement;
015: import org.romaframework.core.serializer.RomaObjectSerializer;
016: import org.romaframework.core.serializer.RomaSerializationException;
017: import org.romaframework.xml.config.XmlConfigActionType;
018: import org.romaframework.xml.config.XmlConfigAspectActionTypeFlow;
019: import org.romaframework.xml.config.XmlConfigAspectActionTypeMonitoring;
020: import org.romaframework.xml.config.XmlConfigAspectActionTypeView;
021: import org.romaframework.xml.config.XmlConfigAspectTypePersistence;
022: import org.romaframework.xml.config.XmlConfigActionType.Aspects;
023:
024: public class SchemaActionSerializer extends AbstractSchemaSerializer {
025: protected final static SchemaActionSerializer instance = new SchemaActionSerializer();
026:
027: public static RomaObjectSerializer getInstace() {
028: return instance;
029: }
030:
031: @Override
032: public XmlObject serialize(Object iToSerialize,
033: Map<String, Object> options)
034: throws RomaSerializationException {
035: SchemaElement toSerialize = (SchemaElement) iToSerialize;
036: XmlConfigActionType action = XmlConfigActionType.Factory
037: .newInstance();
038: String actionName = toSerialize.getName();
039: action.setName(actionName);
040:
041: Aspects aspects = Aspects.Factory.newInstance();
042:
043: // Create flow aspect
044:
045: XmlConfigAspectActionTypeFlow flow = XmlConfigAspectActionTypeFlow.Factory
046: .newInstance();
047: createAspectXml(FlowAspect.ASPECT_NAME, toSerialize
048: .getFeatures(FlowAspect.ASPECT_NAME), flow);
049: if (isNotEndElement(flow)) {
050: aspects.addNewFlow().set(flow);
051: }
052: // TODO: Manage Module configuration: XmlConfigAspectElementTypeModule
053: // module
054: // XmlConfigAspectElementTypeModule module = aspects.addNewModule();
055:
056: // Create monitoring aspect
057:
058: XmlConfigAspectActionTypeMonitoring monitoring = XmlConfigAspectActionTypeMonitoring.Factory
059: .newInstance();
060: createAspectXml(MonitoringAspect.ASPECT_NAME, toSerialize
061: .getFeatures(MonitoringAspect.ASPECT_NAME), monitoring);
062: if (isNotEndElement(monitoring)) {
063: aspects.addNewMonitoring().set(monitoring);
064: }
065:
066: // Create persistence aspect
067:
068: XmlConfigAspectTypePersistence persistence = XmlConfigAspectTypePersistence.Factory
069: .newInstance();
070: createAspectXml(PersistenceAspect.ASPECT_NAME, toSerialize
071: .getFeatures(PersistenceAspect.ASPECT_NAME),
072: persistence);
073: if (isNotEndElement(persistence)) {
074: aspects.addNewPersistence().set(persistence);
075: }
076: // Create view aspect
077: String remappedName = (String) toSerialize.getFeatures(
078: ViewAspect.ASPECT_NAME).getAttribute("actionName");
079: if (remappedName != null && remappedName.equals(actionName)) {
080: toSerialize.getFeatures(ViewAspect.ASPECT_NAME)
081: .setAttribute("actionName", null);
082: }
083:
084: XmlConfigAspectActionTypeView view = XmlConfigAspectActionTypeView.Factory
085: .newInstance();
086: createAspectXml(ViewAspect.ASPECT_NAME, toSerialize
087: .getFeatures(ViewAspect.ASPECT_NAME), view);
088: if (isNotEndElement(view)) {
089: aspects.addNewView().set(view);
090: }
091: toSerialize.getFeatures(ViewAspect.ASPECT_NAME).setAttribute(
092: "actionName", remappedName);
093: if (isNotEndElement(aspects)) {
094: action.addNewAspects().set(aspects);
095: }
096: return action;
097: }
098:
099: @Override
100: protected Object getValueToSet(Entry<String, Object> entry,
101: XmlObject iToSet) {
102: if (entry.getKey().equals("next")) {
103: return ((Class) entry.getValue()).getSimpleName();
104: }
105: return super .getValueToSet(entry, iToSet);
106: }
107:
108: @Override
109: protected boolean isDefaultValue(String aspectName,
110: Entry<String, Object> entry) throws Exception {
111: Class annotation = null;
112: if (aspectName.equals(ViewAspect.ASPECT_NAME)) {
113: annotation = ViewAction.class;
114: } else if (aspectName.equals(MonitoringAspect.ASPECT_NAME)) {
115: annotation = MonitoringAction.class;
116: } else if (aspectName.equals(FlowAspect.ASPECT_NAME)) {
117: annotation = FlowAction.class;
118: }
119: if (annotation == null) {
120: return false;
121: }
122: Object defaultValue = getAnnotationDefaultValue(entry,
123: annotation);
124: if (entry.getValue().equals(defaultValue)) {
125: return true;
126: }
127: return false;
128: }
129: }
|