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.TNodeType;
20 import org.eclipse.winery.topologymodeler.addons.topologycompleter.helper.Constants;
21 import org.eclipse.winery.topologymodeler.addons.topologycompleter.helper.Utils;
24 * This class analyzes the occurrence of place holders in a topology and writes them to an {@link ArrayList}.
26 public class PlaceHolderAnalyzer {
29 * This method searches {@link TNodeTemplate}s that are derived from the abstract "PlaceHolder" type and adds them to a list.
31 * @param toscaAnalyzer
32 * the {@link TOSCAAnalyzer} object to access the data model
34 * @return the found place holders of the topology as a list.
36 public static List<TNodeTemplate> analyzePlaceHolders(TOSCAAnalyzer toscaAnalyzer) {
38 List<TNodeTemplate> foundPlaceHolders = new ArrayList<TNodeTemplate>();
40 // Check the type of the NodeTemplates, write them to a list if the type is derived from the common place holder type.
41 for (TNodeTemplate nodeTemplate : toscaAnalyzer.getNodeTemplates()) {
43 TNodeType nodeType = Utils.getNodeTypeForId(toscaAnalyzer.getNodeTypes(), nodeTemplate.getType());
45 if (nodeType != null && nodeType.getDerivedFrom() != null && nodeType.getDerivedFrom().getTypeRef().getLocalPart().equals(Constants.PLACE_HOLDER_QNAME.getLocalPart()) &&
46 nodeType.getDerivedFrom().getTypeRef().getNamespaceURI().equals(Constants.PLACE_HOLDER_QNAME.getNamespaceURI())) {
47 foundPlaceHolders.add(nodeTemplate);
50 return foundPlaceHolders;