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.joran;
16  
17  import ch.qos.logback.core.Context;
18  import ch.qos.logback.core.joran.util.PropertySetter;
19  import ch.qos.logback.core.joran.util.beans.BeanDescriptionCache;
20  import ch.qos.logback.core.model.Model;
21  import ch.qos.logback.core.model.ParamModel;
22  import ch.qos.logback.core.model.processor.ModelHandlerBase;
23  import ch.qos.logback.core.model.processor.ModelHandlerException;
24  import ch.qos.logback.core.model.processor.ModelInterpretationContext;
25  
26  public class ParamModelHandler extends ModelHandlerBase {
27  
28      private final BeanDescriptionCache beanDescriptionCache;
29  
30      public ParamModelHandler(Context context, BeanDescriptionCache beanDescriptionCache) {
31          super(context);
32          this.beanDescriptionCache = beanDescriptionCache;
33      }
34  
35      static public ModelHandlerBase makeInstance(Context context, ModelInterpretationContext ic) {
36          return new ParamModelHandler(context, ic.getBeanDescriptionCache());
37      }
38  
39      @Override
40      protected Class<ParamModel> getSupportedModelClass() {
41          return ParamModel.class;
42      }
43  
44      @Override
45      public void handle(ModelInterpretationContext mic, Model model) throws ModelHandlerException {
46  
47          ParamModel paramModel = (ParamModel) model;
48  
49          String valueStr = mic.subst(paramModel.getValue());
50  
51          Object o = mic.peekObject();
52  
53          PropertySetter propSetter = new PropertySetter(beanDescriptionCache, o);
54          propSetter.setContext(context);
55  
56          // allow for variable substitution for name as well
57          String finalName = mic.subst(paramModel.getName());
58          propSetter.setProperty(finalName, valueStr);
59      }
60  
61  }