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 java.io.File;
020    
021    import org.apache.logging.log4j.core.config.plugins.Plugin;
022    
023    /**
024     *
025     */
026    @Plugin(name = "JSONConfigurationFactory", category = "ConfigurationFactory")
027    @Order(6)
028    public class JSONConfigurationFactory extends ConfigurationFactory {
029    
030        /**
031         * The file extensions supported by this factory.
032         */
033        public static final String[] SUFFIXES = new String[] {".json", ".jsn"};
034    
035        private static String[] dependencies = new String[] {
036                "com.fasterxml.jackson.databind.ObjectMapper",
037                "com.fasterxml.jackson.databind.JsonNode",
038                "com.fasterxml.jackson.core.JsonParser"
039        };
040    
041        private final File configFile = null;
042    
043        private boolean isActive;
044    
045        public JSONConfigurationFactory() {
046            try {
047                for (final String item : dependencies) {
048                    Class.forName(item);
049                }
050            } catch (final ClassNotFoundException ex) {
051                LOGGER.debug("Missing dependencies for Json support");
052                isActive = false;
053                return;
054            }
055            isActive = true;
056        }
057    
058        @Override
059        protected boolean isActive() {
060            return isActive;
061        }
062    
063        @Override
064        public Configuration getConfiguration(final ConfigurationSource source) {
065            if (!isActive) {
066                return null;
067            }
068            return new JSONConfiguration(source);
069        }
070    
071        @Override
072        public String[] getSupportedTypes() {
073            return SUFFIXES;
074        }
075    }