3b81236c1d85fb1fb8756fe97e4bd6bc1e5fcd37
[vfc/nfvo/wfengine.git] /
1 /*******************************************************************************
2  * Copyright (c) 2013 University of Stuttgart.
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  *     Oliver Kopp - initial API and implementation
11  *******************************************************************************/
12 package org.eclipse.winery.common.ids.definitions.imports;
13
14 import org.apache.commons.io.FilenameUtils;
15 import org.eclipse.winery.model.tosca.TImport;
16 import org.eclipse.winery.common.Util;
17 import org.eclipse.winery.common.ids.Namespace;
18 import org.eclipse.winery.common.ids.XMLId;
19 import org.eclipse.winery.common.ids.definitions.TOSCAComponentId;
20
21 /**
22  * class for import ids (not used for definitions)
23  * 
24  * // Convention: id of import is filename without extension
25  */
26 public class GenericImportId extends TOSCAComponentId {
27         
28         private final String type;
29         
30         
31         /**
32          * @param type the importType (e.g., MimeTypes.MIMETYPE_XSD)
33          */
34         public GenericImportId(Namespace namespace, XMLId xmlId, String type) {
35                 super(namespace, xmlId);
36                 this.type = type;
37         }
38         
39         public GenericImportId(String ns, String id, boolean encoded, String type) {
40                 super(ns, id, encoded);
41                 this.type = type;
42         }
43         
44         /**
45          * Generates an ImportId based on an TImport object The import has to be an
46          * import created by winery. This method uses the convention that the id is
47          * derived from the location
48          * 
49          * @param i the TImport element to derive an id from
50          */
51         public GenericImportId(TImport i) {
52                 this(i.getNamespace(), GenericImportId.getId(i), false, i.getImportType());
53         }
54         
55         private static String getId(TImport i) {
56                 String fileName = Util.getLastURIPart(i.getLocation());
57                 String id = FilenameUtils.removeExtension(fileName);
58                 return id;
59         }
60         
61         public String getType() {
62                 return this.type;
63         }
64 }