1
2
3
4
5
6 package gov.nist.secauto.oscal.lib.profile.resolver.support;
7
8 import gov.nist.secauto.metaschema.core.metapath.item.node.IAssemblyNodeItem;
9 import gov.nist.secauto.metaschema.core.metapath.item.node.IRootAssemblyNodeItem;
10 import gov.nist.secauto.metaschema.core.util.ObjectUtils;
11
12 import java.util.EnumSet;
13 import java.util.Set;
14
15 import edu.umd.cs.findbugs.annotations.NonNull;
16
17 public abstract class AbstractIndexingVisitor<T, R>
18 extends AbstractCatalogEntityVisitor<T, R> {
19
20 public AbstractIndexingVisitor() {
21 this(ObjectUtils.notNull(EnumSet.allOf(IEntityItem.ItemType.class)));
22 }
23
24 public AbstractIndexingVisitor(@NonNull Set<IEntityItem.ItemType> itemTypesToIndex) {
25 super(itemTypesToIndex);
26 }
27
28 @NonNull
29 protected abstract IIndexer getIndexer(T state);
30
31 @Override
32 public R visitGroup(IAssemblyNodeItem item, R childResult, T state) {
33 getIndexer(state).addGroup(item);
34 return childResult;
35 }
36
37 @Override
38 public R visitControl(IAssemblyNodeItem item, R childResult, T state) {
39 getIndexer(state).addControl(item);
40 return childResult;
41 }
42
43 @Override
44 protected R visitParameter(@NonNull IAssemblyNodeItem parameterItem,
45 @NonNull IAssemblyNodeItem catalogOrGroupOrControl, T state) {
46 getIndexer(state).addParameter(parameterItem);
47 return newDefaultResult(state);
48 }
49
50 @Override
51 protected void visitPart(@NonNull IAssemblyNodeItem partItem,
52 @NonNull IAssemblyNodeItem catalogOrGroupOrControl, T state) {
53 getIndexer(state).addPart(partItem);
54 }
55
56 @Override
57 protected void visitRole(IAssemblyNodeItem roleItem, IAssemblyNodeItem metadataItem, T state) {
58 getIndexer(state).addRole(roleItem);
59 }
60
61 @Override
62 protected void visitLocation(IAssemblyNodeItem locationItem, IAssemblyNodeItem metadataItem,
63 T state) {
64 getIndexer(state).addLocation(locationItem);
65 }
66
67 @Override
68 protected void visitParty(IAssemblyNodeItem partyItem, IAssemblyNodeItem metadataItem, T state) {
69 getIndexer(state).addParty(partyItem);
70 }
71
72 @Override
73 protected void visitResource(IAssemblyNodeItem resourceItem, IRootAssemblyNodeItem rootItem, T state) {
74 getIndexer(state).addResource(resourceItem);
75 }
76 }