コード例 #1
0
ファイル: BeanUtil.java プロジェクト: java-proj-2014/JXADF
 /**
  * 供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
ファイル: ContainerUtil.java プロジェクト: rongbo-j/dwr
 /**
  * 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
ファイル: ContainerUtil.java プロジェクト: rongbo-j/dwr
  /**
   * 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;
    }
  }