use of org.apache.openejb.jee.JndiReference in project tomee by apache.
the class CheckInjectionTargets method validate.
public void validate(final EjbModule ejbModule) {
for (final EnterpriseBean bean : ejbModule.getEjbJar().getEnterpriseBeans()) {
final List<JndiReference> entries = new ArrayList<JndiReference>();
entries.addAll(bean.getEjbLocalRef());
entries.addAll(bean.getEjbRef());
entries.addAll(bean.getEnvEntry());
entries.addAll(bean.getMessageDestinationRef());
entries.addAll(bean.getPersistenceContextRef());
entries.addAll(bean.getPersistenceUnitRef());
entries.addAll(bean.getResourceEnvRef());
entries.addAll(bean.getResourceRef());
entries.addAll(bean.getServiceRef());
for (final JndiReference reference : entries) {
// check injection target
for (final InjectionTarget target : reference.getInjectionTarget()) {
boolean classPrefix = false;
String name = target.getInjectionTargetName();
if (name.startsWith(target.getInjectionTargetClass() + "/")) {
classPrefix = true;
name = name.substring(target.getInjectionTargetClass().length() + 1);
}
final String shortNameInvalid = name;
if (name.startsWith("set") && name.length() >= 4 && Character.isUpperCase(name.charAt(3))) {
final StringBuilder correctName = new StringBuilder(name);
correctName.delete(0, 3);
correctName.setCharAt(0, Character.toLowerCase(correctName.charAt(0)));
final String shortNameCorrect = correctName.toString();
if (classPrefix) {
correctName.insert(0, target.getInjectionTargetClass() + "/");
}
warn(bean, "injectionTarget.nameContainsSet", target.getInjectionTargetName(), shortNameInvalid, shortNameCorrect, correctName, reference.getName(), reference.getClass().getSimpleName());
target.setInjectionTargetName(correctName.toString());
}
}
}
}
}
use of org.apache.openejb.jee.JndiReference in project tomee by apache.
the class AutoConfig method processJndiRefs.
private void processJndiRefs(final String moduleId, final JndiConsumer jndiConsumer, final AppResources appResources, final ClassLoader classLoader) throws OpenEJBException {
// Resource reference
for (final ResourceRef ref : jndiConsumer.getResourceRef()) {
// skip destinations with lookup name
if (ref.getLookupName() != null) {
continue;
}
// skip destinations with a global jndi name
final String mappedName = ref.getMappedName() == null ? "" : ref.getMappedName();
if (mappedName.startsWith("jndi:")) {
continue;
}
final String refType = getType(ref, classLoader);
// skip references such as URLs which are automatically handled by the server
if (isIgnoredReferenceType(refType, classLoader)) {
continue;
}
String destinationId = mappedName.length() == 0 ? ref.getName() : mappedName;
try {
destinationId = getResourceId(moduleId, destinationId, refType, appResources);
} catch (final OpenEJBException ex) {
if (!(ref instanceof ContextRef)) {
throw ex;
} else {
// let jaxrs provider manage it
continue;
}
}
ref.setMappedName(destinationId);
}
// Resource env reference
for (final JndiReference ref : jndiConsumer.getResourceEnvRef()) {
// skip destinations with lookup name
if (ref.getLookupName() != null) {
continue;
}
// skip destinations with a global jndi name
final String mappedName = ref.getMappedName() == null ? "" : ref.getMappedName();
if (mappedName.startsWith("jndi:")) {
continue;
}
final String refType = getType(ref, classLoader);
// skip references such as URLs which are automatically handled by the server
if (isIgnoredReferenceType(refType, classLoader)) {
continue;
}
String destinationId = mappedName.length() == 0 ? ref.getName() : mappedName;
destinationId = getResourceEnvId(moduleId, destinationId, refType, appResources);
ref.setMappedName(destinationId);
}
// Message destination reference
for (final MessageDestinationRef ref : jndiConsumer.getMessageDestinationRef()) {
// skip destinations with lookup name
if (ref.getLookupName() != null) {
continue;
}
// skip destinations with a global jndi name
final String mappedName = ref.getMappedName() == null ? "" : ref.getMappedName();
if (mappedName.startsWith("jndi:")) {
continue;
}
String destinationId = mappedName.length() == 0 ? ref.getName() : mappedName;
destinationId = getResourceEnvId(moduleId, destinationId, ref.getType(), appResources);
ref.setMappedName(destinationId);
}
}
use of org.apache.openejb.jee.JndiReference in project tomee by apache.
the class LinkBuiltInTypes method link.
private void link(final JndiConsumer consumer) {
final Map<String, String> links = new HashMap<String, String>();
add(links, BeanManager.class);
add(links, Validator.class);
add(links, ValidatorFactory.class);
add(links, EJBContext.class, EntityContext.class, SessionContext.class, MessageDrivenContext.class);
add(links, UserTransaction.class);
add(links, TransactionManager.class);
add(links, TransactionSynchronizationRegistry.class);
add(links, TimerService.class);
add(links, WebServiceContext.class);
final List<JndiReference> refs = new ArrayList<JndiReference>();
refs.addAll(consumer.getResourceRef());
refs.addAll(consumer.getResourceEnvRef());
for (final JndiReference ref : refs) {
final String link = links.get(ref.getType());
if (link == null) {
continue;
}
if (ref.getName().equals(link)) {
// make sure the user hasn't linked it to itself or anything else
ref.setLookupName(null);
continue;
}
ref.setLookupName(link);
}
}
Aggregations