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.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;
24 * This class contains a method to analyze a TOSCA {@link TTopologyTemplate} for
25 * the occurrence of "Deferred"-{@link TRelationshipTemplate}s.
27 * A "Deferred"-{@link TRelationshipTemplate} serves as place holder for any number of Node or Relationship
30 public class DeferredAnalyzer {
33 * Iterates over all {@link TRelationshipTemplate} and checks if its type is "deferred".
35 * @param toscaAnalyzer
36 * the {@link TOSCAAnalyzer} object to access the data model
38 * @return a list of found deferred {@link TRelationshipTemplate}s
40 public static List<TRelationshipTemplate> analyzeDeferredRelations(TOSCAAnalyzer toscaAnalyzer) {
42 List<TRelationshipTemplate> foundDeferredRelations = new ArrayList<TRelationshipTemplate>();
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())) {
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();
53 if (source.getRequirements() != null) {
54 foundDeferredRelations.add(relationshipTemplate);
58 return foundDeferredRelations;