use of org.glassfish.apf.AnnotationInfo in project Payara by payara.
the class AnnotationProcessorImpl method processParameters.
private HandlerProcessingResult processParameters(ProcessingContext ctx, Annotation[][] parametersAnnotations) throws AnnotationProcessorException {
HandlerProcessingResultImpl result = new HandlerProcessingResultImpl();
// process the method parameters...
for (Annotation[] parameterAnnotations : parametersAnnotations) {
logStart(ctx.getHandler(), ElementType.PARAMETER, null);
if (parameterAnnotations != null) {
for (Annotation annotation : parameterAnnotations) {
AnnotationInfo info = new AnnotationInfo(ctx, null, annotation, ElementType.PARAMETER);
process(ctx, info, result);
dumpProcessingResult(result);
}
}
logEnd(ctx.getHandler(), ElementType.PARAMETER, null);
}
return result;
}
use of org.glassfish.apf.AnnotationInfo in project Payara by payara.
the class ConnectorValidator method accept.
public void accept(ConnectorDescriptor descriptor) {
// make sure that the ActivationSpec class implement ActivationSpec interface.
validateActivationSpec(descriptor);
// validate & process annotations if a valid connector annotation is not already processed
if (!descriptor.getValidConnectorAnnotationProcessed()) {
Set<AnnotationInfo> annotations = descriptor.getConnectorAnnotations();
String raClass = descriptor.getResourceAdapterClass();
if (annotations.size() == 0) {
return;
}
// only one annotation is present
if (annotations.size() == 1) {
Iterator<AnnotationInfo> it = annotations.iterator();
AnnotationInfo annotationInfo = it.next();
Class claz = (Class) annotationInfo.getAnnotatedElement();
Connector connector = (Connector) annotationInfo.getAnnotation();
ConnectorAnnotationHandler.processDescriptor(claz, connector, descriptor);
Collection<AnnotationInfo> configProperties = descriptor.getConfigPropertyAnnotations(claz.getName());
if (configProperties != null) {
for (AnnotationInfo ai : configProperties) {
ConfigPropertyHandler handler = new ConfigPropertyHandler();
try {
handler.processAnnotation(ai);
} catch (AnnotationProcessorException e) {
RuntimeException re = new RuntimeException("Unable to process ConfigProperty " + "annotation in class [" + claz.getName() + "] : " + e.getMessage());
re.initCause(e);
throw re;
}
}
}
} else {
// are present, ignore them.
if (raClass == null || raClass.equals("")) {
// all the cases below are unacceptable, fail deployment
if (annotations.size() > 1) {
throw new RuntimeException("cannot determine appropriate @Connector annotation as multiple " + "annotations are present");
}
}
}
}
// check whether outbound is defined, if so, atleast one connection-definition must be present
if (descriptor.getOutBoundDefined()) {
Set connectionDefinitions = descriptor.getOutboundResourceAdapter().getConnectionDefs();
if (connectionDefinitions.size() == 0) {
throw new RuntimeException("Invalid connector descriptor for RAR [ " + descriptor.getName() + " ], when " + "outbound-resource-adapter is specified," + "atleast one connection-definition must be specified either via annotation or via descriptor");
}
}
if (_logger.isLoggable(Level.FINEST)) {
_logger.log(Level.FINEST, descriptor.toString());
}
processConfigProperties(descriptor);
// processed all annotations, clear from book-keeping
descriptor.getConnectorAnnotations().clear();
descriptor.getAllConfigPropertyAnnotations().clear();
descriptor.getConfigPropertyProcessedClasses().clear();
}
use of org.glassfish.apf.AnnotationInfo in project Payara by payara.
the class AnnotationProcessorImpl method process.
private void process(ProcessingContext ctx, AnnotationInfo element, HandlerProcessingResultImpl result) throws AnnotationProcessorException {
Annotation annotation = element.getAnnotation();
if (AnnotationUtils.shouldLog("annotation")) {
logger.finer("Annotation : " + annotation.annotationType().getName() + " delegate = " + delegate);
}
result.addResult(annotation.annotationType(), ResultType.UNPROCESSED);
// we ignore all java.* annotations
Package annPackage = annotation.annotationType().getPackage();
if (annPackage != null && annPackage.getName().startsWith("java.lang"))
return;
List<AnnotationHandler> annotationHandlers = handlers.get(annotation.annotationType().getName());
if (annotationHandlers != null) {
for (AnnotationHandler handler : annotationHandlers) {
// here we need to be careful, we are ready to invoke a handler
// to process a particular annotation type. However, this handler
// may have defined a list of annotations that should be processed
// (if present on the annotated element) before itself.
// do this check and process those annotations first.
Class<? extends Annotation>[] dependencies = handler.getTypeDependencies();
if (dependencies != null) {
AnnotatedElement ae = element.getAnnotatedElement();
for (Class<? extends Annotation> annotationType : dependencies) {
Annotation depAnnotation = ae.getAnnotation(annotationType);
if (depAnnotation != null) {
ResultType resultType = result.processedAnnotations().get(annotationType);
if (resultType == null || resultType == ResultType.UNPROCESSED) {
// annotation is present, process it.
AnnotationInfo info = new AnnotationInfo(ctx, ae, depAnnotation, getTopElementType());
process(ctx, info, result);
}
}
}
}
// at this point, all annotation that I declared depending on
// are processed
HandlerProcessingResult processingResult = null;
try {
processingResult = handler.processAnnotation(element);
} catch (AnnotationProcessorException ape) {
// I am logging this exception
log(Level.SEVERE, ape.getLocator(), ape.getMessage());
// errors.
if (ape.isFatal()) {
throw ape;
}
if (++errorCount > 100) {
throw new AnnotationProcessorException(AnnotationUtils.getLocalString("enterprise.deployment.annotation.toomanyerror", "Too many errors, annotation processing abandoned."));
}
processingResult = HandlerProcessingResultImpl.getDefaultResult(annotation.annotationType(), ResultType.FAILED);
} catch (Throwable e) {
AnnotationProcessorException ape = new AnnotationProcessorException(e.getMessage(), element);
ape.initCause(e);
throw ape;
}
result.addAll(processingResult);
}
} else {
if (delegate != null) {
delegate.process(ctx, element, result);
} else {
ctx.getErrorHandler().fine(new AnnotationProcessorException("No handler defined for " + annotation.annotationType()));
}
}
}
Aggregations