if (refName == null && member == null) {
fail(consumer.getJndiConsumerName(), "presistenceUnitAnnotation.onClassWithNoName", persistenceUnit.unitName());
return;
}
PersistenceUnitRef persistenceUnitRef = consumer.getPersistenceUnitRefMap().get(refName);
if (persistenceUnitRef == null) {
persistenceUnitRef = new PersistenceUnitRef();
persistenceUnitRef.setPersistenceUnitName(persistenceUnit.unitName());
persistenceUnitRef.setPersistenceUnitRefName(refName);
consumer.getPersistenceUnitRef().add(persistenceUnitRef);
}
if (member != null) {
Class type = member.getType();
if (EntityManager.class.isAssignableFrom(type)) {
/**
* Was @PersistenceUnit mistakenly used when @PersistenceContext should have been used?
*/
ValidationContext validationContext = getValidationContext();
String jndiConsumerName = consumer.getJndiConsumerName();
String name = persistenceUnitRef.getName();
validationContext.fail(jndiConsumerName, "presistenceUnitAnnotation.onEntityManager", name);
} else if (!EntityManagerFactory.class.isAssignableFrom(type)) {
/**
* Was @PersistenceUnit mistakenly used for something that isn't an EntityManagerFactory?
*/
fail(consumer.getJndiConsumerName(), "presistenceUnitAnnotation.onNonEntityManagerFactory", persistenceUnitRef.getName());
} else {
// Set the member name where this will be injected
InjectionTarget target = new InjectionTarget();
target.setInjectionTargetClass(member.getDeclaringClass().getName());
target.setInjectionTargetName(member.getName());
persistenceUnitRef.getInjectionTarget().add(target);
}
}
if (persistenceUnitRef.getPersistenceUnitName() == null && !persistenceUnit.unitName().equals("")) {
persistenceUnitRef.setPersistenceUnitName(persistenceUnit.unitName());
}
}