def _generate_event_dto(msg, model): msg_java_name_upper = msg.java_name_upper # Negative retval is mapped to java exception, so filter it out: fields = filter(lambda field: not is_retval(field), msg.fields) return _EVENT_TEMPLATE.substitute( plugin_package=model.plugin_package, json_filename=model.json_api_files, json_definition=msg.doc, class_name=msg_java_name_upper, fields=generate_fields(fields), hash_code=generate_hash_code(fields), equals=generate_equals(msg_java_name_upper, fields), to_string=generate_to_string(msg_java_name_upper, fields))
def _generate_request_dto(msg, model, base_type): msg_java_name_upper = msg.java_name_upper fields = msg.fields return _REQUEST_TEMPLATE.substitute( plugin_package=model.plugin_package, json_filename=model.json_api_files, json_definition=msg.doc, class_name=msg_java_name_upper, base_type=base_type, fields=generate_fields(fields), hash_code=generate_hash_code(fields), equals=generate_equals(msg_java_name_upper, fields), to_string=generate_to_string(msg_java_name_upper, fields), send=_generate_send(model, msg))
def generate_types(work_dir, model, logger): logger.debug("Generating custom types for %s " % model.json_api_files) for t in model.types: if not isinstance(t, Class): continue logger.debug("Generating DTO for type %s", t) type_class_name = t.java_name fields = t.fields type_class = _TYPE_TEMPLATE.substitute( plugin_package=model.plugin_package, c_type_name=t.name, json_filename=model.json_api_files, json_definition=t.doc, java_type_name=type_class_name, fields=generate_fields(fields), hash_code=generate_hash_code(fields), equals=generate_equals(type_class_name, fields), to_string=generate_to_string(type_class_name, fields)) with open("%s/%s.java" % (work_dir, type_class_name), "w") as f: f.write(type_class)
def generate_unions(work_dir, model, logger): logger.debug("Generating unions for %s " % model.json_api_files) for t in model.types: if not isinstance(t, Union): continue logger.debug("Generating DTO for union %s", t) java_union_name = t.java_name fields = t.fields type_class = _UNION_TEMPLATE.substitute( plugin_package=model.plugin_package, c_type_name=t.name, json_filename=model.json_api_files, json_definition=t.doc, java_union_name=java_union_name, fields=generate_fields(fields, access_modifier="private"), constructors=_generate_constructors(java_union_name, fields), getters=_generate_getters(fields), hash_code=generate_hash_code(fields), equals=generate_equals(java_union_name, fields), to_string=generate_to_string(java_union_name, fields)) with open("%s/%s.java" % (work_dir, java_union_name), "w") as f: f.write(type_class)