Search in sources :

Example 1 with WebServiceRef

use of javax.xml.ws.WebServiceRef in project wildfly by wildfly.

the class WSRefUtils method getWebServiceRefAnnotation.

private static WebServiceRef getWebServiceRefAnnotation(final AnnotatedElement anElement, final UnifiedServiceRefMetaData serviceRefUMDM) {
    final WebServiceRef webServiceRefAnnotation = getAnnotation(anElement, WebServiceRef.class);
    final WebServiceRefs webServiceRefsAnnotation = getAnnotation(anElement, WebServiceRefs.class);
    if (webServiceRefAnnotation == null && webServiceRefsAnnotation == null) {
        return null;
    }
    // Build the list of @WebServiceRef relevant annotations
    final List<WebServiceRef> wsrefList = new ArrayList<WebServiceRef>();
    if (webServiceRefAnnotation != null) {
        wsrefList.add(webServiceRefAnnotation);
    }
    if (webServiceRefsAnnotation != null) {
        for (final WebServiceRef webServiceRefAnn : webServiceRefsAnnotation.value()) {
            wsrefList.add(webServiceRefAnn);
        }
    }
    // Return effective @WebServiceRef annotation
    WebServiceRef returnValue = null;
    if (wsrefList.size() == 1) {
        returnValue = wsrefList.get(0);
    } else {
        for (WebServiceRef webServiceRefAnn : wsrefList) {
            if (serviceRefUMDM.getServiceRefName().endsWith(webServiceRefAnn.name())) {
                returnValue = webServiceRefAnn;
                break;
            }
        }
    }
    return returnValue;
}
Also used : ArrayList(java.util.ArrayList) WebServiceRefs(javax.xml.ws.WebServiceRefs) WebServiceRef(javax.xml.ws.WebServiceRef)

Example 2 with WebServiceRef

use of javax.xml.ws.WebServiceRef in project wildfly by wildfly.

the class WeldJaxwsInjectionServices method registerWebServiceRefInjectionPoint.

@Override
public <T> ResourceReferenceFactory<T> registerWebServiceRefInjectionPoint(final InjectionPoint injectionPoint) {
    WebServiceRef annotation = getResourceAnnotated(injectionPoint).getAnnotation(WebServiceRef.class);
    if (annotation == null) {
        throw WeldLogger.ROOT_LOGGER.annotationNotFound(WebServiceRef.class, injectionPoint.getMember());
    }
    validateWebServiceRefInjectionPoint(injectionPoint, annotation);
    try {
        ManagedReferenceFactory factory = WebServiceReferences.createWebServiceFactory(deploymentUnit, classNameFromType(injectionPoint.getType()), new WSRefAnnotationWrapper(annotation), (AnnotatedElement) injectionPoint.getMember(), getBindingName(injectionPoint, annotation));
        return new ManagedReferenceFactoryToResourceReferenceFactoryAdapter<>(factory);
    } catch (DeploymentUnitProcessingException e) {
        throw new RuntimeException(e);
    }
}
Also used : DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) WSRefAnnotationWrapper(org.jboss.as.webservices.webserviceref.WSRefAnnotationWrapper) ManagedReferenceFactory(org.jboss.as.naming.ManagedReferenceFactory) WebServiceRef(javax.xml.ws.WebServiceRef)

Example 3 with WebServiceRef

use of javax.xml.ws.WebServiceRef in project tomee by apache.

the class LegacyAnnotationProcessor method processAnnotations.

/**
 * Inject resources in specified instance.
 * @param instance
 * @throws java.lang.IllegalAccessException
 * @throws java.lang.reflect.InvocationTargetException
 * @throws javax.naming.NamingException
 */
public void processAnnotations(final Object instance) throws IllegalAccessException, InvocationTargetException, NamingException {
    if (context == null) {
        // No resource injection
        return;
    }
    Class<?> clazz = instance.getClass();
    while (clazz != null) {
        // Initialize fields annotations
        final Field[] fields = clazz.getDeclaredFields();
        for (int i = 0; i < fields.length; i++) {
            if (fields[i].isAnnotationPresent(Resource.class)) {
                final Resource annotation = fields[i].getAnnotation(Resource.class);
                lookupFieldResource(context, instance, fields[i], annotation.name(), clazz);
            }
            if (fields[i].isAnnotationPresent(EJB.class)) {
                final EJB annotation = fields[i].getAnnotation(EJB.class);
                lookupFieldResource(context, instance, fields[i], annotation.name(), clazz);
            }
            if (fields[i].isAnnotationPresent(WebServiceRef.class)) {
                final WebServiceRef annotation = fields[i].getAnnotation(WebServiceRef.class);
                lookupFieldResource(context, instance, fields[i], annotation.name(), clazz);
            }
            if (fields[i].isAnnotationPresent(PersistenceContext.class)) {
                final PersistenceContext annotation = fields[i].getAnnotation(PersistenceContext.class);
                lookupFieldResource(context, instance, fields[i], annotation.name(), clazz);
            }
            if (fields[i].isAnnotationPresent(PersistenceUnit.class)) {
                final PersistenceUnit annotation = fields[i].getAnnotation(PersistenceUnit.class);
                lookupFieldResource(context, instance, fields[i], annotation.name(), clazz);
            }
        }
        // Initialize methods annotations
        final Method[] methods = clazz.getDeclaredMethods();
        for (int i = 0; i < methods.length; i++) {
            if (methods[i].isAnnotationPresent(Resource.class)) {
                final Resource annotation = methods[i].getAnnotation(Resource.class);
                lookupMethodResource(context, instance, methods[i], annotation.name(), clazz);
            }
            if (methods[i].isAnnotationPresent(EJB.class)) {
                final EJB annotation = methods[i].getAnnotation(EJB.class);
                lookupMethodResource(context, instance, methods[i], annotation.name(), clazz);
            }
            if (methods[i].isAnnotationPresent(WebServiceRef.class)) {
                final WebServiceRef annotation = methods[i].getAnnotation(WebServiceRef.class);
                lookupMethodResource(context, instance, methods[i], annotation.name(), clazz);
            }
            if (methods[i].isAnnotationPresent(PersistenceContext.class)) {
                final PersistenceContext annotation = methods[i].getAnnotation(PersistenceContext.class);
                lookupMethodResource(context, instance, methods[i], annotation.name(), clazz);
            }
            if (methods[i].isAnnotationPresent(PersistenceUnit.class)) {
                final PersistenceUnit annotation = methods[i].getAnnotation(PersistenceUnit.class);
                lookupMethodResource(context, instance, methods[i], annotation.name(), clazz);
            }
        }
        clazz = clazz.getSuperclass();
    }
}
Also used : Field(java.lang.reflect.Field) PersistenceUnit(javax.persistence.PersistenceUnit) Resource(javax.annotation.Resource) PersistenceContext(javax.persistence.PersistenceContext) Method(java.lang.reflect.Method) EJB(javax.ejb.EJB) WebServiceRef(javax.xml.ws.WebServiceRef)

Example 4 with WebServiceRef

use of javax.xml.ws.WebServiceRef in project tomcat70 by apache.

the class DefaultInstanceManager method populateAnnotationsCache.

/**
 * Make sure that the annotations cache has been populated for the provided
 * class.
 *
 * @param clazz         clazz to populate annotations for
 * @param injections    map of injections for this class from xml deployment
 *                      descriptor
 * @throws IllegalAccessException       if injection target is inaccessible
 * @throws javax.naming.NamingException if value cannot be looked up in jndi
 * @throws java.lang.reflect.InvocationTargetException
 *                                      if injection fails
 */
protected void populateAnnotationsCache(Class<?> clazz, Map<String, String> injections) throws IllegalAccessException, InvocationTargetException, NamingException {
    List<AnnotationCacheEntry> annotations = null;
    while (clazz != null) {
        AnnotationCacheEntry[] annotationsArray = annotationCache.get(clazz);
        if (annotationsArray == null) {
            if (annotations == null) {
                annotations = new ArrayList<AnnotationCacheEntry>();
            } else {
                annotations.clear();
            }
            if (context != null) {
                // Initialize fields annotations for resource injection if
                // JNDI is enabled
                Field[] fields = Introspection.getDeclaredFields(clazz);
                for (Field field : fields) {
                    Resource resourceAnnotation;
                    Annotation ejbAnnotation;
                    Annotation webServiceRefAnnotation;
                    Annotation persistenceContextAnnotation;
                    Annotation persistenceUnitAnnotation;
                    if (injections != null && injections.containsKey(field.getName())) {
                        annotations.add(new AnnotationCacheEntry(field.getName(), null, injections.get(field.getName()), AnnotationCacheEntryType.FIELD));
                    } else if ((resourceAnnotation = field.getAnnotation(Resource.class)) != null) {
                        annotations.add(new AnnotationCacheEntry(field.getName(), null, resourceAnnotation.name(), AnnotationCacheEntryType.FIELD));
                    } else if (EJB_PRESENT && (ejbAnnotation = field.getAnnotation(EJB.class)) != null) {
                        annotations.add(new AnnotationCacheEntry(field.getName(), null, ((EJB) ejbAnnotation).name(), AnnotationCacheEntryType.FIELD));
                    } else if (WS_PRESENT && (webServiceRefAnnotation = field.getAnnotation(WebServiceRef.class)) != null) {
                        annotations.add(new AnnotationCacheEntry(field.getName(), null, ((WebServiceRef) webServiceRefAnnotation).name(), AnnotationCacheEntryType.FIELD));
                    } else if (JPA_PRESENT && (persistenceContextAnnotation = field.getAnnotation(PersistenceContext.class)) != null) {
                        annotations.add(new AnnotationCacheEntry(field.getName(), null, ((PersistenceContext) persistenceContextAnnotation).name(), AnnotationCacheEntryType.FIELD));
                    } else if (JPA_PRESENT && (persistenceUnitAnnotation = field.getAnnotation(PersistenceUnit.class)) != null) {
                        annotations.add(new AnnotationCacheEntry(field.getName(), null, ((PersistenceUnit) persistenceUnitAnnotation).name(), AnnotationCacheEntryType.FIELD));
                    }
                }
            }
            // Initialize methods annotations
            Method[] methods = Introspection.getDeclaredMethods(clazz);
            Method postConstruct = null;
            String postConstructFromXml = postConstructMethods.get(clazz.getName());
            Method preDestroy = null;
            String preDestroyFromXml = preDestroyMethods.get(clazz.getName());
            for (Method method : methods) {
                if (context != null) {
                    // Resource injection only if JNDI is enabled
                    if (injections != null && Introspection.isValidSetter(method)) {
                        String fieldName = Introspection.getPropertyName(method);
                        if (injections.containsKey(fieldName)) {
                            annotations.add(new AnnotationCacheEntry(method.getName(), method.getParameterTypes(), injections.get(fieldName), AnnotationCacheEntryType.SETTER));
                            continue;
                        }
                    }
                    Resource resourceAnnotation;
                    Annotation ejbAnnotation;
                    Annotation webServiceRefAnnotation;
                    Annotation persistenceContextAnnotation;
                    Annotation persistenceUnitAnnotation;
                    if ((resourceAnnotation = method.getAnnotation(Resource.class)) != null) {
                        annotations.add(new AnnotationCacheEntry(method.getName(), method.getParameterTypes(), resourceAnnotation.name(), AnnotationCacheEntryType.SETTER));
                    } else if (EJB_PRESENT && (ejbAnnotation = method.getAnnotation(EJB.class)) != null) {
                        annotations.add(new AnnotationCacheEntry(method.getName(), method.getParameterTypes(), ((EJB) ejbAnnotation).name(), AnnotationCacheEntryType.SETTER));
                    } else if (WS_PRESENT && (webServiceRefAnnotation = method.getAnnotation(WebServiceRef.class)) != null) {
                        annotations.add(new AnnotationCacheEntry(method.getName(), method.getParameterTypes(), ((WebServiceRef) webServiceRefAnnotation).name(), AnnotationCacheEntryType.SETTER));
                    } else if (JPA_PRESENT && (persistenceContextAnnotation = method.getAnnotation(PersistenceContext.class)) != null) {
                        annotations.add(new AnnotationCacheEntry(method.getName(), method.getParameterTypes(), ((PersistenceContext) persistenceContextAnnotation).name(), AnnotationCacheEntryType.SETTER));
                    } else if (JPA_PRESENT && (persistenceUnitAnnotation = method.getAnnotation(PersistenceUnit.class)) != null) {
                        annotations.add(new AnnotationCacheEntry(method.getName(), method.getParameterTypes(), ((PersistenceUnit) persistenceUnitAnnotation).name(), AnnotationCacheEntryType.SETTER));
                    }
                }
                postConstruct = findPostConstruct(postConstruct, postConstructFromXml, method);
                preDestroy = findPreDestroy(preDestroy, preDestroyFromXml, method);
            }
            if (postConstruct != null) {
                annotations.add(new AnnotationCacheEntry(postConstruct.getName(), postConstruct.getParameterTypes(), null, AnnotationCacheEntryType.POST_CONSTRUCT));
            } else if (postConstructFromXml != null) {
                throw new IllegalArgumentException("Post construct method " + postConstructFromXml + " for class " + clazz.getName() + " is declared in deployment descriptor but cannot be found.");
            }
            if (preDestroy != null) {
                annotations.add(new AnnotationCacheEntry(preDestroy.getName(), preDestroy.getParameterTypes(), null, AnnotationCacheEntryType.PRE_DESTROY));
            } else if (preDestroyFromXml != null) {
                throw new IllegalArgumentException("Pre destroy method " + preDestroyFromXml + " for class " + clazz.getName() + " is declared in deployment descriptor but cannot be found.");
            }
            if (annotations.isEmpty()) {
                // Use common object to save memory
                annotationsArray = ANNOTATIONS_EMPTY;
            } else {
                annotationsArray = annotations.toArray(new AnnotationCacheEntry[annotations.size()]);
            }
            synchronized (annotationCache) {
                annotationCache.put(clazz, annotationsArray);
            }
        }
        clazz = clazz.getSuperclass();
    }
}
Also used : Resource(javax.annotation.Resource) PersistenceContext(javax.persistence.PersistenceContext) Method(java.lang.reflect.Method) Annotation(java.lang.annotation.Annotation) Field(java.lang.reflect.Field) PersistenceUnit(javax.persistence.PersistenceUnit) EJB(javax.ejb.EJB) WebServiceRef(javax.xml.ws.WebServiceRef)

Example 5 with WebServiceRef

use of javax.xml.ws.WebServiceRef in project Payara by payara.

the class InjectionServicesImpl method getLookupName.

/**
 * Returns the JNDI name to lookup
 * <p>
 * This calls getJndiName with the appropriate arguments for the annotation type
 * @param annotatedClass
 * @param annotatedField
 * @param injectionResources
 * @return
 */
private String getLookupName(Class annotatedClass, AnnotatedField annotatedField, List<InjectionCapable> injectionResources) {
    String lookupName = null;
    if (annotatedField.isAnnotationPresent(Resource.class)) {
        Resource resource = annotatedField.getAnnotation(Resource.class);
        lookupName = getJndiName(resource.lookup(), resource.mappedName(), resource.name());
    } else if (annotatedField.isAnnotationPresent(EJB.class)) {
        EJB ejb = annotatedField.getAnnotation(EJB.class);
        lookupName = getJndiName(ejb.lookup(), ejb.mappedName(), ejb.name());
    } else if (annotatedField.isAnnotationPresent(WebServiceRef.class)) {
        WebServiceRef webServiceRef = annotatedField.getAnnotation(WebServiceRef.class);
        lookupName = getJndiName(webServiceRef.lookup(), webServiceRef.mappedName(), webServiceRef.name());
    } else if (annotatedField.isAnnotationPresent(PersistenceUnit.class)) {
        PersistenceUnit persistenceUnit = annotatedField.getAnnotation(PersistenceUnit.class);
        lookupName = getJndiName(persistenceUnit.unitName(), null, persistenceUnit.name());
    } else if (annotatedField.isAnnotationPresent(PersistenceContext.class)) {
        PersistenceContext persistenceContext = annotatedField.getAnnotation(PersistenceContext.class);
        lookupName = getJndiName(persistenceContext.unitName(), null, persistenceContext.name());
    }
    if (lookupName == null || lookupName.trim().length() == 0) {
        lookupName = getComponentEnvName(annotatedClass, annotatedField.getJavaMember().getName(), injectionResources);
    }
    return lookupName;
}
Also used : PersistenceUnit(javax.persistence.PersistenceUnit) Resource(javax.annotation.Resource) PersistenceContext(javax.persistence.PersistenceContext) EJB(javax.ejb.EJB) WebServiceRef(javax.xml.ws.WebServiceRef)

Aggregations

WebServiceRef (javax.xml.ws.WebServiceRef)6 Resource (javax.annotation.Resource)3 EJB (javax.ejb.EJB)3 PersistenceContext (javax.persistence.PersistenceContext)3 PersistenceUnit (javax.persistence.PersistenceUnit)3 Field (java.lang.reflect.Field)2 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 WebServiceRefs (javax.xml.ws.WebServiceRefs)2 Annotation (java.lang.annotation.Annotation)1 HandlerProcessingResult (org.glassfish.apf.HandlerProcessingResult)1 ManagedReferenceFactory (org.jboss.as.naming.ManagedReferenceFactory)1 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)1 WSRefAnnotationWrapper (org.jboss.as.webservices.webserviceref.WSRefAnnotationWrapper)1