2 * Copyright 2016 [ZTE] and others.
\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
8 * http://www.apache.org/licenses/LICENSE-2.0
\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
17 package org.openo.commontosca.catalog.model.parser;
\r
19 import org.openo.commontosca.catalog.db.exception.CatalogResourceException;
\r
21 import java.util.HashMap;
\r
22 import java.util.Map;
\r
25 public class ModelParserFactory {
\r
26 private static final ModelParserFactory instance = new ModelParserFactory();
\r
28 public static ModelParserFactory getInstance() {
\r
32 private Map<EnumPackageFormat, AbstractModelParser> pkgType2ParseMap =
\r
33 new HashMap<EnumPackageFormat, AbstractModelParser>();
\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
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
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
56 return pkgType2ParseMap.get(format).parse(packageId, fileLocation);
\r