001package io.ebean.enhance.common; 002 003import java.util.Set; 004 005/** 006 * Helper to check for entity annotations on a class. 007 */ 008public class EntityCheck { 009 010 /** 011 * A class with one of these annotations is enhanced as an "entity". 012 */ 013 private static String[] entityAnnotations = { 014 EnhanceConstants.ENTITY_ANNOTATION, 015 EnhanceConstants.EMBEDDABLE_ANNOTATION, 016 EnhanceConstants.MAPPEDSUPERCLASS_ANNOTATION, 017 EnhanceConstants.DOCSTORE_ANNOTATION 018 }; 019 020 /** 021 * Return true if the annotation is for an Entity, Embeddable, MappedSuperclass or DocStore. 022 */ 023 public static boolean isEntityAnnotation(String desc) { 024 025 if (!desc.startsWith(EnhanceConstants.JAVAX_PERSISTENCE)) { 026 return desc.equals(EnhanceConstants.DOCSTORE_ANNOTATION); 027 } 028 if (desc.equals(EnhanceConstants.ENTITY_ANNOTATION)) { 029 return true; 030 } else if (desc.equals(EnhanceConstants.EMBEDDABLE_ANNOTATION)) { 031 return true; 032 } else if (desc.equals(EnhanceConstants.MAPPEDSUPERCLASS_ANNOTATION)) { 033 return true; 034 } 035 return false; 036 } 037 038 /** 039 * Return true if the class annotations contains one of the entity annotations. 040 */ 041 public static boolean hasEntityAnnotation(Set<String> classAnnotations) { 042 043 for (String entityAnnotation : entityAnnotations) { 044 if (classAnnotations.contains(entityAnnotation)) { 045 return true; 046 } 047 } 048 return false; 049 } 050}