コード例 #1
0
ファイル: SingletonScope.java プロジェクト: GEFFROY/Quercus
  @Override
  protected <T> T create(Contextual<T> bean, CreationalContext<T> env) {
    T instance = super.create(bean, env);

    if ((instance instanceof HandleAware) && (bean instanceof PassivationCapable)) {
      HandleAware handleAware = (HandleAware) instance;
      PassivationCapable passiveBean = (PassivationCapable) bean;

      handleAware.setSerializationHandle(new SingletonHandle(passiveBean.getId()));
    }

    return instance;
  }
コード例 #2
0
  public static void setHandle(Object obj, Object handle) {
    if (obj instanceof HandleAware) {
      ((HandleAware) obj).setSerializationHandle(handle);
    } else {
      try {
        Class cl = obj.getClass();

        for (Field field : cl.getDeclaredFields()) {
          if (field.getName().equals("__caucho_handle")) {
            field.setAccessible(true);
            field.set(obj, handle);
          }
        }
      } catch (Exception e) {
        throw ConfigException.create(e);
      }
    }
  }