1 /*******************************************************************************
2 * Copyright (c) 2013 Pascal Hirmer.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * and the Apache License 2.0 which both accompany this distribution,
6 * and are available at http://www.eclipse.org/legal/epl-v10.html
7 * and http://www.apache.org/licenses/LICENSE-2.0
10 * Pascal Hirmer - initial API and implementation
11 *******************************************************************************/
13 package org.eclipse.winery.topologymodeler.addons.topologycompleter.analyzer;
15 import java.util.ArrayList;
16 import java.util.List;
18 import org.eclipse.winery.model.tosca.TEntityTemplate;
19 import org.eclipse.winery.model.tosca.TNodeTemplate;
20 import org.eclipse.winery.model.tosca.TNodeType;
21 import org.eclipse.winery.model.tosca.TRelationshipTemplate;
22 import org.eclipse.winery.model.tosca.TRelationshipType;
23 import org.eclipse.winery.model.tosca.TRequirement;
24 import org.eclipse.winery.model.tosca.TRequirementType;
25 import org.eclipse.winery.model.tosca.TTopologyTemplate;
28 * This class contains several methods to analyze the content of a TOSCA {@link TTopologyTemplate} and to fill a data model
29 * with the analyzed information. This class serves the access to all types and templates of a topology.
31 public class TOSCAAnalyzer {
33 // lists containing the elements of a topology
34 List<TNodeTemplate> nodeTemplates = new ArrayList<TNodeTemplate>();
35 List<TRelationshipTemplate> relationshipTemplates = new ArrayList<TRelationshipTemplate>();
36 List<TRequirement> requirements = new ArrayList<TRequirement>();
38 List<TNodeType> nodeTypes;
39 List<TRelationshipType> relationshipTypes;
40 List<TRequirementType> requirementTypes;
43 * This method analyzes the TOSCA {@link TTopologyTemplate} for {@link TNodeTemplate}s, {@link TRelationshipTemplate}s
44 * and existing {@link TRequirement}s and adds them to a list.
47 * the TOSCA {@link TTopologyTemplate}
49 public void analyzeTOSCATopology(TTopologyTemplate topology) {
51 // fill the data model with content of the topology
52 List<TEntityTemplate> templateNodes = topology.getNodeTemplateOrRelationshipTemplate();
54 for (TEntityTemplate entityTemplate : templateNodes) {
55 if (entityTemplate instanceof TNodeTemplate) {
56 // add the node templates and their requirements to the data model
57 nodeTemplates.add((TNodeTemplate) entityTemplate);
58 if (((TNodeTemplate) entityTemplate).getRequirements() != null) {
59 requirements.addAll(((TNodeTemplate) entityTemplate).getRequirements().getRequirement());
61 } else if (entityTemplate instanceof TRelationshipTemplate) {
62 // add RelationshipTemplates
63 relationshipTemplates.add((TRelationshipTemplate) entityTemplate);
69 * Setter for the types received from the Winery repository.
71 * @param nodeTypeXMLStrings
72 * a list of {@link TNodeType}s from the Winery repository
73 * @param relationshipTypeXMLStrings
74 * a list of {@link TRelationshipType}s from the Winery repository
75 * @param requirementTypeList
76 * a list of {@link TRequirementType}s from the Winery repository
78 public void setTypes(List<TNodeType> nodeTypes, List<TRelationshipType> relationshipTypes, List<TRequirementType> requirementTypes) {
79 this.nodeTypes = nodeTypes;
80 this.relationshipTypes = relationshipTypes;
81 this.requirementTypes = requirementTypes;
85 * Returns the {@link TNodeTemplate}s of the topology.
87 * @return the {@link TNodeTemplate}s as a list
89 public List<TNodeTemplate> getNodeTemplates() {
94 * Returns the {@link TRelationshipTemplate}s of the topology.
96 * @return the {@link TRelationshipTemplate}s as a list
98 public List<TRelationshipTemplate> getRelationshipTemplates() {
99 return relationshipTemplates;
103 * Returns the {@link TRequirement}s of the topology.
105 * @return the {@link TRequirement}s as a list
107 public List<TRequirement> getRequirements() {
112 * Returns the {@link TRelationshipType}s of the topology.
114 * @return the {@link TRelationshipType}s as a list
116 public List<TRelationshipType> getRelationshipTypes() {
117 return relationshipTypes;
121 * Returns the {@link TNodeType}s of the topology.
123 * @return the {@link TNodeType}s as a list
125 public List<TNodeType> getNodeTypes() {
130 * Returns the {@link TRequirementType}s of the topology.
132 * @return the {@link TRequirementType}s as a list
134 public List<TRequirementType> getRequirementTypes() {
135 return requirementTypes;
139 * Clears all the templates from the data model before the analysis of a topology is restarted.
141 public void clear() {
142 nodeTemplates.clear();
143 relationshipTemplates.clear();
144 requirements.clear();