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.placeholderhandling;
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.TNodeType;
20 import org.eclipse.winery.topologymodeler.addons.topologycompleter.analyzer.TOSCAAnalyzer;
21 import org.eclipse.winery.topologymodeler.addons.topologycompleter.helper.Constants;
24 * This class finds suitable replacement types for a place holder.
26 public class PlaceHolderHandler {
29 * This method returns a suitable {@link TNodeType} to replace a given {@link TNodeTemplate} placeholder.
30 * A suitable Node Type to replace a placeholder is matched by its type. If the type of a NodeType equals the identifier of a placeholder
31 * it can be used to replace it.
34 * the placeholder to be replaced
35 * @param toscaAnalyzer
36 * the {@link TOSCAAnalyzer} object to access the data model
38 * @return a list of {@link TNodeType}s to replace the placeholder
40 public static List<TNodeType> getSuitableNodeTypes(TNodeTemplate nodeTemplate, TOSCAAnalyzer toscaAnalyzer) {
42 List<TNodeType> suitableNodeTypes = new ArrayList<>();
44 // TODO: matching the name without a name space is unsafe and only works assuming that no one creates generic NodeTemplates with the same name as the place holders.
45 // However a NodeTemplate name does not have a name space.
46 if (nodeTemplate.getName().equals(Constants.PlaceHolders.WEBSERVER.toString())) {
47 for (TNodeType nodeType : toscaAnalyzer.getNodeTypes()) {
48 if (nodeType.getDerivedFrom() != null && nodeType.getDerivedFrom().getTypeRef().getLocalPart().equals(Constants.PlaceHolders.WEBSERVER.toString())) {
49 suitableNodeTypes.add(nodeType);
52 } else if (nodeTemplate.getName().equals(Constants.PlaceHolders.DATABASE.toString())) {
53 for (TNodeType nodeType : toscaAnalyzer.getNodeTypes()) {
54 if (nodeType.getDerivedFrom() != null && nodeType.getDerivedFrom().getTypeRef().getLocalPart().equals(Constants.PlaceHolders.DATABASE.toString())) {
55 suitableNodeTypes.add(nodeType);
58 } else if (nodeTemplate.getName().equals(Constants.PlaceHolders.OPERATINGSYSTEM.toString())) {
59 for (TNodeType nodeType : toscaAnalyzer.getNodeTypes()) {
60 if (nodeType.getDerivedFrom() != null && nodeType.getDerivedFrom().getTypeRef().getLocalPart().equals(Constants.PlaceHolders.OPERATINGSYSTEM.toString())) {
61 suitableNodeTypes.add(nodeType);
64 } else if (nodeTemplate.getName().equals(Constants.PlaceHolders.CLOUDPROVIDER.toString())) {
65 for (TNodeType nodeType : toscaAnalyzer.getNodeTypes()) {
66 if (nodeType.getDerivedFrom() != null && nodeType.getDerivedFrom().getTypeRef().getLocalPart().equals(Constants.PlaceHolders.CLOUDPROVIDER.toString())) {
67 suitableNodeTypes.add(nodeType);
72 return suitableNodeTypes;