@@ -0,0 +1,3266 @@
+/*%0A * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.%0A *%0A * WSO2 Inc. licenses this file to you under the Apache License,%0A * Version 2.0 (the %22License%22); you may not use this file except%0A * in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *   http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing,%0A * software distributed under the License is distributed on an%0A * %22AS IS%22 BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY%0A * KIND, either express or implied.  See the License for the%0A * specific language governing permissions and limitations%0A * under the License.%0A */%0A%0Apackage org.wso2.carbon.uis.internal.deployment.parser;%0A%0Aimport org.wso2.carbon.uis.internal.exception.ConfigurationException;%0Aimport org.wso2.carbon.uis.internal.exception.FileOperationException;%0Aimport org.wso2.carbon.uis.internal.reference.FileReference;%0Aimport org.yaml.snakeyaml.Yaml;%0Aimport org.yaml.snakeyaml.constructor.Constructor;%0A%0A/**%0A * Parser for YAML configuration files in web apps.%0A *%0A * @since 0.12.1%0A */%0Apublic class YamlFileParser %7B%0A%0A    /**%0A     * Parses the given YAML configuration file and de-serialize the content into given bean type.%0A     *%0A     * @param yamlFile reference to the YAML configuration file%0A     * @param type     class of the bean to be used when de-serializing%0A     * @param %3CT%3E      type of the bean class to be used when de-serializing%0A     * @return returns the populated bean instance%0A     * @throws ConfigurationException if cannot read or parse the content of the specified YAML file%0A     */%0A    public static %3CT%3E T parse(FileReference yamlFile, Class%3CT%3E type) throws ConfigurationException %7B%0A        T loadedBean;%0A        try %7B%0A            loadedBean = new Yaml(new ClassLoaderConstructor(type)).loadAs(yamlFile.getContent(), type);%0A        %7D catch (FileOperationException e) %7B%0A            throw new ConfigurationException(%0A                    %22Cannot read the YAML configuration file '%22 + yamlFile.getFilePath() + %22'.%22, e);%0A        %7D catch (Exception e) %7B%0A            throw new ConfigurationException(%0A                    %22Cannot parse the YAML configuration file '%22 + yamlFile.getFilePath() + %22'.%22, e);%0A        %7D%0A        if (loadedBean == null) %7B%0A            // Either configuration file is empty or has only comments.%0A            throw new ConfigurationException(%0A                    %22Cannot load the YAML configuration file '%22 + yamlFile.getFilePath() + %22' as it is empty.%22);%0A        %7D%0A        return loadedBean;%0A    %7D%0A%0A    /**%0A     * OSGi friendly YAML constructor that loads classes through a given class object.%0A     *%0A     * @since 0.12.1%0A     */%0A    private static class ClassLoaderConstructor extends Constructor %7B%0A%0A        private final ClassLoader classLoader;%0A%0A        /**%0A         * Creates a new constructor.%0A         *%0A         * @param aClass class that uses for class loading%0A         */%0A        public ClassLoaderConstructor(Class aClass) %7B%0A            super(Object.class);%0A            this.classLoader = aClass.getClassLoader();%0A        %7D%0A%0A        @Override%0A        protected Class%3C?%3E getClassForName(String name) throws ClassNotFoundException %7B%0A            return Class.forName(name, true, classLoader);%0A        %7D%0A    %7D%0A%7D%0A

add YamlFileParser class