View Javadoc
1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2015, 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 v1.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  package ch.qos.logback.classic.joran.action;
15  
16  import org.xml.sax.Attributes;
17  
18  import ch.qos.logback.core.joran.action.BaseModelAction;
19  import ch.qos.logback.core.joran.action.PreconditionValidator;
20  import ch.qos.logback.core.joran.spi.SaxEventInterpretationContext;
21  import ch.qos.logback.core.model.InsertFromJNDIModel;
22  import ch.qos.logback.core.model.Model;
23  
24  /**
25   * Insert an env-entry found in JNDI as a new context variable
26   * 
27   * @author Ceki Gulcu
28   *
29   */
30  public class InsertFromJNDIAction extends BaseModelAction {
31  
32      public static final String ENV_ENTRY_NAME_ATTR = "env-entry-name";
33      public static final String AS_ATTR = "as";
34  
35      @Override
36      protected Model buildCurrentModel(SaxEventInterpretationContext interpretationContext, String name,
37              Attributes attributes) {
38          InsertFromJNDIModel ifjm = new InsertFromJNDIModel();
39          ifjm.setEnvEntryName(attributes.getValue(ENV_ENTRY_NAME_ATTR));
40          ifjm.setAs(attributes.getValue(AS_ATTR));
41          ifjm.setScopeStr(attributes.getValue(SCOPE_ATTRIBUTE));
42  
43          return ifjm;
44      }
45  
46      @Override
47      protected boolean validPreconditions(SaxEventInterpretationContext seic, String name, Attributes attributes) {
48          PreconditionValidator validator = new PreconditionValidator(this, seic, name, attributes);
49          validator.generic(ENV_ENTRY_NAME_ATTR);
50          validator.generic(AS_ATTR);
51  
52          return validator.isValid();
53      }
54  
55  }