Package: ScanningMetadataInterpolatorFactory
ScanningMetadataInterpolatorFactory
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ScanningMetadataInterpolatorFactory() |
|
|
|
|
|
||||||||||||||||||||
initialize() |
|
|
|
|
|
||||||||||||||||||||
lambda$initialize$0(MetadataReader, MetadataReaderFactory) |
|
|
|
|
|
||||||||||||||||||||
static {...} |
|
|
|
|
|
Coverage
1: /*
2: * *************************************************************************************************************************************************************
3: *
4: * NorthernWind - lightweight CMS
5: * http://tidalwave.it/projects/northernwind
6: *
7: * Copyright (C) 2011 - 2025 Tidalwave s.a.s. (http://tidalwave.it)
8: *
9: * *************************************************************************************************************************************************************
10: *
11: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
12: * You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
17: * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
18: *
19: * *************************************************************************************************************************************************************
20: *
21: * git clone https://bitbucket.org/tidalwave/northernwind-src
22: * git clone https://github.com/tidalwave-it/northernwind-src
23: *
24: * *************************************************************************************************************************************************************
25: */
26: package it.tidalwave.northernwind.frontend.media.impl.interpolator;
27:
28: import javax.annotation.PostConstruct;
29: import java.util.ArrayList;
30: import java.util.List;
31: import it.tidalwave.util.spring.ClassScanner;
32: import lombok.Getter;
33: import lombok.extern.slf4j.Slf4j;
34:
35: /***************************************************************************************************************************************************************
36: *
37: * An implementation of {@link MetadataInterpolatorFactory} that scans the class path for candidates.
38: *
39: * @author Fabrizio Giudici
40: *
41: **************************************************************************************************************************************************************/
42: @Slf4j
43: public class ScanningMetadataInterpolatorFactory implements MetadataInterpolatorFactory
44: {
45: @Getter
46: private final List<MetadataInterpolator> interpolators = new ArrayList<>();
47:
48: @PostConstruct
49: public void initialize()
50: {
51: interpolators.clear();
52: log.info("Scanning for metadata interpolators...");
53:
54: // FIXME: doesn't check through the whole hierarchy
55: final var scanner = new ClassScanner().withIncludeFilter((metadataReader, metadataReaderFactory) ->
56: {
57: final var interfaceNames = List.of(metadataReader.getClassMetadata().getInterfaceNames());
58: final var superClassName = metadataReader.getClassMetadata().getSuperClassName();
59:
60:• return interfaceNames.contains(MetadataInterpolator.class.getName()) ||
61:• ((superClassName != null) && superClassName.equals(MetadataInterpolatorSupport.class.getName()));
62: });
63:
64:• for (final var clazz : scanner.findClasses())
65: {
66: try
67: {
68: interpolators.add((MetadataInterpolator)clazz.newInstance());
69: log.info(">>>> added metadata interpolator: {}", clazz);
70: }
71: catch (InstantiationException | IllegalAccessException e)
72: {
73: log.warn("Couldn't add metadata interpolator: " + clazz, e);
74: }
75: }
76: }
77: }