View Javadoc
1   /*
2    * Copyright 2001-2005 The Apache Software Foundation.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.apache.logging.log4j.catalog.api.annotation;
17  
18  import org.springframework.context.annotation.Condition;
19  import org.springframework.context.annotation.ConditionContext;
20  import org.springframework.core.env.Environment;
21  import org.springframework.core.type.AnnotatedTypeMetadata;
22  import org.springframework.util.MultiValueMap;
23  
24  /**
25   *
26   */
27  public class PropertyExistsCondition implements Condition {
28      @Override
29      public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
30          Environment env = context.getEnvironment();
31          MultiValueMap<String, Object> attrs = metadata.getAllAnnotationAttributes(ConditionOnPropertyExists.class.getName());
32          if (attrs != null) {
33              Object value = attrs.get("value");
34              return value != null && null != env && env.getProperty(value.toString()) != null;
35          }
36          return false;
37      }
38  }