45131a78b33838465b84eba91b4f48ae1978e42e
[vfc/nfvo/wfengine.git] /
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
8  *
9  * Contributors:
10  *    Pascal Hirmer - initial API and implementation
11  *******************************************************************************/
12
13 package org.eclipse.winery.topologymodeler.addons.topologycompleter.analyzer;
14
15 import java.util.ArrayList;
16 import java.util.List;
17
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;
26
27 /**
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.
30  */
31 public class TOSCAAnalyzer {
32
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>();
37
38         List<TNodeType>                 nodeTypes;
39         List<TRelationshipType>         relationshipTypes;
40         List<TRequirementType>          requirementTypes;
41
42         /**
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.
45          *
46          * @param topology
47          *            the TOSCA {@link TTopologyTemplate}
48          */
49         public void analyzeTOSCATopology(TTopologyTemplate topology) {
50
51                 // fill the data model with content of the topology
52                 List<TEntityTemplate> templateNodes = topology.getNodeTemplateOrRelationshipTemplate();
53
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());
60                                 }
61                         } else if (entityTemplate instanceof TRelationshipTemplate) {
62                                 // add RelationshipTemplates
63                                 relationshipTemplates.add((TRelationshipTemplate) entityTemplate);
64                         }
65                 }
66         }
67
68         /**
69          * Setter for the types received from the Winery repository.
70          *
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
77          */
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;
82         }
83
84         /**
85          * Returns the {@link TNodeTemplate}s of the topology.
86          *
87          * @return the {@link TNodeTemplate}s as a list
88          */
89         public List<TNodeTemplate> getNodeTemplates() {
90                 return nodeTemplates;
91         }
92
93         /**
94          * Returns the {@link TRelationshipTemplate}s of the topology.
95          *
96          * @return the {@link TRelationshipTemplate}s as a list
97          */
98         public List<TRelationshipTemplate> getRelationshipTemplates() {
99                 return relationshipTemplates;
100         }
101
102         /**
103          * Returns the {@link TRequirement}s of the topology.
104          *
105          * @return the {@link TRequirement}s as a list
106          */
107         public List<TRequirement> getRequirements() {
108                 return requirements;
109         }
110
111         /**
112          * Returns the {@link TRelationshipType}s of the topology.
113          *
114          * @return the {@link TRelationshipType}s as a list
115          */
116         public List<TRelationshipType> getRelationshipTypes() {
117                 return relationshipTypes;
118         }
119
120         /**
121          * Returns the {@link TNodeType}s of the topology.
122          *
123          * @return the {@link TNodeType}s as a list
124          */
125         public List<TNodeType> getNodeTypes() {
126                 return nodeTypes;
127         }
128
129         /**
130          * Returns the {@link TRequirementType}s of the topology.
131          *
132          * @return the {@link TRequirementType}s as a list
133          */
134         public List<TRequirementType> getRequirementTypes() {
135                 return requirementTypes;
136         }
137
138         /**
139          * Clears all the templates from the data model before the analysis of a topology is restarted.
140          */
141         public void clear() {
142                 nodeTemplates.clear();
143                 relationshipTemplates.clear();
144                 requirements.clear();
145         }
146 }