1 /*
2 * Logback: the reliable, generic, fast and flexible logging framework.
3 * Copyright (C) 1999-2026, QOS.ch. All rights reserved.
4 *
5 * This program and the accompanying materials are dual-licensed under
6 * either the terms of the Eclipse Public License v2.0 as published by
7 * the Eclipse Foundation
8 *
9 * or (per the licensee's choosing)
10 *
11 * under the terms of the GNU Lesser General Public License version 2.1
12 * as published by the Free Software Foundation.
13 */
14
15 package ch.qos.logback.core.boolex;
16
17 /**
18 * Checks whether a named property is defined in the
19 * context (e.g. system properties, environment, or the configured
20 * property map used by the surrounding framework).
21 *
22 * <p>This condition expects a property name to be provided via
23 * {@link #setKey(String)}. When {@link #evaluate()} is called it returns
24 * {@code true} if the named property is defined and {@code false}
25 * otherwise.
26 */
27 public class IsPropertyDefinedCondition extends PropertyConditionBase {
28
29 /**
30 * The property name to check for definition. Must be set before
31 * starting this evaluator.
32 */
33 String key;
34
35 /**
36 * Start the evaluator. If the required {@link #key} is not set an
37 * error is reported and startup is aborted.
38 */
39 public void start() {
40 if (key == null) {
41 addError("In IsPropertyDefinedEvaluator 'key' parameter cannot be null");
42 return;
43 }
44 super.start();
45 }
46
47 /**
48 * Return the configured property name (key) that this evaluator will
49 * test for definition.
50 *
51 * @return the property key, or {@code null} if not set
52 */
53 public String getKey() {
54 return key;
55 }
56
57 /**
58 * Set the property name (key) to be checked by this evaluator.
59 *
60 * @param key the property name to check; must not be {@code null}
61 */
62 public void setKey(String key) {
63 this.key = key;
64 }
65
66
67 /**
68 * Evaluate whether the configured property is defined.
69 *
70 * @return {@code true} if the property named by {@link #key} is
71 * defined, {@code false} otherwise
72 */
73 @Override
74 public boolean evaluate() {
75 return isDefined(key);
76 }
77 }