f69e2ece7722444f2ff677e2a8c8060a160286d3
[vfc/nfvo/catalog.git] /
1 /**\r
2  * Copyright 2016 [ZTE] and others.\r
3  *\r
4  * Licensed under the Apache License, Version 2.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  *\r
8  *     http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  */\r
16 \r
17 package org.openo.commontosca.catalog.model.parser;\r
18 \r
19 import org.openo.commontosca.catalog.db.exception.CatalogResourceException;\r
20 \r
21 import java.util.HashMap;\r
22 import java.util.Map;\r
23 \r
24 \r
25 public class ModelParserFactory {\r
26   private static final ModelParserFactory instance = new ModelParserFactory();\r
27 \r
28   public static ModelParserFactory getInstance() {\r
29     return instance;\r
30   }\r
31 \r
32   private Map<EnumPackageFormat, AbstractModelParser> pkgType2ParseMap =\r
33       new HashMap<EnumPackageFormat, AbstractModelParser>();\r
34 \r
35   private ModelParserFactory() {\r
36     // PackageParseMap.put(EnumPackageFormat.TOSCA_XML, new\r
37     // ToscaXmlModelParser());\r
38     pkgType2ParseMap.put(EnumPackageFormat.TOSCA_YAML, new ToscaYamlModelParser());\r
39   }\r
40 \r
41   /**\r
42    * parse package.\r
43    * @param packageId package id\r
44    * @param fileLocation package location\r
45    * @param format package format\r
46    * @return service template id \r
47    * @throws CatalogResourceException e\r
48    */\r
49   public String parse(String packageId, String fileLocation, EnumPackageFormat format)\r
50       throws CatalogResourceException {\r
51     if (pkgType2ParseMap.get(format) == null) {\r
52       throw new CatalogResourceException("Can't find its parser. package type = "\r
53           + format.toString());\r
54     }\r
55 \r
56     return pkgType2ParseMap.get(format).parse(packageId, fileLocation);\r
57   }\r
58 }\r