1717
1818import com .google .common .reflect .TypeToken ;
1919import io .adminshell .aas .v3 .dataformat .core .util .MostSpecificTypeTokenComparator ;
20+ import io .adminshell .aas .v3 .model .Qualifier ;
2021import java .lang .reflect .Type ;
2122import java .util .ArrayList ;
2223import java .util .List ;
@@ -31,40 +32,70 @@ public class PropertyNamingStrategy implements NamingStrategy {
3132
3233 protected class TypeSafeFunction <T > {
3334
34- public TypeSafeFunction (Class <T > inputType , BiFunction <T , String , String > provider , boolean applyToRefSemantic ) {
35+ public TypeSafeFunction (Class <T > inputType , BiFunction <T , String , String > nameProvider , BiFunction < T , String , String > refSemanticProvider ) {
3536 this .inputType = TypeToken .of (inputType );
36- this .provider = provider ;
37- this .applyToRefSemantic = applyToRefSemantic ;
37+ this .nameProvider = nameProvider ;
38+ this .refSemanticProvider = refSemanticProvider ;
3839 }
3940 TypeToken inputType ;
40- BiFunction <T , String , String > provider ;
41- boolean applyToRefSemantic ;
41+ BiFunction <T , String , String > nameProvider ;
42+ BiFunction < T , String , String > refSemanticProvider ;
4243 }
4344
44- public <T > void registerCustomNaming (Class <T > type , BiFunction <T , String , String > provider , boolean applyToRefSemantic ) {
45- customNamings .add (new TypeSafeFunction (type , provider , applyToRefSemantic ));
45+ public <T > void registerCustomNaming (Class <T > type ,
46+ BiFunction <T , String , String > nameProvider ) {
47+ customNamings .add (new TypeSafeFunction (type , nameProvider , nameProvider ));
4648 }
4749
48- public void registerCustomNaming (Class <?> type , String oldName , String newName , boolean applyToRefSemantic ) {
49- customNamings .add (new TypeSafeFunction (type , (obj , property ) -> Objects .equals (oldName , property ) ? newName : null , applyToRefSemantic ));
50+ public <T > void registerCustomNaming (Class <T > type ,
51+ BiFunction <T , String , String > nameProvider ,
52+ BiFunction <T , String , String > refSemanticProvider ) {
53+ customNamings .add (new TypeSafeFunction (type , nameProvider , refSemanticProvider ));
5054 }
5155
52- public <T > void registerCustomNaming (Class <T > type , Function <T , String > provider , boolean applyToRefSemantic ) {
53- customNamings .add (new TypeSafeFunction (type , (x , y ) -> provider .apply ((T ) x ), applyToRefSemantic ));
56+ public void registerCustomNaming (Class <?> type ,
57+ String oldName ,
58+ String newName ) {
59+ customNamings .add (new TypeSafeFunction (type ,
60+ (obj , property ) -> Objects .equals (oldName , property ) ? newName : null ,
61+ (obj , property ) -> Objects .equals (oldName , property ) ? newName : null ));
5462 }
5563
56- private List <TypeSafeFunction > getCustomNaming (Type type , String property , boolean applyToRefSemantic ) {
64+ public void registerCustomNaming (Class <?> type ,
65+ String oldName ,
66+ String newName ,
67+ String newRefSemantic ) {
68+ customNamings .add (new TypeSafeFunction (type ,
69+ (obj , property ) -> Objects .equals (oldName , property ) ? newName : null ,
70+ (obj , property ) -> Objects .equals (oldName , property ) ? newRefSemantic : null ));
71+ }
72+
73+ public <T > void registerCustomNaming (Class <T > type ,
74+ Function <T , String > nameProvider ) {
75+ customNamings .add (new TypeSafeFunction (type ,
76+ (x , y ) -> nameProvider .apply ((T ) x ),
77+ (x , y ) -> nameProvider .apply ((T ) x )));
78+ }
79+
80+ public <T > void registerCustomNaming (Class <T > type ,
81+ Function <T , String > nameProvider ,
82+ Function <T , String > refSemanticProvider ) {
83+ customNamings .add (new TypeSafeFunction (type ,
84+ (x , y ) -> nameProvider .apply ((T ) x ),
85+ (x , y ) -> refSemanticProvider .apply ((T ) x )));
86+ }
87+
88+ private List <TypeSafeFunction > getCustomNaming (Type type , String property ) {
5789 return customNamings .stream ()
5890 .filter (x -> x .inputType .isSupertypeOf (type ))
59- .filter (x -> !applyToRefSemantic || x .applyToRefSemantic )
6091 .sorted ((x , y ) -> Objects .compare (x .inputType , y .inputType , new MostSpecificTypeTokenComparator ()))
6192 .collect (Collectors .toList ());
6293 }
6394
6495 @ Override
6596 public String getName (Type type , Object obj , String property ) {
66- for (TypeSafeFunction customNaming : getCustomNaming (type , property , false )) {
67- String result = (String ) customNaming .provider .apply (obj , property );
97+ for (TypeSafeFunction customNaming : getCustomNaming (type , property )) {
98+ String result = (String ) customNaming .nameProvider .apply (obj , property );
6899 if (result != null ) {
69100 return result ;
70101 }
@@ -74,8 +105,11 @@ public String getName(Type type, Object obj, String property) {
74105
75106 @ Override
76107 public String getNameForRefSemantic (Type type , Object obj , String property ) {
77- for (TypeSafeFunction customNaming : getCustomNaming (type , property , true )) {
78- String result = (String ) customNaming .provider .apply (obj , property );
108+ if (Qualifier .class .equals (type ) || property .startsWith ("qualifier" )) {
109+ String d = "" ;
110+ }
111+ for (TypeSafeFunction customNaming : getCustomNaming (type , property )) {
112+ String result = (String ) customNaming .refSemanticProvider .apply (obj , property );
79113 if (result != null ) {
80114 return result ;
81115 }
0 commit comments