1515 */
1616package io .adminshell .aas .v3 .dataformat .core ;
1717
18- import io .adminshell .aas .v3 .model .Constraint ;
19- import io .adminshell .aas .v3 .model .Referable ;
20- import io .github .classgraph .ClassGraph ;
21- import io .github .classgraph .ClassInfo ;
22- import io .github .classgraph .ClassInfoList ;
23- import io .github .classgraph .ScanResult ;
2418import java .util .ArrayList ;
2519import java .util .HashMap ;
2620import java .util .List ;
2721import java .util .Map ;
2822import java .util .Objects ;
2923import java .util .Set ;
3024import java .util .stream .Collectors ;
25+
3126import org .slf4j .Logger ;
3227import org .slf4j .LoggerFactory ;
3328
29+ import io .adminshell .aas .v3 .model .Constraint ;
30+ import io .adminshell .aas .v3 .model .Referable ;
31+ import io .github .classgraph .ClassGraph ;
32+ import io .github .classgraph .ClassInfo ;
33+ import io .github .classgraph .ClassInfoList ;
34+ import io .github .classgraph .ScanResult ;
35+
3436/**
3537 * Helper class to collect relevant data needed for
3638 * ReflectionAnnotationIntrospector via reflection.
@@ -49,10 +51,15 @@ public class ReflectionHelper {
4951 */
5052 public static final String DEFAULT_IMPLEMENTATION_PACKAGE_NAME = MODEL_PACKAGE_NAME + ".impl" ;
5153 /**
52- * Name of package where the mixins are defined. These mixins are
54+ * Name of package where the json mixins are defined. These mixins are
5355 * automatically added to JsonSerializer and JsonDeserializer.
5456 */
55- public static final String MIXINS_PACKAGE_NAME = ROOT_PACKAGE_NAME + ".dataformat.json.mixins" ;
57+ public static final String JSON_MIXINS_PACKAGE_NAME = ROOT_PACKAGE_NAME + ".dataformat.json.mixins" ;
58+ /**
59+ * Name of package where the xml mixins are defined. These mixins are
60+ * automatically added to XmlSerializer and XmlDeserializer.
61+ */
62+ public static final String XML_MIXINS_PACKAGE_NAME = ROOT_PACKAGE_NAME + ".dataformat.xml.mixins" ;
5663 /**
5764 * Suffix that identifies a class as a mixin.
5865 */
@@ -77,10 +84,15 @@ public class ReflectionHelper {
7784 */
7885 public static final Map <Class <?>, Set <Class <?>>> SUBTYPES ;
7986 /**
80- * Expanded list of all mixin classes defined in the MIXINS_PACKAGE_NAME
87+ * Expanded list of all mixin classes defined in the JSON_MIXINS_PACKAGE_NAME
8188 * package together with the corresponding class they should be applied to.
8289 */
83- public static final Map <Class <?>, Class <?>> MIXINS ;
90+ public static final Map <Class <?>, Class <?>> JSON_MIXINS ;
91+ /**
92+ * Expanded list of all mixin classes defined in the XML_MIXINS_PACKAGE_NAME
93+ * package together with the corresponding class they should be applied to.
94+ */
95+ public static final Map <Class <?>, Class <?>> XML_MIXINS ;
8496 /**
8597 * Expanded list of all default implementations in the
8698 * DEFAULT_IMPLEMENTATION_PACKAGE_NAME package together with the interface
@@ -123,7 +135,7 @@ public Class<? extends T> getImplementationType() {
123135 *
124136 * @param type the class to check
125137 * @return whether the given class is an interface and from within the
126- * MODEL_PACKAGE_NAME package
138+ * MODEL_PACKAGE_NAME package
127139 */
128140 public static boolean isModelInterface (Class <?> type ) {
129141 return type .isInterface () && MODEL_PACKAGE_NAME .equals (type .getPackageName ());
@@ -155,7 +167,7 @@ public static boolean hasDefaultImplementation(Class<?> interfaceType) {
155167 *
156168 * @param type the class to check
157169 * @return whether the given class is an interface from within the
158- * MODEL_PACKAGE_NAME package as well as a default implementation or not
170+ * MODEL_PACKAGE_NAME package as well as a default implementation or not
159171 */
160172 public static boolean isModelInterfaceOrDefaultImplementation (Class <?> type ) {
161173 return isModelInterface (type ) || isDefaultImplementation (type );
@@ -167,7 +179,7 @@ public static boolean isModelInterfaceOrDefaultImplementation(Class<?> type) {
167179 *
168180 * @param clazz the class to find the type information for
169181 * @return the type information for the given class or null if there is no
170- * type information or type information should not be included
182+ * type information or type information should not be included
171183 */
172184 public static String getModelType (Class <?> clazz ) {
173185 Class <?> type = getMostSpecificTypeWithModelType (clazz );
@@ -193,7 +205,7 @@ public static String getModelType(Class<?> clazz) {
193205 *
194206 * @param clazz the class to find the type for
195207 * @return the most specific supertype of given class that contains some AAS
196- * type information or null if there is none
208+ * type information or null if there is none
197209 */
198210 public static Class <?> getMostSpecificTypeWithModelType (Class <?> clazz ) {
199211 return TYPES_WITH_MODEL_TYPE .stream ()
@@ -224,7 +236,8 @@ public static Class<?> getMostSpecificTypeWithModelType(Class<?> clazz) {
224236 .scan ();
225237 TYPES_WITH_MODEL_TYPE = scanModelTypes (modelScan );
226238 SUBTYPES = scanSubtypes (modelScan );
227- MIXINS = scanMixins (modelScan );
239+ JSON_MIXINS = scanMixins (modelScan , JSON_MIXINS_PACKAGE_NAME );
240+ XML_MIXINS = scanMixins (modelScan , XML_MIXINS_PACKAGE_NAME );
228241 DEFAULT_IMPLEMENTATIONS = scanDefaultImplementations (modelScan );
229242 ENUMS = modelScan .getAllEnums ().loadClasses (Enum .class );
230243 INTERFACES_WITHOUT_DEFAULT_IMPLEMENTATION = getInterfacesWithoutDefaultImplementation (modelScan );
@@ -247,7 +260,7 @@ private static List<ImplementationInfo> scanDefaultImplementations(ScanResult mo
247260 .loadClasses ()
248261 .stream ()
249262 .forEach (x -> {
250- String interfaceName = x .getSimpleName ().substring (DEFAULT_IMPLEMENTATION_PREFIX .length ());//using conventions
263+ String interfaceName = x .getSimpleName ().substring (DEFAULT_IMPLEMENTATION_PREFIX .length ());// using conventions
251264 ClassInfoList interfaceClassInfos = modelScan .getAllClasses ().filter (y -> y .isInterface () && Objects .equals (y .getSimpleName (), interfaceName ));
252265 if (interfaceClassInfos .isEmpty ()) {
253266 logger .warn ("could not find interface realized by default implementation class '{}'" , x .getSimpleName ());
@@ -263,10 +276,10 @@ private static List<ImplementationInfo> scanDefaultImplementations(ScanResult mo
263276 return defaultImplementations ;
264277 }
265278
266- private static Map <Class <?>, Class <?>> scanMixins (ScanResult modelScan ) {
279+ private static Map <Class <?>, Class <?>> scanMixins (ScanResult modelScan , String packageName ) {
267280 ScanResult mixinScan = new ClassGraph ()
268281 .enableClassInfo ()
269- .acceptPackagesNonRecursive (MIXINS_PACKAGE_NAME )
282+ .acceptPackagesNonRecursive (packageName )
270283 .scan ();
271284 Map <Class <?>, Class <?>> mixins = new HashMap <>();
272285 mixinScan .getAllClasses ()
@@ -290,13 +303,13 @@ private static Map<Class<?>, Class<?>> scanMixins(ScanResult modelScan) {
290303 private static Map <Class <?>, Set <Class <?>>> scanSubtypes (ScanResult modelScan ) {
291304 return modelScan .getAllInterfaces ().stream ()
292305 .filter (ReflectionHelper ::hasSubclass )
293- .collect (Collectors .toMap (x -> x . loadClass () , ReflectionHelper ::getSubclasses ));
306+ .collect (Collectors .toMap (ClassInfo :: loadClass , ReflectionHelper ::getSubclasses ));
294307 }
295308
296309 private static Set <Class <?>> getSubclasses (ClassInfo clazzInfo ) {
297310 return clazzInfo .getClassesImplementing ()
298311 .directOnly ()
299- .filter (x -> x . isInterface () )
312+ .filter (ClassInfo :: isInterface )
300313 .loadClasses ()
301314 .stream ()
302315 .collect (Collectors .toSet ());
0 commit comments