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