MustacheNodesToYAML.jrag 7.48 KB
Newer Older
René Schöne's avatar
René Schöne committed
1
2
3
4
5
aspect MustacheNodesToYAML {
  syn Document MRagConnect.toYAML() {
    Document doc = new Document();
    MappingElement root = new MappingElement();
    root.addKeyValuePair("rootNodeName", StringElement.of(rootNodeName()));
René Schöne's avatar
René Schöne committed
6
    root.addKeyValuePair("closeMethod", StringElement.of(closeMethod()));
René Schöne's avatar
René Schöne committed
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
    root.addKeyValuePair("usesMqtt", ValueElement.of(usesMqtt));
    root.addKeyValuePair("usesRest", ValueElement.of(usesRest));
    // mqtt
    root.addKeyValuePair("mqttHandlerField", StringElement.of(mqttHandlerField()));
    root.addKeyValuePair("mqttHandlerAttribute", StringElement.of(mqttHandlerAttribute()));
    root.addKeyValuePair("mqttSetupWaitUntilReadyMethod", StringElement.of(mqttSetupWaitUntilReadyMethod()));

    // rootTypeComponents
    ListElement rootTypeComponents = new ListElement();
    for (MTypeComponent comp : getRootTypeComponentList()) {
      MappingElement inner = new MappingElement();
      inner.addKeyValuePair("first", ValueElement.of(comp.isFirst()));
      inner.addKeyValuePair("name", StringElement.of(comp.name()));
      rootTypeComponents.addElement(inner);
    }
René Schöne's avatar
René Schöne committed
22
    root.addKeyValuePair("RootTypeComponents", rootTypeComponents);
René Schöne's avatar
René Schöne committed
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66

    // rest
    root.addKeyValuePair("restHandlerField", StringElement.of(restHandlerField()));
    root.addKeyValuePair("restHandlerAttribute", StringElement.of(restHandlerAttribute()));

    // ReceiveDefinitions
    ListElement receiveDefinitions = new ListElement();
    for (MReceiveDefinition def : getReceiveDefinitionList()) {
      receiveDefinitions.addElement(def.toYAML());
    }
    root.addKeyValuePair("ReceiveDefinitions", receiveDefinitions);

    // SendDefinitions
    ListElement sendDefinitions = new ListElement();
    for (MSendDefinition def : getSendDefinitionList()) {
      sendDefinitions.addElement(def.toYAML());
    }
    root.addKeyValuePair("SendDefinitions", sendDefinitions);

    // MappingDefinitions
    ListElement mappingDefinitions = new ListElement();
    for (MMappingDefinition def : getMappingDefinitionList()) {
      mappingDefinitions.addElement(def.toYAML());
    }
    root.addKeyValuePair("MappingDefinitions", mappingDefinitions);

    // DependencyDefinitions
    ListElement dependencyDefinitions = new ListElement();
    for (MDependencyDefinition def : getDependencyDefinitionList()) {
      dependencyDefinitions.addElement(def.toYAML());
    }
    root.addKeyValuePair("DependencyDefinitions", dependencyDefinitions);

    // TokenComponents
    ListElement tokenComponents = new ListElement();
    for (MTokenComponent comp : getTokenComponentList()) {
      tokenComponents.addElement(comp.toYAML());
    }
    root.addKeyValuePair("TokenComponents", tokenComponents);

    doc.addComplexElement(root);
    return doc;
  }

René Schöne's avatar
René Schöne committed
67
68
69
70
71
72
73
74
75
76
77
78
  syn MappingElement MEndpointDefinition.toYAML() {
    MappingElement result = new MappingElement();
    result.addKeyValuePair("parentTypeName", StringElement.of(parentTypeName()));
    result.addKeyValuePair("connectMethod", StringElement.of(connectMethod()));
    result.addKeyValuePair("connectParameterName", StringElement.of(connectParameterName()));
    result.addKeyValuePair("lastDefinitionToType", StringElement.of(lastDefinitionToType()));
    result.addKeyValuePair("preemptiveReturn", StringElement.of(preemptiveReturn()));
    result.addKeyValuePair("alwaysApply", ValueElement.of(alwaysApply()));
    result.addKeyValuePair("condition", StringElement.of(
    condition().replace("\"", "\\\"").replace("\n", "\\n")));
    result.addKeyValuePair("lastResult", StringElement.of(lastResult()));
    result.addKeyValuePair("tokenName", StringElement.of(tokenName()));
René Schöne's avatar
René Schöne committed
79
    result.addKeyValuePair("InnerMappingDefinitions", innerMappingDefinitionsAsListElement());
René Schöne's avatar
René Schöne committed
80
    return result;
René Schöne's avatar
René Schöne committed
81
82
  }

René Schöne's avatar
René Schöne committed
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
  syn MappingElement MReceiveDefinition.toYAML() {
    MappingElement result = super.toYAML();
    result.addKeyValuePair("loggingEnabledForReads", ValueElement.of(loggingEnabledForReads));
    return result;
  }

  syn MappingElement MSendDefinition.toYAML() {
    MappingElement result = super.toYAML();
    result.addKeyValuePair("sender", StringElement.of(sender()));
    result.addKeyValuePair("lastValue", StringElement.of(lastValue()));
    result.addKeyValuePair("loggingEnabledForWrites", ValueElement.of(loggingEnabledForWrites));
    result.addKeyValuePair("updateMethod", StringElement.of(updateMethod()));
    result.addKeyValuePair("writeMethod", StringElement.of(writeMethod()));
    result.addKeyValuePair("tokenResetMethod", StringElement.of(tokenResetMethod()));
    return result;
René Schöne's avatar
René Schöne committed
98
99
100
  }

  syn Element MMappingDefinition.toYAML() {
René Schöne's avatar
René Schöne committed
101
102
103
104
105
106
107
108
    MappingElement result = new MappingElement();
    result.addKeyValuePair("toType", StringElement.of(toType()));
    result.addKeyValuePair("methodName", StringElement.of(methodName()));
    result.addKeyValuePair("fromType", StringElement.of(fromType()));
    result.addKeyValuePair("fromVariableName", StringElement.of(fromVariableName()));
    result.addKeyValuePair("content", StringElement.of(
        content().replace("\"", "\\\"").replace("\n", "\\n")));
    return result;
René Schöne's avatar
René Schöne committed
109
110
111
  }

  syn Element MDependencyDefinition.toYAML() {
René Schöne's avatar
René Schöne committed
112
113
114
115
116
117
    MappingElement result = new MappingElement();
    result.addKeyValuePair("targetParentTypeName", StringElement.of(targetParentTypeName()));
    result.addKeyValuePair("dependencyMethod", StringElement.of(dependencyMethod()));
    result.addKeyValuePair("sourceParentTypeName", StringElement.of(sourceParentTypeName()));
    result.addKeyValuePair("internalRelationPrefix", StringElement.of(internalRelationPrefix()));
    return result;
René Schöne's avatar
René Schöne committed
118
119
120
  }

  syn Element MTokenComponent.toYAML() {
René Schöne's avatar
René Schöne committed
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
    MappingElement result = new MappingElement();
    result.addKeyValuePair("parentTypeName", StringElement.of(parentTypeName()));
    result.addKeyValuePair("name", StringElement.of(name()));
    result.addKeyValuePair("javaType", StringElement.of(javaType()));
    result.addKeyValuePair("internalName", StringElement.of(internalName()));
    ListElement dependencyDefinitions = new ListElement();
    for (MDependencyDefinition def : getDependencyDefinitionList()) {
      MappingElement inner = new MappingElement();
      inner.addKeyValuePair("targetParentTypeName", StringElement.of(def.targetParentTypeName()));
      inner.addKeyValuePair("internalRelationPrefix", StringElement.of(def.internalRelationPrefix()));
      MappingElement targetEndpointDefinition = new MappingElement();
    targetEndpointDefinition.addKeyValuePair("updateMethod", StringElement.of(def.targetEndpointDefinition().updateMethod()));
    targetEndpointDefinition.addKeyValuePair("writeMethod", StringElement.of(def.targetEndpointDefinition().writeMethod()));
      inner.addKeyValuePair("targetEndpointDefinition", targetEndpointDefinition);
      dependencyDefinitions.addElement(inner);
    }
    result.addKeyValuePair("DependencyDefinitions", dependencyDefinitions);
    return result;
  }

  ListElement MEndpointDefinition.innerMappingDefinitionsAsListElement() {
    ListElement innerMappingDefinitions = new ListElement();
    for (MInnerMappingDefinition def : getInnerMappingDefinitionList()) {
      MappingElement inner = new MappingElement();
      inner.addKeyValuePair("toType", StringElement.of(def.toType()));
      inner.addKeyValuePair("methodName", StringElement.of(def.methodName()));
      inner.addKeyValuePair("inputVarName", StringElement.of(def.inputVarName()));
René Schöne's avatar
René Schöne committed
148
      inner.addKeyValuePair("outputVarName", StringElement.of(def.outputVarName()));
René Schöne's avatar
René Schöne committed
149
150
151
152
      inner.addKeyValuePair("last", ValueElement.of(def.isLast()));
      innerMappingDefinitions.addElement(inner);
    }
    return innerMappingDefinitions;
René Schöne's avatar
René Schöne committed
153
154
155
  }

}