Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
PackagePersistableBusinessObjectClassExposer |
|
| 3.0;3 |
1 | /* | |
2 | * Copyright 2007 The Kuali Foundation | |
3 | * | |
4 | * Licensed under the Educational Community License, Version 1.0 (the "License"); | |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at | |
7 | * | |
8 | * http://www.opensource.org/licenses/ecl1.php | |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | * See the License for the specific language governing permissions and | |
14 | * limitations under the License. | |
15 | */ | |
16 | package org.kuali.rice.krad.app.persistence.jpa; | |
17 | ||
18 | import org.reflections.Reflections; | |
19 | ||
20 | import javax.persistence.Embeddable; | |
21 | import javax.persistence.Entity; | |
22 | import javax.persistence.MappedSuperclass; | |
23 | import java.util.HashSet; | |
24 | import java.util.List; | |
25 | import java.util.Set; | |
26 | ||
27 | /** | |
28 | * Abstract class which exposes as JPA managed classes all of the business objects in a given package | |
29 | * | |
30 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
31 | * | |
32 | */ | |
33 | 0 | public abstract class PackagePersistableBusinessObjectClassExposer implements |
34 | PersistableBusinessObjectClassExposer { | |
35 | ||
36 | /** | |
37 | * Exposes all of the JPA annotated entities in the package given by the getPackageNameToExpose method | |
38 | * to be managed by the PersistenceUnit calling this | |
39 | * | |
40 | * @see PersistableBusinessObjectClassExposer#exposePersistableBusinessObjectClassNames() | |
41 | */ | |
42 | @Override | |
43 | public Set<String> exposePersistableBusinessObjectClassNames() { | |
44 | 0 | Set<String> exposedClassNames = new HashSet<String>(); |
45 | ||
46 | 0 | for (String packageNameToExpose: getPackageNamesToExpose()) { |
47 | 0 | Reflections reflections = new Reflections(packageNameToExpose); |
48 | 0 | final Set<Class<?>> entities = reflections.getTypesAnnotatedWith(Entity.class); |
49 | 0 | for (Class<?> entityClass : entities) { |
50 | 0 | exposedClassNames.add(entityClass.getName()); |
51 | } | |
52 | ||
53 | 0 | final Set<Class<?>> mappedSuperclasses = reflections.getTypesAnnotatedWith(MappedSuperclass.class); |
54 | 0 | for (Class<?> mappedSuperclassClass : mappedSuperclasses) { |
55 | 0 | exposedClassNames.add(mappedSuperclassClass.getName()); |
56 | } | |
57 | ||
58 | 0 | final Set<Class<?>> embeddables = reflections.getTypesAnnotatedWith(Embeddable.class); |
59 | 0 | for (Class<?> embeddableClass : embeddables) { |
60 | // may this loop never be entered | |
61 | 0 | exposedClassNames.add(embeddableClass.getName()); |
62 | } | |
63 | 0 | } |
64 | 0 | return exposedClassNames; |
65 | } | |
66 | ||
67 | /** | |
68 | * @return the name of the package to expose all JPA annotated entities in | |
69 | */ | |
70 | public abstract List<String> getPackageNamesToExpose(); | |
71 | ||
72 | } |