Search in sources :

Example 1 with Connector

use of javax.resource.spi.Connector 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();
}
Also used : Connector(javax.resource.spi.Connector) Set(java.util.Set) ConfigPropertyHandler(com.sun.enterprise.connectors.deployment.annotation.handlers.ConfigPropertyHandler) AnnotationProcessorException(org.glassfish.apf.AnnotationProcessorException) AnnotationInfo(org.glassfish.apf.AnnotationInfo)

Example 2 with Connector

use of javax.resource.spi.Connector in project Payara by payara.

the class ConnectorAnnotationHandler method processAnnotation.

public HandlerProcessingResult processAnnotation(AnnotationInfo element) throws AnnotationProcessorException {
    AnnotatedElementHandler aeHandler = element.getProcessingContext().getHandler();
    Connector connector = (Connector) element.getAnnotation();
    List<Class<? extends Annotation>> list = new ArrayList<Class<? extends Annotation>>();
    list.add(getAnnotationType());
    if (aeHandler instanceof RarBundleContext) {
        RarBundleContext rarContext = (RarBundleContext) aeHandler;
        ConnectorDescriptor desc = rarContext.getDescriptor();
        Class annotatedClass = (Class) element.getAnnotatedElement();
        if (desc.getResourceAdapterClass().equals("")) {
            desc.addConnectorAnnotation(element);
            return getSuccessfulProcessedResult(list);
        } else if (!isResourceAdapterClass(annotatedClass)) {
            desc.addConnectorAnnotation(element);
            return getSuccessfulProcessedResult(list);
        } else if (!desc.getResourceAdapterClass().equals(annotatedClass.getName())) {
            desc.addConnectorAnnotation(element);
            return getSuccessfulProcessedResult(list);
        } else {
            processDescriptor(annotatedClass, connector, desc);
            desc.setValidConnectorAnnotationProcessed(true);
        }
    } else {
        String logMessage = "Not a rar bundle context";
        return getFailureResult(element, logMessage, true);
    }
    return getSuccessfulProcessedResult(list);
}
Also used : Connector(javax.resource.spi.Connector) ConnectorDescriptor(com.sun.enterprise.deployment.ConnectorDescriptor) ArrayList(java.util.ArrayList) RarBundleContext(com.sun.enterprise.deployment.annotation.context.RarBundleContext) Annotation(java.lang.annotation.Annotation)

Aggregations

Connector (javax.resource.spi.Connector)2 ConfigPropertyHandler (com.sun.enterprise.connectors.deployment.annotation.handlers.ConfigPropertyHandler)1 ConnectorDescriptor (com.sun.enterprise.deployment.ConnectorDescriptor)1 RarBundleContext (com.sun.enterprise.deployment.annotation.context.RarBundleContext)1 Annotation (java.lang.annotation.Annotation)1 ArrayList (java.util.ArrayList)1 Set (java.util.Set)1 AnnotationInfo (org.glassfish.apf.AnnotationInfo)1 AnnotationProcessorException (org.glassfish.apf.AnnotationProcessorException)1