Пример #1
0
  @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;
  }
  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);
      }
    }
  }