3 # Copyright (c) 2016,2018 Cisco and/or its affiliates.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at:
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 from string import Template
17 from jvpp_common_gen import generate_hash_code, generate_equals, generate_to_string, generate_fields
18 from jvpp_model import Class
21 def generate_types(work_dir, model, logger):
22 logger.debug("Generating custom types for %s " % model.json_api_files)
25 if not isinstance(t, Class):
27 logger.debug("Generating DTO for type %s", t)
28 type_class_name = t.java_name
30 type_class = _TYPE_TEMPLATE.substitute(
31 plugin_package=model.plugin_package,
33 json_filename=model.json_api_files,
34 json_definition=t.doc,
35 java_type_name=type_class_name,
36 fields=generate_fields(fields),
37 hash_code=generate_hash_code(fields),
38 equals=generate_equals(type_class_name, fields),
39 to_string=generate_to_string(type_class_name, fields)
41 with open("%s/%s.java" % (work_dir, type_class_name), "w") as f:
44 _TYPE_TEMPLATE = Template("""
45 package $plugin_package.types;
48 * <p>This class represents $c_type_name type definition.
49 * <br>It was generated by jvpp_types_gen.py based on $json_filename:
54 public final class $java_type_name {