c4db9bbae311683e959dcbc65795e5da87be84ee
[vfc/nfvo/wfengine.git] / winery / org.eclipse.winery.topologymodeler / src / main / java / org / eclipse / winery / topologymodeler / addons / topologycompleter / analyzer / DeferredAnalyzer.java
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.TNodeTemplate;
19 import org.eclipse.winery.model.tosca.TRelationshipTemplate;
20 import org.eclipse.winery.model.tosca.TTopologyTemplate;
21 import org.eclipse.winery.topologymodeler.addons.topologycompleter.helper.Constants;
22
23 /**
24  * This class contains a method to analyze a TOSCA {@link TTopologyTemplate} for
25  * the occurrence of "Deferred"-{@link TRelationshipTemplate}s.
26  *
27  * A "Deferred"-{@link TRelationshipTemplate} serves as place holder for any number of Node or Relationship
28  * Templates.
29  */
30 public class DeferredAnalyzer {
31
32         /**
33          * Iterates over all {@link TRelationshipTemplate} and checks if its type is "deferred".
34          *
35          * @param toscaAnalyzer
36          *            the {@link TOSCAAnalyzer} object to access the data model
37          *
38          * @return a list of found deferred {@link TRelationshipTemplate}s
39          */
40         public static List<TRelationshipTemplate> analyzeDeferredRelations(TOSCAAnalyzer toscaAnalyzer) {
41
42                 List<TRelationshipTemplate> foundDeferredRelations = new ArrayList<TRelationshipTemplate>();
43
44                 for (TRelationshipTemplate relationshipTemplate : toscaAnalyzer.getRelationshipTemplates()) {
45                         if (relationshipTemplate.getType() != null && relationshipTemplate.getType().getLocalPart().equals(Constants.DEFERRED_QNAME.getLocalPart()) &&
46                                         relationshipTemplate.getType().getNamespaceURI().equals(Constants.DEFERRED_QNAME.getNamespaceURI())) {
47
48                                 // TODO: This step has to be done until the "Provisioning-API"
49                                 // is implemented. The Deferred RelationshipTemplate can only be
50                                 // completed if Requirements exist at the source template.
51                                 TNodeTemplate source = (TNodeTemplate) relationshipTemplate.getSourceElement().getRef();
52
53                                 if (source.getRequirements() != null) {
54                                         foundDeferredRelations.add(relationshipTemplate);
55                                 }
56                         }
57                 }
58                 return foundDeferredRelations;
59         }
60 }