001/* 002 * Copyright 2012-2017 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; 024import org.springframework.util.Assert; 025 026/** 027 * {@link SpringBootCondition} used to check if the Hazelcast configuration is available. 028 * This either kicks in if a default configuration has been found or if configurable 029 * property referring to the resource to use has been set. 030 * 031 * @author Stephane Nicoll 032 * @author Madhura Bhave 033 * @author Vedran Pavic 034 * @since 1.3.0 035 */ 036public abstract class HazelcastConfigResourceCondition extends ResourceCondition { 037 038 private final String configSystemProperty; 039 040 protected HazelcastConfigResourceCondition(String configSystemProperty, 041 String... resourceLocations) { 042 super("Hazelcast", "spring.hazelcast.config", resourceLocations); 043 Assert.notNull(configSystemProperty, "ConfigSystemProperty must not be null"); 044 this.configSystemProperty = configSystemProperty; 045 } 046 047 @Override 048 protected ConditionOutcome getResourceOutcome(ConditionContext context, 049 AnnotatedTypeMetadata metadata) { 050 if (System.getProperty(this.configSystemProperty) != null) { 051 return ConditionOutcome.match(startConditionMessage().because( 052 "System property '" + this.configSystemProperty + "' is set.")); 053 } 054 return super.getResourceOutcome(context, metadata); 055 } 056 057}