File tree Expand file tree Collapse file tree 9 files changed +240
-0
lines changed
asf/java/ui/schema/decorator Expand file tree Collapse file tree 9 files changed +240
-0
lines changed Original file line number Diff line number Diff line change 1+ package io .asf .java .ui .schema .decorator ;
2+
3+ import com .fasterxml .jackson .databind .BeanProperty ;
4+ import com .fasterxml .jackson .module .jsonSchema .JsonSchema ;
5+ import com .fasterxml .jackson .module .jsonSchema .types .StringSchema ;
6+
7+ import io .asfjava .ui .core .form .CheckBox ;
8+
9+ public class CheckBoxSchemaDecorator implements SchemaDecorator {
10+
11+ @ Override
12+ public void customizeSchema (BeanProperty property , JsonSchema jsonschema ) {
13+ CheckBox annotation = property .getAnnotation (CheckBox .class );
14+ if (annotation != null && annotation .title () != null ) {
15+ ((StringSchema ) jsonschema ).setTitle (annotation .title ());
16+ }
17+ }
18+
19+ @ Override
20+ public String getAnnotation () {
21+ return CheckBox .class .getName ();
22+ }
23+
24+ }
Original file line number Diff line number Diff line change 1+ package io .asf .java .ui .schema .decorator ;
2+
3+ import com .fasterxml .jackson .databind .BeanProperty ;
4+ import com .fasterxml .jackson .module .jsonSchema .JsonSchema ;
5+ import com .fasterxml .jackson .module .jsonSchema .types .StringSchema ;
6+
7+ import io .asfjava .ui .core .form .ComboBox ;
8+
9+ public class ComboBoxSchemaDecorator implements SchemaDecorator {
10+
11+ @ Override
12+ public void customizeSchema (BeanProperty property , JsonSchema jsonschema ) {
13+ ComboBox annotation = property .getAnnotation (ComboBox .class );
14+ if (annotation != null && annotation .title () != null ) {
15+ ((StringSchema ) jsonschema ).setTitle (annotation .title ());
16+ }
17+ }
18+
19+ @ Override
20+ public String getAnnotation () {
21+ return ComboBox .class .getName ();
22+ }
23+
24+ }
Original file line number Diff line number Diff line change 1+ package io .asf .java .ui .schema .decorator ;
2+
3+ import com .fasterxml .jackson .databind .BeanProperty ;
4+ import com .fasterxml .jackson .module .jsonSchema .JsonSchema ;
5+ import com .fasterxml .jackson .module .jsonSchema .types .StringSchema ;
6+
7+ import io .asfjava .ui .core .form .Password ;
8+
9+ public class PasswordSchemaDecorator implements SchemaDecorator {
10+
11+ @ Override
12+ public void customizeSchema (BeanProperty property , JsonSchema jsonschema ) {
13+ Password annotation = property .getAnnotation (Password .class );
14+ if (annotation != null && annotation .title () != null ) {
15+ ((StringSchema ) jsonschema ).setTitle (annotation .title ());
16+ }
17+ }
18+
19+ @ Override
20+ public String getAnnotation () {
21+ return Password .class .getName ();
22+ }
23+
24+ }
Original file line number Diff line number Diff line change 1+ package io .asf .java .ui .schema .decorator ;
2+
3+ import com .fasterxml .jackson .databind .BeanProperty ;
4+ import com .fasterxml .jackson .module .jsonSchema .JsonSchema ;
5+ import com .fasterxml .jackson .module .jsonSchema .types .StringSchema ;
6+
7+ import io .asfjava .ui .core .form .Password ;
8+ import io .asfjava .ui .core .form .RadioBox ;
9+
10+ public class RadioBoxSchemaDecorator implements SchemaDecorator {
11+
12+ @ Override
13+ public void customizeSchema (BeanProperty property , JsonSchema jsonschema ) {
14+ RadioBox annotation = property .getAnnotation (RadioBox .class );
15+ if (annotation != null && annotation .title () != null ) {
16+ ((StringSchema ) jsonschema ).setTitle (annotation .title ());
17+ }
18+ }
19+
20+ @ Override
21+ public String getAnnotation () {
22+ return RadioBox .class .getName ();
23+ }
24+
25+ }
Original file line number Diff line number Diff line change 1+ package io .asf .java .ui .schema .decorator ;
2+
3+ import com .fasterxml .jackson .databind .BeanProperty ;
4+ import com .fasterxml .jackson .module .jsonSchema .JsonSchema ;
5+
6+ public interface SchemaDecorator {
7+
8+ void customizeSchema (BeanProperty property ,JsonSchema jsonschema );
9+ String getAnnotation ();
10+ }
Original file line number Diff line number Diff line change 1+ package io .asf .java .ui .schema .decorator ;
2+
3+ import com .fasterxml .jackson .databind .BeanProperty ;
4+ import com .fasterxml .jackson .module .jsonSchema .JsonSchema ;
5+ import com .fasterxml .jackson .module .jsonSchema .types .StringSchema ;
6+
7+ import io .asfjava .ui .core .form .TextArea ;
8+
9+ public class TextAreaSchemaDecorator implements SchemaDecorator {
10+
11+ @ Override
12+ public void customizeSchema (BeanProperty property , JsonSchema jsonschema ) {
13+ TextArea annotation = property .getAnnotation (TextArea .class );
14+ if (annotation != null && annotation .title () != null ) {
15+ ((StringSchema ) jsonschema ).setTitle (annotation .title ());
16+ }
17+ }
18+
19+ @ Override
20+ public String getAnnotation () {
21+ return TextArea .class .getName ();
22+ }
23+
24+ }
Original file line number Diff line number Diff line change 1+ package io .asf .java .ui .schema .decorator ;
2+
3+ import com .fasterxml .jackson .databind .BeanProperty ;
4+ import com .fasterxml .jackson .module .jsonSchema .JsonSchema ;
5+ import com .fasterxml .jackson .module .jsonSchema .types .StringSchema ;
6+
7+ import io .asfjava .ui .core .form .TextField ;
8+
9+ public class TextFieldSchemaDecorator implements SchemaDecorator {
10+
11+ @ Override
12+ public void customizeSchema (BeanProperty property , JsonSchema jsonschema ) {
13+ TextField annotation = property .getAnnotation (TextField .class );
14+ if (annotation != null ) {
15+ if (annotation .title ()!=null ){
16+ ((StringSchema ) jsonschema ).setTitle (annotation .title ());
17+ }
18+ if (annotation .pattern ()!=null )
19+ {
20+ ((StringSchema ) jsonschema ).setPattern (annotation .pattern ());
21+ }
22+ }
23+ }
24+
25+ @ Override
26+ public String getAnnotation () {
27+ return TextField .class .getName ();
28+ }
29+
30+ }
Original file line number Diff line number Diff line change 1+ package io .asfjava .ui .core ;
2+
3+ import java .util .Map ;
4+ import java .util .concurrent .ConcurrentHashMap ;
5+
6+ import io .asf .java .ui .schema .decorator .SchemaDecorator ;
7+
8+ public final class SchemaDecoratorFactory {
9+ public SchemaDecorator getGenerator (String annotationName ) {
10+ return GENERATORS .get (annotationName );
11+ }
12+
13+ void register (String annotationName , SchemaDecorator generator ) {
14+ GENERATORS .put (annotationName , generator );
15+ }
16+
17+ public static SchemaDecoratorFactory getInstance () {
18+ if (INSTANCE == null ) {
19+ INSTANCE = new SchemaDecoratorFactory ();
20+ }
21+ return INSTANCE ;
22+ }
23+
24+ private static final Map <String , SchemaDecorator > GENERATORS = new ConcurrentHashMap <>();
25+
26+ private static SchemaDecoratorFactory INSTANCE ;
27+
28+ private SchemaDecoratorFactory () {
29+ }
30+ }
Original file line number Diff line number Diff line change 1+ package io .asfjava .ui .core ;
2+
3+ import java .util .Set ;
4+
5+ import org .reflections .Reflections ;
6+
7+ import io .asf .java .ui .schema .decorator .SchemaDecorator ;
8+
9+
10+
11+ final class SchemaDecoratorLoader {
12+
13+ private static final String PACKAGESCAN = "io.asfjava.ui.schema.decorator" ;
14+ private static Reflections reflections = new Reflections (PACKAGESCAN );
15+ void load () {
16+
17+ Set <Class <? extends SchemaDecorator >> subTypes = reflections
18+ .getSubTypesOf (SchemaDecorator .class );
19+ for (Class <? extends SchemaDecorator > subtype : subTypes ) {
20+ SchemaDecorator schemaDecorator ;
21+ try {
22+ schemaDecorator = (SchemaDecorator ) Class .forName (subtype .getName ()).newInstance ();
23+ SchemaDecoratorFactory .getInstance ().register (schemaDecorator .getAnnotation (),
24+ schemaDecorator );
25+ } catch (InstantiationException e ) {
26+ e .printStackTrace ();
27+ } catch (IllegalAccessException e ) {
28+ e .printStackTrace ();
29+ } catch (ClassNotFoundException e ) {
30+ e .printStackTrace ();
31+ }
32+ }
33+ }
34+
35+ void unload () {
36+ System .out .println ("I'm unloader" );
37+ }
38+
39+ static SchemaDecoratorLoader getInstance () {
40+ if (INSTANCE == null )
41+ INSTANCE = new SchemaDecoratorLoader ();
42+ return INSTANCE ;
43+ }
44+
45+ private static SchemaDecoratorLoader INSTANCE ;
46+
47+ private SchemaDecoratorLoader () {
48+ }
49+ }
You can’t perform that action at this time.
0 commit comments