コード例 #1
0
  public void setMetaClass(Object obj, MetaClass theMetaClass) {
    Class theClass = obj.getClass();
    final ClassInfo info = ClassInfo.getClassInfo(theClass);
    MetaClass oldMC = null;
    info.lock();
    try {
      oldMC = info.getPerInstanceMetaClass(obj);
      info.setPerInstanceMetaClass(obj, theMetaClass);
    } finally {
      info.unlock();
    }

    fireConstantMetaClassUpdate(obj, theClass, oldMC, theMetaClass);
  }
コード例 #2
0
  /**
   * if oldMc is null, newMc will replace whatever meta class was used before. if oldMc is not null,
   * then newMc will be used only if he stored mc is the same as oldMc
   */
  private void setMetaClass(Class theClass, MetaClass oldMc, MetaClass newMc) {
    final ClassInfo info = ClassInfo.getClassInfo(theClass);

    MetaClass mc = null;
    info.lock();
    try {
      mc = info.getStrongMetaClass();
      info.setStrongMetaClass(newMc);
    } finally {
      info.unlock();
    }
    if ((oldMc == null && mc != newMc) || (oldMc != null && mc != newMc && mc != oldMc)) {
      fireConstantMetaClassUpdate(null, theClass, mc, newMc);
    }
  }