SystemPropertiesReader.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */

  20. package org.openspcoop2.pdd.core.dynamic;

  21. import org.openspcoop2.core.config.Property;
  22. import org.openspcoop2.core.config.SystemProperties;
  23. import org.openspcoop2.pdd.config.ConfigurazionePdDManager;
  24. import org.openspcoop2.protocol.sdk.state.RequestInfo;
  25. import org.slf4j.Logger;

  26. /**
  27.  * SystemPropertiesReader
  28.  *
  29.  * @author Andrea Poli (apoli@link.it)
  30.  * @author $Author$
  31.  * @version $Rev$, $Date$
  32.  */
  33. public class SystemPropertiesReader extends PropertiesReader {
  34.    
  35.     private SystemProperties systemProperties;
  36.    
  37.     public SystemPropertiesReader(Logger log, RequestInfo requestInfo, boolean initFromJmx) throws DynamicException{
  38.         super(log);
  39.         try {
  40.             if(ConfigurazionePdDManager.getInstance()!=null && ConfigurazionePdDManager.getInstance().isInitializedConfigurazionePdDReader()) {
  41.                 if(initFromJmx) {
  42.                     this.systemProperties = ConfigurazionePdDManager.getInstance().getSystemPropertiesPdDNoCached(true);
  43.                 }
  44.                 else {
  45.                     this.systemProperties = ConfigurazionePdDManager.getInstance().getSystemPropertiesPdDCached(requestInfo);
  46.                 }
  47.             }
  48.         }catch(Exception e) {
  49.             throw new DynamicException(e.getMessage(),e);
  50.         }      
  51.     }
  52.        
  53.     @Override
  54.     public String read(String nome) throws DynamicException{
  55.         if(this.systemProperties==null || this.systemProperties.sizeSystemPropertyList()<=0) {
  56.             return null;
  57.         }
  58.         for (Property p : this.systemProperties.getSystemPropertyList()) {
  59.             if(p!=null && p.getNome()!=null && p.getNome().equalsIgnoreCase(nome)) {
  60.                 return p.getValore();
  61.             }
  62.         }
  63.         return null;
  64.     }
  65.    
  66. }