Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

39
LINES

< > BotCompany Repo | #1030766 // BEAUtils

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (15280L/98K).

sclass BEAUtils {
  Map<S, Class<? extends BEAObject>> beaClasses = calcBEAClasses();
  
  Map<S, Class<? extends BEAObject>> beaClasses() {
    ret beaClasses if null = calcBEAClasses();
  }
  
  // e.g. "Input" => BInput
  Map<S, Class<? extends BEAObject>> calcBEAClasses() {
    ret ciMapToKeys(c -> dropPrefix("B", shortClassName(c)),
      listMinusItem(BEAObject, myNonAbstractClassesImplementing(BEAObject)));
  }
  
  Class<? extends BEAObject> defaultCustomClass(BEAObject o) {
    ret beaClasses().get(o.type());
  }
  
  <A extends BEAObject> A migrateConceptToClass(Class<A> c, BEAObject in) {
    A out = unlisted(c);
    for (S field : conceptFields(in)) try {
      continue if eq(field, "type");
      cset(out, field, cget(in, field));
      // TODO: check Ref types
    } catch e {
      fail("Can't convert field " + field, e);
    }
    ret out;
  }
  
  BEAObject autoMigrate(BEAObject o) {
    pcall {
      Class<? extends BEAObject> targetClass = defaultCustomClass(o);
      printVars_str(+o, +targetClass);
      if (targetClass != null && targetClass != _getClass(o))
        ret replaceConceptAndUpdateRefs(o, migrateConceptToClass(targetClass, o));
    }
    ret o;
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt

No comments. add comment

Snippet ID: #1030766
Snippet name: BEAUtils
Eternal ID of this version: #1030766/5
Text MD5: b721a3aff8d050f24107cff81ba440cd
Transpilation MD5: 7bd7e116c149546194424a6c74a58355
Author: stefan
Category: javax / Gazelle BEA
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-03-19 17:19:29
Source code size: 1239 bytes / 39 lines
Pitched / IR pitched: No / No
Views / Downloads: 206 / 434
Version history: 4 change(s)
Referenced in: [show references]