예제 #1
0
 /**
  * 供DWR框架调用获得Bean
  *
  * @param beanName
  * @return
  */
 public static Object getBeanOfDwr(String beanName) {
   try {
     ServerContext ctx = ServerContextFactory.get();
     if (ctx == null) {
       LOG.warn("ServerContext[ServerContextFactory.get()] is null.");
       return null;
     }
     Container container = ctx.getContainer();
     return container.getBean(beanName);
   } catch (Exception e) {
     LOG.error(e.getMessage(), e);
   }
   return null;
 }
예제 #2
0
 /**
  * Get an boolean setting from the Container.
  *
  * @param container The container to look into
  * @param name The name of the setting to investigate
  * @param defaultValue The value to return if none is given
  * @return The value of the setting as an boolean, or the defaultValue if the setting is empty or
  *     not convertible.
  */
 public static boolean getBooleanSetting(Container container, String name, boolean defaultValue) {
   Object value = container.getBean(name);
   if (value == null) {
     return defaultValue;
   }
   return Boolean.parseBoolean(value.toString());
 }
예제 #3
0
  /**
   * Get an integer setting from the Container.
   *
   * @param container The container to look into
   * @param name The name of the setting to investigate
   * @param defaultValue The value to return if none is given
   * @return The value of the setting as an int, or the defaultValue if the setting is empty or not
   *     convertible.
   */
  public static int getIntSetting(Container container, String name, int defaultValue) {
    Object value = container.getBean(name);
    if (value == null) {
      return defaultValue;
    }

    try {
      return Integer.parseInt(value.toString());
    } catch (NumberFormatException ex) {
      log.warn(
          "Failed to convert value '"
              + value
              + "' from setting '"
              + name
              + "' to an integer: "
              + ex.getMessage());
      return defaultValue;
    }
  }