⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 globalsettings.java

📁 一个javabean的转换与copy非常的好用希望大家好好研究一下
💻 JAVA
字号:
/*
 * Copyright 2005-2007 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.sf.dozer.util.mapping.config;

import java.io.IOException;
import java.net.URL;
import java.util.Properties;

import org.apache.log4j.Logger;

import net.sf.dozer.util.mapping.MappingException;
import net.sf.dozer.util.mapping.util.InitLogger;
import net.sf.dozer.util.mapping.util.Loader;
import net.sf.dozer.util.mapping.util.MapperConstants;
import net.sf.dozer.util.mapping.util.MappingUtils;

/**
 * @author tierney.matt
 */
public class GlobalSettings {
  
  private static final Logger log = Logger.getLogger(GlobalSettings.class);
  private static GlobalSettings singleton;

  private final Settings settings;
  private String loadedByFileName;

  public static synchronized GlobalSettings getInstance() {
    if (singleton == null) {
      singleton = new GlobalSettings();
    }
    return singleton;
  }
  
  protected static GlobalSettings createNew() {
    return new GlobalSettings();
  }
  
  private GlobalSettings() {
    settings = loadSettings();
  }

  public Settings getSettings() {
    return settings;
  }
  
  protected String getLoadedByFileName() {
    return loadedByFileName;
  }

  private synchronized Settings loadSettings() {
    Settings result = new Settings();
    MappingUtils utils = new MappingUtils();    

    //Determine prop file name
    String propFileName = System.getProperty(MapperConstants.CONFIG_FILE_SYS_PROP);
    if (utils.isBlankOrNull(propFileName)) {
      propFileName = MapperConstants.DEFAULT_CONFIG_FILE;
    }

    InitLogger.log(log,"Trying to find configuration file: " + propFileName);
    //Load prop file.  Prop file is optional, so if it's not found just use defaults
    Loader loader = new Loader();
    URL url = loader.getResource(propFileName);
    if (url == null) {
      InitLogger.log(log,"Configuration file not found: " + propFileName + ".  Using defaults for all global properties.");
      return result;
    } else {
      InitLogger.log(log,"Using URL [" + url + "] for global property configuration");
    }
    
    Properties props = new Properties();
    try {
      InitLogger.log(log,"Reading properties from URL [" + url + "]");
      props.load(url.openStream());
    } catch (IOException e) {
      throw new MappingException("Problem loading properties from URL [" + propFileName + "]", e);
    }
    
    //Populate settings from loaded properties
    SettingsHelper.populateSettingsFromProperties(result, props);
    loadedByFileName = propFileName;
    InitLogger.log(log,"Finished configuring global properties");    
    
    return result;
  }
  
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -