11package org .hisrc .jsonix .compilation .jsc ;
22
3+ import org .apache .commons .lang3 .Validate ;
4+ import org .hisrc .jsonix .compilation .MappingCompiler ;
5+ import org .hisrc .jsonix .definition .Mapping ;
6+ import org .hisrc .jsonix .definition .Module ;
7+ import org .hisrc .jsonix .definition .Modules ;
38import org .hisrc .jsonix .jsonschema .JsonSchemaBuilder ;
9+ import org .hisrc .jsonschema .model .v4 .keyword .Keywords ;
410import org .jvnet .jaxb2_commons .xml .bind .model .MBuiltinLeafInfo ;
511import org .jvnet .jaxb2_commons .xml .bind .model .MClassInfo ;
612import org .jvnet .jaxb2_commons .xml .bind .model .MClassRef ;
915import org .jvnet .jaxb2_commons .xml .bind .model .MIDREF ;
1016import org .jvnet .jaxb2_commons .xml .bind .model .MIDREFS ;
1117import org .jvnet .jaxb2_commons .xml .bind .model .MList ;
18+ import org .jvnet .jaxb2_commons .xml .bind .model .MPackagedTypeInfo ;
1219import org .jvnet .jaxb2_commons .xml .bind .model .MTypeInfoVisitor ;
1320import org .jvnet .jaxb2_commons .xml .bind .model .MWildcardTypeInfo ;
1421
1522public class JsonSchemaRefTypeInfoCompilerVisitor <T , C extends T > implements
1623 MTypeInfoVisitor <T , C , JsonSchemaBuilder > {
1724
25+ private final JsonSchemaMappingCompiler <T , C > mappingCompiler ;
26+ private final Modules <T , C > modules ;
27+ private final Module <T , C > module ;
28+ private final Mapping <T , C > mapping ;
29+
30+ public JsonSchemaRefTypeInfoCompilerVisitor (
31+ JsonSchemaMappingCompiler <T , C > mappingCompiler ) {
32+ Validate .notNull (mappingCompiler );
33+ this .mappingCompiler = mappingCompiler ;
34+ this .modules = mappingCompiler .getModules ();
35+ this .module = mappingCompiler .getModule ();
36+ this .mapping = mappingCompiler .getMapping ();
37+ }
38+
39+ public JsonSchemaMappingCompiler <T , C > getMappingCompiler () {
40+ return mappingCompiler ;
41+ }
42+
43+ public Modules <T , C > getModules () {
44+ return modules ;
45+ }
46+
47+ public Mapping <T , C > getMapping () {
48+ return mapping ;
49+ }
50+
1851 @ Override
1952 public JsonSchemaBuilder visitClassInfo (MClassInfo <T , C > info ) {
20- throw new UnsupportedOperationException ( );
53+ return createTypeInfoSchemaRef ( info );
2154 }
2255
2356 @ Override
2457 public JsonSchemaBuilder visitClassRef (MClassRef <T , C > info ) {
25- throw new UnsupportedOperationException ( );
58+ return createTypeInfoSchemaRef ( info );
2659 }
2760
2861 @ Override
2962 public JsonSchemaBuilder visitList (MList <T , C > info ) {
30- throw new UnsupportedOperationException ();
63+ return new JsonSchemaBuilder ().addType ("array" ).addItem (
64+ info .getItemTypeInfo ().acceptTypeInfoVisitor (this ));
3165 }
3266
3367 @ Override
@@ -52,11 +86,26 @@ public JsonSchemaBuilder visitBuiltinLeafInfo(MBuiltinLeafInfo<T, C> info) {
5286
5387 @ Override
5488 public JsonSchemaBuilder visitEnumLeafInfo (MEnumLeafInfo <T , C > info ) {
55- throw new UnsupportedOperationException ( );
89+ return createTypeInfoSchemaRef ( info );
5690 }
5791
5892 @ Override
5993 public JsonSchemaBuilder visitWildcardTypeInfo (MWildcardTypeInfo <T , C > info ) {
6094 throw new UnsupportedOperationException ();
6195 }
96+
97+ private JsonSchemaBuilder createTypeInfoSchemaRef (
98+ MPackagedTypeInfo <T , C > info ) {
99+
100+ final String typeInfoSchemaId = getModules ().getSchemaId (
101+ info .getPackageInfo ().getPackageName ());
102+ final String mappingSchemaId = typeInfoSchemaId .equals (getMapping ()
103+ .getSchemaId ()) ? "" : typeInfoSchemaId ;
104+ final String typeInfoRef = mappingSchemaId
105+ + "/"
106+ + Keywords .definitions
107+ + "/"
108+ + info .getContainerLocalName (MappingCompiler .DEFAULT_SCOPED_NAME_DELIMITER );
109+ return new JsonSchemaBuilder ().addRef (typeInfoRef );
110+ }
62111}
0 commit comments