use of org.jboss.jandex.AnnotationTarget in project wildfly by wildfly.
the class JSFAnnotationProcessor method deploy.
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final Map<Class<? extends Annotation>, Set<Class<?>>> instances = new HashMap<Class<? extends Annotation>, Set<Class<?>>>();
final CompositeIndex compositeIndex = deploymentUnit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX);
if (compositeIndex == null) {
// Can not continue without index
return;
}
final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
if (module == null) {
// Can not continue without module
return;
}
final ClassLoader classLoader = module.getClassLoader();
for (FacesAnnotation annotation : FacesAnnotation.values()) {
final List<AnnotationInstance> annotationInstances = compositeIndex.getAnnotations(annotation.indexName);
if (annotationInstances == null || annotationInstances.isEmpty()) {
continue;
}
final Set<Class<?>> discoveredClasses = new HashSet<Class<?>>();
instances.put(annotation.annotationClass, discoveredClasses);
for (AnnotationInstance annotationInstance : annotationInstances) {
final AnnotationTarget target = annotationInstance.target();
if (target instanceof ClassInfo) {
final DotName className = ClassInfo.class.cast(target).name();
final Class<?> annotatedClass;
try {
annotatedClass = classLoader.loadClass(className.toString());
} catch (ClassNotFoundException e) {
throw new DeploymentUnitProcessingException(JSFLogger.ROOT_LOGGER.classLoadingFailed(className));
}
discoveredClasses.add(annotatedClass);
} else {
throw new DeploymentUnitProcessingException(JSFLogger.ROOT_LOGGER.invalidAnnotationLocation(annotation, target));
}
}
}
deploymentUnit.addToAttachmentList(ServletContextAttribute.ATTACHMENT_KEY, new ServletContextAttribute(FACES_ANNOTATIONS_SC_ATTR, instances));
}
use of org.jboss.jandex.AnnotationTarget in project wildfly by wildfly.
the class JPAAnnotationProcessor method processPersistenceAnnotations.
private void processPersistenceAnnotations(final DeploymentUnit deploymentUnit, final EEModuleDescription eeModuleDescription, List<AnnotationInstance> persistenceContexts, final EEApplicationClasses applicationClasses) throws DeploymentUnitProcessingException {
for (AnnotationInstance annotation : persistenceContexts) {
ClassInfo declaringClass;
final AnnotationTarget annotationTarget = annotation.target();
if (annotationTarget instanceof FieldInfo) {
FieldInfo fieldInfo = (FieldInfo) annotationTarget;
declaringClass = fieldInfo.declaringClass();
EEModuleClassDescription eeModuleClassDescription = eeModuleDescription.addOrGetLocalClassDescription(declaringClass.name().toString());
this.processField(deploymentUnit, annotation, fieldInfo, eeModuleClassDescription);
} else if (annotationTarget instanceof MethodInfo) {
MethodInfo methodInfo = (MethodInfo) annotationTarget;
declaringClass = methodInfo.declaringClass();
EEModuleClassDescription eeModuleClassDescription = eeModuleDescription.addOrGetLocalClassDescription(declaringClass.name().toString());
this.processMethod(deploymentUnit, annotation, methodInfo, eeModuleClassDescription);
} else if (annotationTarget instanceof ClassInfo) {
declaringClass = (ClassInfo) annotationTarget;
EEModuleClassDescription eeModuleClassDescription = eeModuleDescription.addOrGetLocalClassDescription(declaringClass.name().toString());
this.processClass(deploymentUnit, annotation, eeModuleClassDescription);
}
}
}
use of org.jboss.jandex.AnnotationTarget in project wildfly by wildfly.
the class WSClassVerificationProcessor method verifyApacheCXFModuleDependencyRequirement.
private void verifyApacheCXFModuleDependencyRequirement(DeploymentUnit unit) {
if (!hasCxfModuleDependency(unit)) {
//notify user if he clearly forgot the CXF module dependency
final CompositeIndex index = unit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX);
final DotName[] dotNames = { WEB_SERVICE_ANNOTATION, WEB_SERVICE_PROVIDER_ANNOTATION };
for (final DotName dotName : dotNames) {
for (AnnotationInstance ai : index.getAnnotations(dotName)) {
AnnotationTarget at = ai.target();
if (at instanceof ClassInfo) {
final ClassInfo clazz = (ClassInfo) ai.target();
for (DotName dn : clazz.annotations().keySet()) {
if (dn.toString().startsWith("org.apache.cxf")) {
WSLogger.ROOT_LOGGER.missingModuleDependency(dn.toString(), clazz.name().toString(), "org.apache.cxf");
}
}
}
}
}
}
}
use of org.jboss.jandex.AnnotationTarget in project wildfly by wildfly.
the class WSHandlerChainAnnotationProcessor method processHandlerChainAnnotations.
private static void processHandlerChainAnnotations(final ResourceRoot currentResourceRoot, final List<ResourceRoot> resourceRoots, final Index index, final WSEndpointHandlersMapping mapping) throws DeploymentUnitProcessingException {
final List<AnnotationInstance> webServiceAnnotations = index.getAnnotations(WEB_SERVICE_ANNOTATION);
final List<AnnotationInstance> webServiceProviderAnnotations = index.getAnnotations(WEB_SERVICE_PROVIDER_ANNOTATION);
for (final AnnotationInstance annotationInstance : webServiceAnnotations) {
final AnnotationTarget annotationTarget = annotationInstance.target();
if (annotationTarget instanceof ClassInfo) {
final ClassInfo classInfo = (ClassInfo) annotationTarget;
if (isJaxwsEndpoint(classInfo, index)) {
AnnotationInstance handlerChainAnnotationInstance = getHandlerChainAnnotationInstance(classInfo);
//implementation bean. The service implementation bean’s @HandlerChain is used if @HandlerChain is present on both."
if (handlerChainAnnotationInstance == null) {
handlerChainAnnotationInstance = getEndpointInterfaceHandlerChainAnnotationInstance(classInfo, index);
}
if (handlerChainAnnotationInstance != null) {
final String endpointClass = classInfo.name().toString();
processHandlerChainAnnotation(currentResourceRoot, resourceRoots, handlerChainAnnotationInstance, endpointClass, mapping);
}
}
} else {
// We ignore fields & methods annotated with @HandlerChain.
// These are used always in combination with @WebServiceRef
// which are always referencing JAXWS client proxies only.
}
}
for (final AnnotationInstance annotationInstance : webServiceProviderAnnotations) {
final AnnotationTarget annotationTarget = annotationInstance.target();
if (annotationTarget instanceof ClassInfo) {
final ClassInfo classInfo = (ClassInfo) annotationTarget;
final AnnotationInstance handlerChainAnnotationInstance = getHandlerChainAnnotationInstance(classInfo);
if (handlerChainAnnotationInstance != null && isJaxwsEndpoint(classInfo, index)) {
final String endpointClass = classInfo.name().toString();
processHandlerChainAnnotation(currentResourceRoot, resourceRoots, handlerChainAnnotationInstance, endpointClass, mapping);
}
} else {
// We ignore fields & methods annotated with @HandlerChain.
// These are used always in combination with @WebServiceRef
// which are always referencing JAXWS client proxies only.
}
}
}
use of org.jboss.jandex.AnnotationTarget in project wildfly by wildfly.
the class JandexAnnotationRepositoryImpl method getAnnotation.
@Override
public Collection<Annotation> getAnnotation(Class<?> annotationClass) {
List<AnnotationInstance> instances = backingRepository.getAnnotations(DotName.createSimple(annotationClass.getName()));
ArrayList<Annotation> annotations = new ArrayList<Annotation>(instances.size());
for (AnnotationInstance instance : instances) {
AnnotationTarget target = instance.target();
Annotation annotation = null;
if (target instanceof MethodInfo) {
MethodInfo m = (MethodInfo) target;
List<String> parameterTypes = new ArrayList<String>(m.args().length);
for (Type type : m.args()) {
parameterTypes.add(type.toString());
}
String declaringClass = m.declaringClass().name().toString();
annotation = new AnnotationImpl(declaringClass, cl, parameterTypes, m.name(), true, false, annotationClass);
}
if (target instanceof FieldInfo) {
FieldInfo f = (FieldInfo) target;
String declaringClass = f.declaringClass().name().toString();
annotation = new AnnotationImpl(declaringClass, cl, null, f.name(), false, true, annotationClass);
}
if (target instanceof ClassInfo) {
ClassInfo c = (ClassInfo) target;
annotation = new AnnotationImpl(c.name().toString(), cl, null, null, false, false, annotationClass);
}
if (annotation != null) {
annotations.add(annotation);
}
}
annotations.trimToSize();
if (annotations.size() == 0) {
return null;
} else {
return Collections.unmodifiableList(annotations);
}
}
Aggregations