| 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.kns.org.kuali.rice.krad.app.persistence.jpa; | |
| 17 | ||
| 18 |  import java.util.HashSet; | |
| 19 |  import java.util.List; | |
| 20 |  import java.util.Set; | |
| 21 | ||
| 22 |  import javax.persistence.Embeddable; | |
| 23 |  import javax.persistence.Entity; | |
| 24 |  import javax.persistence.MappedSuperclass; | |
| 25 | ||
| 26 |  import org.reflections.Reflections; | |
| 27 | ||
| 28 |  /** | |
| 29 |   * Abstract class which exposes as JPA managed classes all of the business objects in a given package  | |
| 30 |   *  | |
| 31 |   * @author Kuali Rice Team (rice.collab@kuali.org) | |
| 32 |   * | |
| 33 |   */ | |
| 34 | 0 |  public abstract class PackagePersistableBusinessObjectClassExposer implements | 
| 35 |                  PersistableBusinessObjectClassExposer { | |
| 36 | ||
| 37 |          /** | |
| 38 |           * Exposes all of the JPA annotated entities in the package given by the getPackageNameToExpose method | |
| 39 |           * to be managed by the PersistenceUnit calling this | |
| 40 |           *  | |
| 41 |           * @see PersistableBusinessObjectClassExposer#exposePersistableBusinessObjectClassNames() | |
| 42 |           */ | |
| 43 | @Override | |
| 44 |          public Set<String> exposePersistableBusinessObjectClassNames() { | |
| 45 | 0 |                  Set<String> exposedClassNames = new HashSet<String>(); | 
| 46 | ||
| 47 | 0 |                  for (String packageNameToExpose: getPackageNamesToExpose()) { | 
| 48 | 0 |                          Reflections reflections = new Reflections(packageNameToExpose); | 
| 49 | 0 |                          final Set<Class<?>> entities = reflections.getTypesAnnotatedWith(Entity.class); | 
| 50 | 0 |                          for (Class<?> entityClass : entities) { | 
| 51 | 0 |                                  exposedClassNames.add(entityClass.getName()); | 
| 52 | } | |
| 53 | ||
| 54 | 0 |                          final Set<Class<?>> mappedSuperclasses = reflections.getTypesAnnotatedWith(MappedSuperclass.class); | 
| 55 | 0 |                          for (Class<?> mappedSuperclassClass : mappedSuperclasses) { | 
| 56 | 0 |                                  exposedClassNames.add(mappedSuperclassClass.getName()); | 
| 57 | } | |
| 58 | ||
| 59 | 0 |                          final Set<Class<?>> embeddables = reflections.getTypesAnnotatedWith(Embeddable.class); | 
| 60 | 0 |                          for (Class<?> embeddableClass : embeddables) { | 
| 61 |                                  // may this loop never be entered | |
| 62 | 0 |                                  exposedClassNames.add(embeddableClass.getName()); | 
| 63 | } | |
| 64 | 0 |                  } | 
| 65 | 0 |                  return exposedClassNames; | 
| 66 | } | |
| 67 | ||
| 68 |          /** | |
| 69 |           * @return the name of the package to expose all JPA annotated entities in | |
| 70 |           */ | |
| 71 | public abstract List<String> getPackageNamesToExpose(); | |
| 72 | ||
| 73 | } |