1
2
3
4
5
6 package gov.nist.secauto.metaschema.core.metapath.item;
7
8 import gov.nist.secauto.metaschema.core.metapath.item.node.INodeItem;
9 import gov.nist.secauto.metaschema.core.metapath.type.TypeMetapathException;
10
11 import edu.umd.cs.findbugs.annotations.NonNull;
12 import edu.umd.cs.findbugs.annotations.Nullable;
13
14
15
16
17 public final class ItemUtils {
18
19 private ItemUtils() {
20
21 }
22
23
24
25
26
27
28
29
30
31
32
33 @NonNull
34 public static INodeItem checkItemIsNodeItemForStep(@Nullable IItem item) {
35 if (item instanceof INodeItem) {
36 return (INodeItem) item;
37 }
38 if (item == null) {
39 throw new TypeMetapathException(TypeMetapathException.NOT_A_NODE_ITEM_FOR_STEP,
40 "Item is null.");
41 }
42 throw new TypeMetapathException(TypeMetapathException.NOT_A_NODE_ITEM_FOR_STEP,
43 String.format(
44 "The item of type '%s' is not a INodeItem.",
45 item.getClass().getName()));
46 }
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63 @SuppressWarnings("unchecked")
64 @NonNull
65 public static <TYPE> TYPE checkItemType(@NonNull IItem item, @NonNull Class<TYPE> clazz) {
66 if (clazz.isInstance(item)) {
67 return (TYPE) item;
68 }
69 throw new TypeMetapathException(TypeMetapathException.INVALID_TYPE_ERROR,
70 String.format(
71 "The item of type '%s' is not the required type '%s'.",
72 item.getClass().getName(),
73 clazz.getName()));
74 }
75 }