def codegen(lang,             <EOL>i,                <EOL>schema_metadata,  <EOL>loader            <EOL>):  
j = schema.extend_and_specialize(i, loader)<EOL>gen = None  <EOL>if lang == "<STR_LIT>":<EOL><INDENT>gen = PythonCodeGen(sys.stdout)<EOL><DEDENT>elif lang == "<STR_LIT>":<EOL><INDENT>gen = JavaCodeGen(schema_metadata.get("<STR_LIT>", schema_metadata.get("<STR_LIT:id>")))<EOL><DEDENT>else:<EOL><INDENT>raise Exception("<STR_LIT>" % lang)<EOL><DEDENT>assert gen is not None<EOL>gen.prologue()<EOL>document_roots = []<EOL>for rec in j:<EOL><INDENT>if rec["<STR_LIT:type>"] in ("<STR_LIT>", "<STR_LIT>"):<EOL><INDENT>gen.type_loader(rec)<EOL>gen.add_vocab(shortname(rec["<STR_LIT:name>"]), rec["<STR_LIT:name>"])<EOL><DEDENT><DEDENT>for rec in j:<EOL><INDENT>if rec["<STR_LIT:type>"] == "<STR_LIT>":<EOL><INDENT>for symbol in rec["<STR_LIT>"]:<EOL><INDENT>gen.add_vocab(shortname(symbol), symbol)<EOL><DEDENT><DEDENT>if rec["<STR_LIT:type>"] == "<STR_LIT>":<EOL><INDENT>if rec.get("<STR_LIT>"):<EOL><INDENT>document_roots.append(rec["<STR_LIT:name>"])<EOL><DEDENT>field_names = []<EOL>for field in rec.get("<STR_LIT>", []):<EOL><INDENT>field_names.append(shortname(field["<STR_LIT:name>"]))<EOL><DEDENT>idfield = "<STR_LIT>"<EOL>for field in rec.get("<STR_LIT>", []):<EOL><INDENT>if field.get("<STR_LIT>") == "<STR_LIT>":<EOL><INDENT>idfield = field.get("<STR_LIT:name>")<EOL><DEDENT><DEDENT>gen.begin_class(rec["<STR_LIT:name>"], aslist(rec.get("<STR_LIT>", [])), rec.get("<STR_LIT>", "<STR_LIT>"),<EOL>rec.get("<STR_LIT>", False), field_names, idfield)<EOL>gen.add_vocab(shortname(rec["<STR_LIT:name>"]), rec["<STR_LIT:name>"])<EOL>for field in rec.get("<STR_LIT>", []):<EOL><INDENT>if field.get("<STR_LIT>") == "<STR_LIT>":<EOL><INDENT>fieldpred = field["<STR_LIT:name>"]<EOL>optional = bool("<STR_LIT>" in field["<STR_LIT:type>"])<EOL>uri_loader = gen.uri_loader(gen.type_loader(field["<STR_LIT:type>"]), True, False, None)<EOL>gen.declare_id_field(fieldpred, uri_loader, field.get("<STR_LIT>"), optional)<EOL>break<EOL><DEDENT><DEDENT>for field in rec.get("<STR_LIT>", []):<EOL><INDENT>optional = bool("<STR_LIT>" in field["<STR_LIT:type>"])<EOL>type_loader = gen.type_loader(field["<STR_LIT:type>"])<EOL>jld = field.get("<STR_LIT>")<EOL>fieldpred = field["<STR_LIT:name>"]<EOL>if isinstance(jld, MutableMapping):<EOL><INDENT>ref_scope = jld.get("<STR_LIT>")<EOL>if jld.get("<STR_LIT>"):<EOL><INDENT>type_loader = gen.typedsl_loader(type_loader, ref_scope)<EOL><DEDENT>elif jld.get("<STR_LIT>") == "<STR_LIT>":<EOL><INDENT>type_loader = gen.uri_loader(type_loader, jld.get("<STR_LIT>", False),<EOL>False, ref_scope)<EOL><DEDENT>elif jld.get("<STR_LIT>") == "<STR_LIT>":<EOL><INDENT>type_loader = gen.uri_loader(type_loader, False, True, ref_scope)<EOL><DEDENT>map_subject = jld.get("<STR_LIT>")<EOL>if map_subject:<EOL><INDENT>type_loader = gen.idmap_loader(<EOL>field["<STR_LIT:name>"], type_loader, map_subject, jld.get("<STR_LIT>"))<EOL><DEDENT>if "<STR_LIT>" in jld and jld["<STR_LIT>"][<NUM_LIT:0>] != "<STR_LIT:@>":<EOL><INDENT>fieldpred = jld["<STR_LIT>"]<EOL><DEDENT><DEDENT>if jld == "<STR_LIT>":<EOL><INDENT>continue<EOL><DEDENT>gen.declare_field(fieldpred, type_loader, field.get("<STR_LIT>"), optional)<EOL><DEDENT>gen.end_class(rec["<STR_LIT:name>"], field_names)<EOL><DEDENT><DEDENT>root_type = list(document_roots)<EOL>root_type.append({<EOL>"<STR_LIT:type>": "<STR_LIT>",<EOL>"<STR_LIT>": document_roots<EOL>})<EOL>gen.epilogue(gen.type_loader(root_type))<EOL>
Generate classes with loaders for the given Schema Salad description.