/*
 * Licensed to Elasticsearch under one or more contributor
 * license agreements. See the NOTICE file distributed with
 * this work for additional information regarding copyright
 * ownership. Elasticsearch licenses this file to you under
 * the Apache License, Version 2.0 (the "License"); you may
 * not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package org.elasticsearch.common.settings.loader;

/**
 * A settings loader factory automatically trying to identify what type of
 * {@link SettingsLoader} to use.
 *
 *
 */
public final class SettingsLoaderFactory {

    private SettingsLoaderFactory() {

    }

    /**
     * Returns a {@link SettingsLoader} based on the resource name.
     */
    public static SettingsLoader loaderFromResource(String resourceName) {
        if (resourceName.endsWith(".json")) {
            return new JsonSettingsLoader(false);
        } else if (resourceName.endsWith(".yml") || resourceName.endsWith(".yaml")) {
            return new YamlSettingsLoader(false);
        } else if (resourceName.endsWith(".properties")) {
            return new PropertiesSettingsLoader();
        } else {
            // lets default to the json one
            return new JsonSettingsLoader(false);
        }
    }

    /**
     * Returns a {@link SettingsLoader} based on the actual settings source.
     */
    public static SettingsLoader loaderFromSource(String source) {
        if (source.indexOf('{') != -1 && source.indexOf('}') != -1) {
            return new JsonSettingsLoader(true);
        }
        if (source.indexOf(':') != -1) {
            return new YamlSettingsLoader(true);
        }
        return new PropertiesSettingsLoader();
    }
}

@@ -847,117 +847,129 @@
 * A 
-settings loader factory automatically trying to identify what type of%0A * %7B@link SettingsLoader%7D to use.%0A *%0A *
+class holding factory methods for settings loaders that attempts%0A * to infer the type of the underlying settings content.
 %0A */
@@ -1051,17 +1051,16 @@
 ory() %7B%0A
-%0A
     %7D%0A%0A 
@@ -1119,24 +1119,31 @@
  on the 
+source 
 resource
  name.%0A 
@@ -1138,13 +1138,656 @@
 urce
- name
+%0A     * name. This factory method assumes that if the resource name ends%0A     * with %22.json%22 then the content should be parsed as JSON, else if%0A     * the resource name ends with %22.yml%22 or %22.yaml%22 then the content%0A     * should be parsed as YAML, else if the resource name ends with%0A     * %22.properties%22 then the content should be parsed as properties,%0A     * otherwise default to attempting to parse as JSON. Note that the%0A     * parsers returned by this method will not accept null-valued%0A     * keys.%0A     *%0A     * @param resourceName The resource name containing the settings%0A     *                     content.%0A     * @return A settings loader
 .%0A  
@@ -2402,30 +2402,570 @@
 the 
-actual settings source
+source content.%0A     * This factory method assumes that if the underlying content%0A     * contains an opening and closing brace ('%7B' and '%7D') then the%0A     * content should be parsed as JSON, else if the underlying content%0A     * fails this condition but contains a ':' then the content should%0A     * be parsed as YAML, and otherwise should be parsed as properties.%0A     * Note that the JSON and YAML parsers returned by this method will%0A     * accept null-valued keys.%0A     *%0A     * @param source The underlying settings content.%0A     * @return A settings loader
 .%0A  
@@ -3319,10 +3319,11 @@
 ;%0A    %7D%0A
+%0A
 %7D%0A

Clarify Javadocs for SettingsLoaderFactory