Skip to content

Package: ManagedClassProcessor

ManagedClassProcessor

nameinstructionbranchcomplexitylinemethod
checkForNoArgConstructor(Class)
M: 0 C: 22
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
getManagedSupertype(Class)
M: 0 C: 12
100%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 0 C: 3
100%
M: 0 C: 1
100%
isEntityType(Class)
M: 0 C: 8
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
isManagedType(Class)
M: 0 C: 10
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
isMappedSuperclassType(Class)
M: 0 C: 8
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
processEntityType(Class)
M: 4 C: 20
83%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 4
100%
M: 0 C: 1
100%
processManagedType(Class)
M: 0 C: 37
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
processMappedSuperclassType(Class)
M: 4 C: 10
71%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 2
100%
M: 0 C: 1
100%
static {...}
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /**
2: * Copyright (C) 2016 Czech Technical University in Prague
3: * <p>
4: * This program is free software: you can redistribute it and/or modify it under
5: * the terms of the GNU General Public License as published by the Free Software
6: * Foundation, either version 3 of the License, or (at your option) any
7: * later version.
8: * <p>
9: * This program is distributed in the hope that it will be useful, but WITHOUT
10: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12: * details. You should have received a copy of the GNU General Public License
13: * along with this program. If not, see <http://www.gnu.org/licenses/>.
14: */
15: package cz.cvut.kbss.jopa.model.metamodel;
16:
17: import cz.cvut.kbss.jopa.exception.MetamodelInitializationException;
18: import cz.cvut.kbss.jopa.model.IRI;
19: import cz.cvut.kbss.jopa.model.annotations.MappedSuperclass;
20: import cz.cvut.kbss.jopa.model.annotations.OWLClass;
21:
22: /**
23: * Utility methods for processing managed types for metamodel construction.
24: */
25: class ManagedClassProcessor {
26:
27: private static final EntityLifecycleCallbackResolver lifecycleCallbackResolver = new EntityLifecycleCallbackResolver();
28:
29: private ManagedClassProcessor() {
30: }
31:
32: static <T> AbstractIdentifiableType<T> processManagedType(Class<T> cls) {
33: final AbstractIdentifiableType<T> type;
34:• if (isEntityType(cls)) {
35: type = processEntityType(cls);
36:• } else if (isMappedSuperclassType(cls)) {
37: type = processMappedSuperclassType(cls);
38: } else {
39: throw new MetamodelInitializationException("Type " + cls + " is not a managed type.");
40: }
41: final EntityLifecycleListenerManager callbackManager = lifecycleCallbackResolver.resolve(type);
42: type.setLifecycleListenerManager(callbackManager);
43: return type;
44: }
45:
46: private static <T> EntityTypeImpl<T> processEntityType(Class<T> cls) {
47: final OWLClass c = cls.getDeclaredAnnotation(OWLClass.class);
48:• assert c != null;
49:
50: checkForNoArgConstructor(cls);
51:
52: return new EntityTypeImpl<>(cls.getSimpleName(), cls, IRI.create(c.iri()));
53: }
54:
55: private static <T> void checkForNoArgConstructor(Class<T> cls) {
56: try {
57: cls.getDeclaredConstructor();
58: } catch (NoSuchMethodException e) {
59: throw new MetamodelInitializationException("Class " + cls + " is missing required no-arg constructor.");
60: }
61: }
62:
63: private static <T> MappedSuperclassTypeImpl<T> processMappedSuperclassType(Class<T> cls) {
64:• assert cls.getDeclaredAnnotation(MappedSuperclass.class) != null;
65:
66: return new MappedSuperclassTypeImpl<>(cls);
67: }
68:
69: static <T> Class<? super T> getManagedSupertype(Class<T> cls) {
70:• if (cls.getSuperclass() != null && isManagedType(cls.getSuperclass())) {
71: return cls.getSuperclass();
72: }
73: return null;
74: }
75:
76: private static boolean isManagedType(Class<?> cls) {
77:• return isEntityType(cls) || isMappedSuperclassType(cls);
78: }
79:
80: private static boolean isEntityType(Class<?> cls) {
81:• return cls.getDeclaredAnnotation(OWLClass.class) != null;
82: }
83:
84: private static boolean isMappedSuperclassType(Class<?> cls) {
85:• return cls.getDeclaredAnnotation(MappedSuperclass.class) != null;
86: }
87: }