Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source.
   * Copyright 2013, Red Hat, Inc., and individual contributors
   * as indicated by the @author tags. See the copyright.txt file in the
   * distribution for a full listing of individual contributors.
   *
   * This is free software; you can redistribute it and/or modify it
   * under the terms of the GNU Lesser General Public License as
   * published by the Free Software Foundation; either version 2.1 of
  * the License, or (at your option) any later version.
  *
  * This software is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 
 package org.jboss.as.connector.deployers.ra;
 
 import static org.jboss.as.ee.EeMessages.MESSAGES;
 
 import java.util.List;
 
 
Deployment processor responsible for processing javax.resource.AdministeredObjectDefinition and javax.resource.AdministeredObjectDefinitions and creating org.jboss.as.ee.component.BindingConfigurations out of them

Author(s):
Jesper Pedersen
 
 
     private static final DotName ADMINISTERED_OBJECT_DEFINITION = DotName.createSimple(AdministeredObjectDefinition.class.getName());
     private static final DotName ADMINISTERED_OBJECT_DEFINITIONS = DotName.createSimple(AdministeredObjectDefinitions.class.getName());
 
 
 
     @Override
     public void deploy(DeploymentPhaseContext phaseContextthrows DeploymentUnitProcessingException {
         final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
         final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(.);
         final EEApplicationClasses applicationClasses = deploymentUnit.getAttachment(.);
 
         // @AdministeredObjectDefinitions
         List<AnnotationInstanceadminObjectDefinitions = index.getAnnotations();
         if (adminObjectDefinitions != null) {
             for (AnnotationInstance annotation : adminObjectDefinitions) {
                 final AnnotationTarget target = annotation.target();
                 if (target instanceof ClassInfo == false) {
                     throw .classOnlyAnnotation("@AdministeredObjectDefinitions"target);
                 }
                 // get the nested @AdministeredObjectDefinition out of the outer @AdministeredObjectDefinitions
                 List<AnnotationInstanceadminObjects = this.getNestedAdministeredObjectAnnotations(annotation);
                 // process the nested @AdministeredObjectDefinition
                 for (AnnotationInstance adminObject : adminObjects) {
                     // create binding configurations out of it
                     this.processAdministeredObjectDefinition(eeModuleDescriptionadminObject, (ClassInfotargetapplicationClasses);
                 }
             }
         }
 
         // @AdministeredObjectDefinition
         List<AnnotationInstanceadminObjects = index.getAnnotations();
         if (adminObjects != null) {
             for (AnnotationInstance adminObject : adminObjects) {
                 final AnnotationTarget target = adminObject.target();
                 if (target instanceof ClassInfo == false) {
                     throw .classOnlyAnnotation("@AdministeredObjectDefinition"target);
                 }
                 // create binding configurations out of it
                 this.processAdministeredObjectDefinition(eeModuleDescriptionadminObject, (ClassInfotargetapplicationClasses);
             }
         }
    }
    @Override
    public void undeploy(DeploymentUnit context) {
    }
    private void processAdministeredObjectDefinition(final EEModuleDescription eeModuleDescriptionfinal AnnotationInstance adminObjectDefinitionfinal ClassInfo targetClassfinal EEApplicationClasses applicationClassesthrows DeploymentUnitProcessingException {
        // create BindingConfiguration out of the @AdministeredObjectDefinition annotation
        final BindingConfiguration bindingConfiguration = this.getBindingConfiguration(adminObjectDefinition);
        EEModuleClassDescription classDescription = eeModuleDescription.addOrGetLocalClassDescription(targetClass.name().toString());
        // add the binding configuration via a class configurator
        classDescription.getBindingConfigurations().add(bindingConfiguration);
    }
    private BindingConfiguration getBindingConfiguration(final AnnotationInstance adminObjectAnnotation) {
        String name = asString(adminObjectAnnotation"name");
        if (name == null || name.isEmpty()) {
            throw .annotationAttributeMissing("@AdministeredObjectDefinition""name");
        }
        // If the name doesn't have a namespace then it defaults to java:comp/env
        if (!name.startsWith("java:")) {
            name = "java:comp/env/" + name;
        }
        String clz = asString(adminObjectAnnotation"className");
        if (clz == null || clz.equals(Object.class.getName())) {
            throw .annotationAttributeMissing("@AdministeredObjectDefinition""className");
        }
        String ra = asString(adminObjectAnnotation"resourceAdapter");
        if (ra == null || ra.equals(Object.class.getName())) {
            throw .annotationAttributeMissing("@AdministeredObjectDefinition""resourceAdapter");
        }
        final DirectAdministeredObjectInjectionSource directAdministeredObjectInjectionSource =
            new DirectAdministeredObjectInjectionSource(nameclzra);
        directAdministeredObjectInjectionSource.setDescription(asString(adminObjectAnnotation,
                                                                        .));
        directAdministeredObjectInjectionSource.setInterface(asString(adminObjectAnnotation,
                                                                      .));
        directAdministeredObjectInjectionSource.setProperties(asArray(adminObjectAnnotation,
                                                                      .));
        final BindingConfiguration bindingDescription = new BindingConfiguration(namedirectAdministeredObjectInjectionSource);
        return bindingDescription;
    }
    private String asString(final AnnotationInstance annotationString property) {
        AnnotationValue value = annotation.value(property);
        return value == null ? null : value.asString();
    }
    private String[] asArray(final AnnotationInstance annotationString property) {
        AnnotationValue value = annotation.value(property);
        return value == null ? null : value.asStringArray();
    }

    
Returns the nested javax.resource.AdministeredObjectDefinition annotations out of the outer javax.resource.AdministeredObjectDefinitions annotation

Parameters:
adminObjectDefinitions The outer javax.resource.AdministeredObjectDefinitions annotation
Returns:
        if (adminObjectDefinitions == null) {
            return Collections.emptyList();
        }
        AnnotationInstance[] nested = adminObjectDefinitions.value().asNestedArray();
        return Arrays.asList(nested);
    }
New to GrepCode? Check out our FAQ X