@Override public Object resolveResource(InjectionPoint injectionPoint) { final Member member = injectionPoint.getMember(); AnnotatedMember<?> annotatedMember; if (injectionPoint.getAnnotated() instanceof AnnotatedField) { annotatedMember = (AnnotatedField<?>) injectionPoint.getAnnotated(); } else { annotatedMember = ((AnnotatedParameter<?>) injectionPoint.getAnnotated()).getDeclaringCallable(); } if (!annotatedMember.isAnnotationPresent(Resource.class)) { throw WeldLogger.ROOT_LOGGER.annotationNotFound(Resource.class, member); } if (member instanceof Method && ((Method) member).getParameterTypes().length != 1) { throw WeldLogger.ROOT_LOGGER.injectionPointNotAJavabean((Method) member); } String name = getResourceName(injectionPoint); for (ResourceInjectionResolver resolver : resourceResolvers) { Object result = resolver.resolve(name); if (result != null) { return result; } } try { return context.lookup(name); } catch (NamingException e) { throw WeldLogger.ROOT_LOGGER.couldNotFindResource(name, injectionPoint.getMember().toString(), e); } }
public synchronized void tryRegisterExtension(final Class<?> extensionClass, final DeploymentUnit deploymentUnit) throws DeploymentUnitProcessingException { if (!Extension.class.isAssignableFrom(extensionClass)) { throw WeldLogger.ROOT_LOGGER.extensionDoesNotImplementExtension(extensionClass); } if (extensions.containsKey(extensionClass)) { return; } try { extensions.put(extensionClass, new MetadataImpl<>((Extension) extensionClass.newInstance(), deploymentUnit.getName())); } catch (Exception e) { WeldLogger.DEPLOYMENT_LOGGER.couldNotLoadPortableExceptionClass(extensionClass.getName(), e); } }
public static String getResourceName(String jndiName, String mappedName) { if (mappedName != null) { return mappedName; } else if (jndiName != null) { return jndiName; } else { throw WeldLogger.ROOT_LOGGER.cannotDetermineResourceName(); } }
propertyName = getPropertyName((Method) injectionPoint.getMember()); if (propertyName == null) { throw WeldLogger.ROOT_LOGGER.injectionPointNotAJavabean((Method) injectionPoint.getMember()); throw WeldLogger.ROOT_LOGGER.cannotInject(injectionPoint);
EJB ejb = ResourceInjectionUtilities.getResourceAnnotated(injectionPoint).getAnnotation(EJB.class); if (ejb == null) { throw WeldLogger.ROOT_LOGGER.annotationNotFound(EJB.class, injectionPoint.getMember()); throw WeldLogger.ROOT_LOGGER.injectionPointNotAJavabean((Method) injectionPoint.getMember());
@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); } }
@SuppressWarnings("unchecked") private Class<Extension> loadExtension(String serviceClassName, final ClassLoader loader) throws DeploymentUnitProcessingException { try { return (Class<Extension>) loader.loadClass(serviceClassName); } catch (Exception e) { WeldLogger.DEPLOYMENT_LOGGER.couldNotLoadPortableExceptionClass(serviceClassName, e); } catch (LinkageError e) { WeldLogger.DEPLOYMENT_LOGGER.couldNotLoadPortableExceptionClass(serviceClassName, e); } return null; }
@Override public Object resolveResource(String jndiName, String mappedName) { String name = ResourceInjectionUtilities.getResourceName(jndiName, mappedName); try { return context.lookup(name); } catch (NamingException e) { throw WeldLogger.ROOT_LOGGER.couldNotFindResource(name, e); } } }
propertyName = getPropertyName((Method) injectionPoint.getMember()); if (propertyName == null) { throw WeldLogger.ROOT_LOGGER.injectionPointNotAJavabean((Method) injectionPoint.getMember()); throw WeldLogger.ROOT_LOGGER.cannotInject(injectionPoint);
@Override public ResourceReferenceFactory<EntityManagerFactory> registerPersistenceUnitInjectionPoint(final InjectionPoint injectionPoint) { //TODO: cache this stuff final PersistenceUnit context = getResourceAnnotated(injectionPoint).getAnnotation(PersistenceUnit.class); if (context == null) { throw WeldLogger.ROOT_LOGGER.annotationNotFound(PersistenceUnit.class, injectionPoint.getMember()); } final String scopedPuName = getScopedPUName(deploymentUnit, context.unitName(), injectionPoint.getMember()); final ServiceName persistenceUnitServiceName = PersistenceUnitServiceImpl.getPUServiceName(scopedPuName); final ServiceController<?> serviceController = deploymentUnit.getServiceRegistry().getRequiredService(persistenceUnitServiceName); //now we have the service controller, as this method is only called at runtime the service should //always be up final PersistenceUnitServiceImpl persistenceUnitService = (PersistenceUnitServiceImpl) serviceController.getValue(); return new ImmediateResourceReferenceFactory<EntityManagerFactory>(persistenceUnitService.getEntityManagerFactory()); }
public Object doLookup(String jndiName, String mappedName) { String name = ResourceInjectionUtilities.getResourceName(jndiName, mappedName); try { return new InitialContext().lookup(name); } catch (NamingException e) { throw WeldLogger.ROOT_LOGGER.couldNotFindResource(name, e); } }
private String getEjbBindLocation(InjectionPoint injectionPoint) { EJB ejb = ResourceInjectionUtilities.getResourceAnnotated(injectionPoint).getAnnotation(EJB.class); String mappedName = ejb.mappedName(); if (!mappedName.equals("")) { return mappedName; } String name = ejb.name(); if (!name.equals("")) { return ResourceInjectionUtilities.RESOURCE_LOOKUP_PREFIX + "/" + name; } String propertyName; if (injectionPoint.getMember() instanceof Field) { propertyName = injectionPoint.getMember().getName(); } else if (injectionPoint.getMember() instanceof Method) { propertyName = ResourceInjectionUtilities.getPropertyName((Method) injectionPoint.getMember()); if (propertyName == null) { throw WeldLogger.ROOT_LOGGER.injectionPointNotAJavabean((Method) injectionPoint.getMember()); } } else { throw WeldLogger.ROOT_LOGGER.cannotInject(injectionPoint); } String className = injectionPoint.getMember().getDeclaringClass().getName(); return ResourceInjectionUtilities.RESOURCE_LOOKUP_PREFIX + "/" + className + "/" + propertyName; }
public synchronized void tryRegisterExtension(final Class<?> extensionClass, final DeploymentUnit deploymentUnit) throws DeploymentUnitProcessingException { if (!Extension.class.isAssignableFrom(extensionClass)) { throw WeldLogger.ROOT_LOGGER.extensionDoesNotImplementExtension(extensionClass); } if (extensions.containsKey(extensionClass)) { return; } try { extensions.put(extensionClass, new MetadataImpl<>((Extension) extensionClass.newInstance(), deploymentUnit.getName())); } catch (Exception e) { WeldLogger.DEPLOYMENT_LOGGER.couldNotLoadPortableExceptionClass(extensionClass.getName(), e); } }
@Override public ResourceReferenceFactory<EntityManager> registerPersistenceContextInjectionPoint(final InjectionPoint injectionPoint) { //TODO: cache this stuff final PersistenceContext context = getResourceAnnotated(injectionPoint).getAnnotation(PersistenceContext.class); if (context == null) { throw WeldLogger.ROOT_LOGGER.annotationNotFound(PersistenceContext.class, injectionPoint.getMember()); } final String scopedPuName = getScopedPUName(deploymentUnit, context.unitName(), injectionPoint.getMember()); final ServiceName persistenceUnitServiceName = PersistenceUnitServiceImpl.getPUServiceName(scopedPuName); final ServiceController<?> serviceController = deploymentUnit.getServiceRegistry().getRequiredService(persistenceUnitServiceName); //now we have the service controller, as this method is only called at runtime the service should //always be up final PersistenceUnitServiceImpl persistenceUnitService = (PersistenceUnitServiceImpl) serviceController.getValue(); return new EntityManagerResourceReferenceFactory(scopedPuName, persistenceUnitService.getEntityManagerFactory(), context, deploymentUnit.getAttachment(JpaAttachments.TRANSACTION_SYNCHRONIZATION_REGISTRY), ContextTransactionManager.getInstance()); }
public static String getResourceName(String jndiName, String mappedName) { if (mappedName != null) { return mappedName; } else if (jndiName != null) { return jndiName; } else { throw WeldLogger.ROOT_LOGGER.cannotDetermineResourceName(); } }