use of org.jboss.jandex.AnnotationInstance 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.AnnotationInstance in project wildfly by wildfly.
the class HibernateSearchProcessor method addSearchDependency.
private void addSearchDependency(ModuleSpecification moduleSpecification, ModuleLoader moduleLoader, DeploymentUnit deploymentUnit) throws DeploymentUnitProcessingException {
String searchModuleName = null;
PersistenceUnitsInApplication persistenceUnitsInApplication = DeploymentUtils.getTopDeploymentUnit(deploymentUnit).getAttachment(PersistenceUnitsInApplication.PERSISTENCE_UNITS_IN_APPLICATION);
for (PersistenceUnitMetadataHolder holder : persistenceUnitsInApplication.getPersistenceUnitHolders()) {
for (PersistenceUnitMetadata pu : holder.getPersistenceUnits()) {
String providerModule = pu.getProperties().getProperty(Configuration.HIBERNATE_SEARCH_MODULE);
if (providerModule != null) {
// one persistence unit specifying the Hibernate search module is allowed
if (searchModuleName == null) {
searchModuleName = providerModule;
} else // more than one persistence unit specifying different Hibernate search module names is not allowed
if (!providerModule.equals(searchModuleName)) {
throw JpaLogger.ROOT_LOGGER.differentSearchModuleDependencies(deploymentUnit.getName(), searchModuleName, providerModule);
}
}
}
}
if (NONE.equals(searchModuleName)) {
// Hibernate Search module will not be added to deployment
ROOT_LOGGER.debugf("Not adding Hibernate Search dependency to deployment %s", deploymentUnit.getName());
return;
}
// use Search module name specified in persistence unit definition
if (searchModuleName != null && !IGNORE.equals(searchModuleName)) {
ModuleIdentifier moduleIdentifier = ModuleIdentifier.fromString(searchModuleName);
moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, moduleIdentifier, false, true, true, false));
ROOT_LOGGER.debugf("added %s dependency to %s", moduleIdentifier, deploymentUnit.getName());
} else {
// add Hibernate Search module dependency if application is using the Hibernate Search Indexed annotation
final CompositeIndex index = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.COMPOSITE_ANNOTATION_INDEX);
List<AnnotationInstance> annotations = index.getAnnotations(SEARCH_INDEXED_ANNOTATION_NAME);
if (annotations != null && annotations.size() > 0) {
moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, defaultSearchModule, false, true, true, false));
ROOT_LOGGER.debugf("deployment %s contains %s annotation, added %s dependency", deploymentUnit.getName(), SEARCH_INDEXED_ANNOTATION_NAME, defaultSearchModule);
}
}
}
use of org.jboss.jandex.AnnotationInstance in project wildfly by wildfly.
the class JPAAnnotationProcessor method bindClassSources.
private void bindClassSources(final DeploymentUnit deploymentUnit, final AnnotationInstance annotation, final EEModuleClassDescription classDescription) throws DeploymentUnitProcessingException {
// handle PersistenceContext and PersistenceUnit annotations
if (isPersistenceContext(annotation) || isPersistenceUnit(annotation)) {
String injectionTypeName = getClassLevelInjectionType(annotation);
InjectionSource injectionSource = getBindingSource(deploymentUnit, annotation, injectionTypeName, classDescription);
if (injectionSource != null) {
final AnnotationValue nameValue = annotation.value("name");
if (nameValue == null || nameValue.asString().isEmpty()) {
classDescription.setInvalid(JpaLogger.ROOT_LOGGER.classLevelAnnotationParameterRequired(annotation.name().toString(), classDescription.getClassName(), "name"));
return;
}
final String name = nameValue.asString();
final BindingConfiguration bindingConfiguration = new BindingConfiguration(name, injectionSource);
classDescription.getBindingConfigurations().add(bindingConfiguration);
}
} else if (isPersistenceUnits(annotation)) {
// handle PersistenceUnits (array of PersistenceUnit)
AnnotationValue containedPersistenceUnits = annotation.value("value");
AnnotationInstance[] arrayPersistenceUnits;
if (containedPersistenceUnits != null && (arrayPersistenceUnits = containedPersistenceUnits.asNestedArray()) != null) {
for (int source = 0; source < arrayPersistenceUnits.length; source++) {
String injectionTypeName = getClassLevelInjectionType(arrayPersistenceUnits[source]);
InjectionSource injectionSource = getBindingSource(deploymentUnit, arrayPersistenceUnits[source], injectionTypeName, classDescription);
if (injectionSource != null) {
final AnnotationValue nameValue = arrayPersistenceUnits[source].value("name");
if (nameValue == null || nameValue.asString().isEmpty()) {
classDescription.setInvalid(JpaLogger.ROOT_LOGGER.classLevelAnnotationParameterRequired(arrayPersistenceUnits[source].name().toString(), classDescription.getClassName(), "name"));
return;
}
final String name = nameValue.asString();
final BindingConfiguration bindingConfiguration = new BindingConfiguration(name, injectionSource);
classDescription.getBindingConfigurations().add(bindingConfiguration);
}
}
}
} else if (isPersistenceContexts(annotation)) {
// handle PersistenceContexts (array of PersistenceContext)
AnnotationValue containedPersistenceContexts = annotation.value("value");
AnnotationInstance[] arrayPersistenceContexts;
if (containedPersistenceContexts != null && (arrayPersistenceContexts = containedPersistenceContexts.asNestedArray()) != null) {
for (int source = 0; source < arrayPersistenceContexts.length; source++) {
String injectionTypeName = getClassLevelInjectionType(arrayPersistenceContexts[source]);
InjectionSource injectionSource = getBindingSource(deploymentUnit, arrayPersistenceContexts[source], injectionTypeName, classDescription);
if (injectionSource != null) {
final AnnotationValue nameValue = arrayPersistenceContexts[source].value("name");
if (nameValue == null || nameValue.asString().isEmpty()) {
classDescription.setInvalid(JpaLogger.ROOT_LOGGER.classLevelAnnotationParameterRequired(arrayPersistenceContexts[source].name().toString(), classDescription.getClassName(), "name"));
return;
}
final String name = nameValue.asString();
final BindingConfiguration bindingConfiguration = new BindingConfiguration(name, injectionSource);
classDescription.getBindingConfigurations().add(bindingConfiguration);
}
}
}
}
}
use of org.jboss.jandex.AnnotationInstance in project wildfly by wildfly.
the class JPAAnnotationProcessor method getBindingSource.
private InjectionSource getBindingSource(final DeploymentUnit deploymentUnit, final AnnotationInstance annotation, String injectionTypeName, final EEModuleClassDescription classDescription) throws DeploymentUnitProcessingException {
PersistenceUnitMetadata pu = getPersistenceUnit(deploymentUnit, annotation, classDescription);
if (pu == null) {
return null;
}
String scopedPuName = pu.getScopedPersistenceUnitName();
ServiceName puServiceName = getPuServiceName(scopedPuName);
if (isPersistenceContext(annotation)) {
if (pu.getTransactionType() == PersistenceUnitTransactionType.RESOURCE_LOCAL) {
classDescription.setInvalid(JpaLogger.ROOT_LOGGER.cannotInjectResourceLocalEntityManager());
return null;
}
AnnotationValue pcType = annotation.value("type");
PersistenceContextType type = (pcType == null || PersistenceContextType.TRANSACTION.name().equals(pcType.asString())) ? PersistenceContextType.TRANSACTION : PersistenceContextType.EXTENDED;
AnnotationValue stType = annotation.value("synchronization");
SynchronizationType synchronizationType = (stType == null || SynchronizationType.SYNCHRONIZED.name().equals(stType.asString())) ? SynchronizationType.SYNCHRONIZED : SynchronizationType.UNSYNCHRONIZED;
Map<String, String> properties;
AnnotationValue value = annotation.value("properties");
AnnotationInstance[] props = value != null ? value.asNestedArray() : null;
if (props != null) {
properties = new HashMap<>();
for (int source = 0; source < props.length; source++) {
properties.put(props[source].value("name").asString(), props[source].value("value").asString());
}
} else {
properties = null;
}
// get deployment settings from top level du (jboss-all.xml is only parsed at the top level).
final JPADeploymentSettings jpaDeploymentSettings = DeploymentUtils.getTopDeploymentUnit(deploymentUnit).getAttachment(JpaAttachments.DEPLOYMENT_SETTINGS_KEY);
return new PersistenceContextInjectionSource(type, synchronizationType, properties, puServiceName, deploymentUnit.getServiceRegistry(), scopedPuName, injectionTypeName, pu, jpaDeploymentSettings);
} else {
return new PersistenceUnitInjectionSource(puServiceName, deploymentUnit.getServiceRegistry(), injectionTypeName, pu);
}
}
use of org.jboss.jandex.AnnotationInstance 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);
}
}
}
Aggregations