001/*
002 * Copyright 2012-2016 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.boot.autoconfigure.hazelcast;
018
019import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
020import org.springframework.boot.autoconfigure.condition.ResourceCondition;
021import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
022import org.springframework.context.annotation.ConditionContext;
023import org.springframework.core.type.AnnotatedTypeMetadata;
024
025/**
026 * {@link SpringBootCondition} used to check if the Hazelcast configuration is available.
027 * This either kicks in if a default configuration has been found or if configurable
028 * property referring to the resource to use has been set.
029 *
030 * @author Stephane Nicoll
031 * @since 1.3.0
032 */
033public abstract class HazelcastConfigResourceCondition extends ResourceCondition {
034
035        static final String CONFIG_SYSTEM_PROPERTY = "hazelcast.config";
036
037        protected HazelcastConfigResourceCondition(String prefix, String propertyName) {
038                super("Hazelcast", prefix, propertyName, "file:./hazelcast.xml",
039                                "classpath:/hazelcast.xml");
040        }
041
042        @Override
043        protected ConditionOutcome getResourceOutcome(ConditionContext context,
044                        AnnotatedTypeMetadata metadata) {
045                if (System.getProperty(CONFIG_SYSTEM_PROPERTY) != null) {
046                        return ConditionOutcome.match(startConditionMessage()
047                                        .because("System property '" + CONFIG_SYSTEM_PROPERTY + "' is set."));
048                }
049                return super.getResourceOutcome(context, metadata);
050        }
051
052}