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
16 package org.openo.commontosca.catalog.model.parser;
\r
18 import java.util.HashMap;
\r
19 import java.util.Map;
\r
21 import org.openo.commontosca.catalog.db.exception.CatalogResourceException;
\r
23 public class ModelParserFactory {
\r
24 private final static ModelParserFactory instance = new ModelParserFactory();
\r
25 public static ModelParserFactory getInstance() {
\r
29 private Map<EnumPackageFormat, AbstractModelParser> pkgType2ParseMap = new HashMap<EnumPackageFormat, AbstractModelParser>();
\r
31 private ModelParserFactory() {
\r
32 // PackageParseMap.put(EnumPackageFormat.TOSCA_XML, new
\r
33 // ToscaXmlModelParser());
\r
34 pkgType2ParseMap.put(EnumPackageFormat.TOSCA_YAML, new ToscaYamlModelParser());
\r
40 * @param fileLocation
\r
42 * @return service template id
\r
43 * @throws CatalogResourceException
\r
45 public String parse(String packageId, String fileLocation,
\r
46 EnumPackageFormat format) throws CatalogResourceException {
\r
47 if (pkgType2ParseMap.get(format) == null) {
\r
48 throw new CatalogResourceException(
\r
49 "Can't find its parser. package type = "
\r
50 + format.toString());
\r
53 return pkgType2ParseMap.get(format).parse(packageId, fileLocation);
\r