bean.sbn 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. {{~if __namespace_with_top_module != ''~}}
  2. package {{__namespace_with_top_module}};
  3. {{~end~}}
  4. import luban.*;
  5. import com.google.gson.JsonElement;
  6. import com.google.gson.JsonObject;
  7. {{~
  8. parent_def_type = __this.parent_def_type
  9. export_fields = __this.export_fields
  10. hierarchy_export_fields = __this.hierarchy_export_fields
  11. ~}}
  12. {{~if __this.comment != '' ~}}
  13. /**
  14. * {{escape_comment __this.comment}}
  15. */
  16. {{~end~}}
  17. public {{class_modifier __this}} class {{__name}} extends {{if parent_def_type}}{{__this.parent_def_type.full_name_with_top_module}}{{else}}AbstractBean{{end}} {
  18. public {{__name}}(JsonObject _buf) {
  19. {{~if parent_def_type~}}
  20. super(_buf);
  21. {{~end~}}
  22. {{~ for field in export_fields ~}}
  23. {{deserialize_field (format_field_name __code_style field.name) '_buf' field.name field.ctype}}
  24. {{~end~}}
  25. }
  26. public static {{__name}} deserialize(JsonObject _buf) {
  27. {{~if __this.is_abstract_type~}}
  28. switch (_buf.get("$type").getAsString()) {
  29. {{~for child in __this.hierarchy_not_abstract_children~}}
  30. case "{{impl_data_type child __this}}": return new {{child.full_name_with_top_module}}(_buf);
  31. {{~end~}}
  32. default: throw new SerializationException();
  33. }
  34. {{~else~}}
  35. return new {{__this.full_name_with_top_module}}(_buf);
  36. {{~end~}}
  37. }
  38. {{~ for field in export_fields ~}}
  39. {{~if field.comment != '' ~}}
  40. /**
  41. * {{escape_comment field.comment}}
  42. */
  43. {{~end~}}
  44. public final {{declaring_type_name field.ctype}} {{format_field_name __code_style field.name}};
  45. {{~end~}}
  46. {{~if !__this.is_abstract_type~}}
  47. public static final int __ID__ = {{__this.id}};
  48. @Override
  49. public int getTypeId() { return __ID__; }
  50. {{~end~}}
  51. @Override
  52. public String toString() {
  53. return "{{full_name}}{ "
  54. {{~for field in hierarchy_export_fields ~}}
  55. + "{{format_field_name __code_style field.name}}:" + {{format_field_name __code_style field.name}} + ","
  56. {{~end~}}
  57. + "}";
  58. }
  59. }