001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements. See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache license, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License. You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the license for the specific language governing permissions and
015     * limitations under the license.
016     */
017    package org.apache.logging.log4j.core.config;
018    
019    import org.apache.logging.log4j.core.config.plugins.Plugin;
020    import java.io.File;
021    
022    /**
023     *
024     */
025    @Plugin(name = "JSONConfigurationFactory", type = "ConfigurationFactory")
026    @Order(6)
027    public class JSONConfigurationFactory extends ConfigurationFactory {
028    
029        /**
030         * The file extensions supported by this factory.
031         */
032        public static final String[] SUFFIXES = new String[] {".json", ".jsn"};
033    
034        private static String[] dependencies = new String[] {
035            "org.codehaus.jackson.JsonNode",
036            "org.codehaus.jackson.map.ObjectMapper"
037        };
038    
039        private final File configFile = null;
040    
041        private boolean isActive;
042    
043        public JSONConfigurationFactory() {
044            try {
045                for (final String item : dependencies) {
046                    Class.forName(item);
047                }
048            } catch (final ClassNotFoundException ex) {
049                LOGGER.debug("Missing dependencies for Json support");
050                isActive = false;
051                return;
052            }
053            isActive = true;
054        }
055    
056        @Override
057        protected boolean isActive() {
058            return isActive;
059        }
060    
061        @Override
062        public Configuration getConfiguration(final ConfigurationSource source) {
063            if (!isActive) {
064                return null;
065            }
066            return new JSONConfiguration(source);
067        }
068    
069        @Override
070        public String[] getSupportedTypes() {
071            return SUFFIXES;
072        }
073    }