2  * Copyright 2016 [ZTE] and others.
 
   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
 
   8  *     http://www.apache.org/licenses/LICENSE-2.0
 
  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.
 
  17 package org.openo.commontosca.catalog.model.parser;
 
  19 import org.openo.commontosca.catalog.common.Config;
 
  20 import org.openo.commontosca.catalog.db.exception.CatalogResourceException;
 
  21 import org.openo.commontosca.catalog.model.parser.yaml.aria.AriaModelParser;
 
  22 import org.openo.commontosca.catalog.model.parser.yaml.zte.ToscaYamlModelParser;
 
  24 import java.util.HashMap;
 
  28 public class ModelParserFactory {
 
  29   private static final ModelParserFactory instance = new ModelParserFactory();
 
  31   public static ModelParserFactory getInstance() {
 
  35   private Map<EnumPackageFormat, AbstractModelParser> pkgType2ParseMap =
 
  36       new HashMap<EnumPackageFormat, AbstractModelParser>();
 
  38   private ModelParserFactory() {
 
  39     // PackageParseMap.put(EnumPackageFormat.TOSCA_XML, new
 
  40     // ToscaXmlModelParser());
 
  42       pkgType2ParseMap.put(EnumPackageFormat.TOSCA_YAML, new AriaModelParser());
 
  44       pkgType2ParseMap.put(EnumPackageFormat.TOSCA_YAML, new ToscaYamlModelParser());
 
  51   private boolean isAriaParser() {
 
  52     return "aria".equalsIgnoreCase(Config.getConfigration().getParserType());
 
  57    * @param packageId package id
 
  58    * @param fileLocation package location
 
  59    * @param format package format
 
  60    * @return service template id 
 
  61    * @throws CatalogResourceException e
 
  63   public String parse(String packageId, String fileLocation, EnumPackageFormat format)
 
  64       throws CatalogResourceException {
 
  65     if (pkgType2ParseMap.get(format) == null) {
 
  66       throw new CatalogResourceException("Can't find its parser. package type = "
 
  70     return pkgType2ParseMap.get(format).parse(packageId, fileLocation);