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).

1  
sclass BEAUtils {
2  
  Map<S, Class<? extends BEAObject>> beaClasses = calcBEAClasses();
3  
  
4  
  Map<S, Class<? extends BEAObject>> beaClasses() {
5  
    ret beaClasses if null = calcBEAClasses();
6  
  }
7  
  
8  
  // e.g. "Input" => BInput
9  
  Map<S, Class<? extends BEAObject>> calcBEAClasses() {
10  
    ret ciMapToKeys(c -> dropPrefix("B", shortClassName(c)),
11  
      listMinusItem(BEAObject, myNonAbstractClassesImplementing(BEAObject)));
12  
  }
13  
  
14  
  Class<? extends BEAObject> defaultCustomClass(BEAObject o) {
15  
    ret beaClasses().get(o.type());
16  
  }
17  
  
18  
  <A extends BEAObject> A migrateConceptToClass(Class<A> c, BEAObject in) {
19  
    A out = unlisted(c);
20  
    for (S field : conceptFields(in)) try {
21  
      continue if eq(field, "type");
22  
      cset(out, field, cget(in, field));
23  
      // TODO: check Ref types
24  
    } catch e {
25  
      fail("Can't convert field " + field, e);
26  
    }
27  
    ret out;
28  
  }
29  
  
30  
  BEAObject autoMigrate(BEAObject o) {
31  
    pcall {
32  
      Class<? extends BEAObject> targetClass = defaultCustomClass(o);
33  
      printVars_str(+o, +targetClass);
34  
      if (targetClass != null && targetClass != _getClass(o))
35  
        ret replaceConceptAndUpdateRefs(o, migrateConceptToClass(targetClass, o));
36  
    }
37  
    ret o;
38  
  }
39  
}

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: 207 / 435
Version history: 4 change(s)
Referenced in: [show references]