Search in sources :

Example 1 with ConfigPropertyHandler

use of com.sun.enterprise.connectors.deployment.annotation.handlers.ConfigPropertyHandler 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)

Aggregations

ConfigPropertyHandler (com.sun.enterprise.connectors.deployment.annotation.handlers.ConfigPropertyHandler)1 Set (java.util.Set)1 Connector (javax.resource.spi.Connector)1 AnnotationInfo (org.glassfish.apf.AnnotationInfo)1 AnnotationProcessorException (org.glassfish.apf.AnnotationProcessorException)1