Add winery source code
[vfc/nfvo/wfengine.git] / winery / org.eclipse.winery.topologymodeler / src / main / java / org / eclipse / winery / topologymodeler / addons / topologycompleter / analyzer / PlaceHolderAnalyzer.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.TNodeType;
20 import org.eclipse.winery.topologymodeler.addons.topologycompleter.helper.Constants;
21 import org.eclipse.winery.topologymodeler.addons.topologycompleter.helper.Utils;
22
23 /**
24  * This class analyzes the occurrence of place holders in a topology and writes them to an {@link ArrayList}.
25  */
26 public class PlaceHolderAnalyzer {
27
28         /**
29          * This method searches {@link TNodeTemplate}s that are derived from the abstract "PlaceHolder" type and adds them to a list.
30          *
31          * @param toscaAnalyzer
32          *            the {@link TOSCAAnalyzer} object to access the data model
33          *
34          * @return the found place holders of the topology as a list.
35          */
36         public static List<TNodeTemplate> analyzePlaceHolders(TOSCAAnalyzer toscaAnalyzer) {
37
38                 List<TNodeTemplate> foundPlaceHolders = new ArrayList<TNodeTemplate>();
39
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()) {
42
43                         TNodeType nodeType = Utils.getNodeTypeForId(toscaAnalyzer.getNodeTypes(), nodeTemplate.getType());
44
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);
48                         }
49                 }
50                 return foundPlaceHolders;
51         }
52 }