Search in sources :

Example 6 with JndiReference

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());
                }
            }
        }
    }
}
Also used : EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) JndiReference(org.apache.openejb.jee.JndiReference) ArrayList(java.util.ArrayList) InjectionTarget(org.apache.openejb.jee.InjectionTarget)

Example 7 with JndiReference

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);
    }
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) MessageDestinationRef(org.apache.openejb.jee.MessageDestinationRef) JndiReference(org.apache.openejb.jee.JndiReference) PersistenceContextRef(org.apache.openejb.jee.PersistenceContextRef) ResourceRef(org.apache.openejb.jee.ResourceRef)

Example 8 with JndiReference

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);
    }
}
Also used : HashMap(java.util.HashMap) JndiReference(org.apache.openejb.jee.JndiReference) ArrayList(java.util.ArrayList)

Aggregations

JndiReference (org.apache.openejb.jee.JndiReference)8 ArrayList (java.util.ArrayList)3 TreeMap (java.util.TreeMap)3 QName (javax.xml.namespace.QName)3 PortComponentRef (org.apache.openejb.jee.PortComponentRef)3 ServiceRef (org.apache.openejb.jee.ServiceRef)3 EjbRef (org.apache.openejb.jee.sun.EjbRef)3 MessageDestinationRef (org.apache.openejb.jee.sun.MessageDestinationRef)3 PortInfo (org.apache.openejb.jee.sun.PortInfo)3 ResourceEnvRef (org.apache.openejb.jee.sun.ResourceEnvRef)3 ResourceRef (org.apache.openejb.jee.sun.ResourceRef)3 StubProperty (org.apache.openejb.jee.sun.StubProperty)3 WsdlPort (org.apache.openejb.jee.sun.WsdlPort)3 HashMap (java.util.HashMap)2 OpenEJBException (org.apache.openejb.OpenEJBException)2 ApplicationClient (org.apache.openejb.jee.ApplicationClient)2 EnterpriseBean (org.apache.openejb.jee.EnterpriseBean)2 MessageDestinationRef (org.apache.openejb.jee.MessageDestinationRef)2 ResourceRef (org.apache.openejb.jee.ResourceRef)2 SunApplicationClient (org.apache.openejb.jee.sun.SunApplicationClient)2