예제 #1
0
  /**
   * Read module info from bytecode.
   *
   * @param moduleName the module name
   * @param jarFile the module jar file
   * @return module info list
   */
  private static ModuleInfo readModuleInformation(
      final String moduleName, final File jarFile, Overrides overrides) {
    Index index = readModuleIndex(jarFile, false);
    final AnnotationInstance ai = getAnnotation(index, moduleName, MODULE_ANNOTATION);
    if (ai == null) return null;
    final AnnotationValue version = ai.value("version");
    if (version == null) return null;

    final AnnotationValue dependencies = ai.value("dependencies");
    if (dependencies == null)
      return new ModuleInfo(null, Collections.<ModuleDependencyInfo>emptySet());

    final Set<ModuleDependencyInfo> infos = new LinkedHashSet<ModuleDependencyInfo>();

    final AnnotationInstance[] imports = dependencies.asNestedArray();
    if (imports != null) {
      for (AnnotationInstance im : imports) {
        final String name = asString(im, "name");
        final ModuleDependencyInfo mi =
            new ModuleDependencyInfo(
                name, asString(im, "version"), asBoolean(im, "optional"), asBoolean(im, "export"));
        infos.add(mi);
      }
    }
    ModuleInfo ret = new ModuleInfo(null, infos);
    if (overrides != null) ret = overrides.applyOverrides(moduleName, version.asString(), ret);
    return ret;
  }
 private Properties getActivationConfigProperties(
     final AnnotationInstance messageBeanAnnotation, boolean replacement) {
   final Properties props = new Properties();
   final AnnotationValue activationConfig = messageBeanAnnotation.value("activationConfig");
   if (activationConfig == null) return props;
   for (final AnnotationInstance propAnnotation : activationConfig.asNestedArray()) {
     String propertyName = propAnnotation.value("propertyName").asString();
     String propertyValue = propAnnotation.value("propertyValue").asString();
     if (replacement)
       props.put(propertyName, PropertiesValueResolver.replaceProperties(propertyValue));
     else props.put(propertyName, propertyValue);
   }
   return props;
 }
  /**
   * We need to check whether the is an explicit type specified via {@link
   * org.hibernate.annotations.Type}.
   *
   * @param type the type specified via the constructor
   * @param typeParameters map for type parameters in case there are any
   * @return the final type for this mapped attribute
   */
  private String determineType(String type, Map<String, String> typeParameters) {
    AnnotationInstance typeAnnotation = getIfExists(HibernateDotNames.TYPE);
    if (typeAnnotation == null) {
      // return discovered type
      return type;
    }

    AnnotationValue parameterAnnotationValue = typeAnnotation.value("parameters");
    if (parameterAnnotationValue != null) {
      AnnotationInstance[] parameterAnnotations = parameterAnnotationValue.asNestedArray();
      for (AnnotationInstance parameterAnnotationInstance : parameterAnnotations) {
        typeParameters.put(
            parameterAnnotationInstance.value("name").asString(),
            parameterAnnotationInstance.value("value").asString());
      }
    }

    return typeAnnotation.value("type").asString();
  }
  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(MESSAGES.cannotInjectResourceLocalEntityManager());
        return null;
      }
      AnnotationValue pcType = annotation.value("type");
      PersistenceContextType type =
          (pcType == null || PersistenceContextType.TRANSACTION.name().equals(pcType.asString()))
              ? PersistenceContextType.TRANSACTION
              : PersistenceContextType.EXTENDED;

      Map 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"), props[source].value("value"));
        }
      } else {
        properties = null;
      }

      return new PersistenceContextInjectionSource(
          type, properties, puServiceName, deploymentUnit, scopedPuName, injectionTypeName, pu);
    } else {
      return new PersistenceUnitInjectionSource(
          puServiceName, deploymentUnit, injectionTypeName, pu);
    }
  }
  public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();

    final EEModuleDescription moduleDescription =
        deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
    final CompositeIndex index =
        deploymentUnit.getAttachment(
            org.jboss.as.server.deployment.Attachments.COMPOSITE_ANNOTATION_INDEX);
    final List<AnnotationInstance> resourceAnnotations = index.getAnnotations(EJB_ANNOTATION_NAME);

    for (AnnotationInstance annotation : resourceAnnotations) {
      final AnnotationTarget annotationTarget = annotation.target();
      final EJBResourceWrapper annotationWrapper = new EJBResourceWrapper(annotation);
      if (annotationTarget instanceof FieldInfo) {
        processField(
            deploymentUnit, annotationWrapper, (FieldInfo) annotationTarget, moduleDescription);
      } else if (annotationTarget instanceof MethodInfo) {
        processMethod(
            deploymentUnit, annotationWrapper, (MethodInfo) annotationTarget, moduleDescription);
      } else if (annotationTarget instanceof ClassInfo) {
        processClass(
            deploymentUnit, annotationWrapper, (ClassInfo) annotationTarget, moduleDescription);
      }
    }
    final List<AnnotationInstance> ejbsAnnotations = index.getAnnotations(EJBS_ANNOTATION_NAME);
    for (AnnotationInstance annotation : ejbsAnnotations) {
      final AnnotationTarget annotationTarget = annotation.target();
      if (annotationTarget instanceof ClassInfo) {
        final AnnotationValue annotationValue = annotation.value();
        final AnnotationInstance[] ejbAnnotations = annotationValue.asNestedArray();
        for (AnnotationInstance ejbAnnotation : ejbAnnotations) {
          final EJBResourceWrapper annotationWrapper = new EJBResourceWrapper(ejbAnnotation);
          processClass(
              deploymentUnit, annotationWrapper, (ClassInfo) annotationTarget, moduleDescription);
        }
      } else {
        throw MESSAGES.annotationOnlyAllowedOnClass(EJBs.class.getName(), annotation.target());
      }
    }
  }
예제 #6
0
  private static Set<ModuleDependencyInfo> getDependencies(
      AnnotationValue dependencies, String module, String version, Overrides overrides) {
    AnnotationInstance[] deps = dependencies.asNestedArray();
    Set<ModuleDependencyInfo> result = new HashSet<ModuleDependencyInfo>(deps.length);
    for (AnnotationInstance dep : deps) {
      AnnotationValue depName = dep.value("name");
      AnnotationValue depVersion = dep.value("version");
      AnnotationValue export = dep.value("export");
      AnnotationValue optional = dep.value("optional");

      result.add(
          new ModuleDependencyInfo(
              depName.asString(),
              depVersion.asString(),
              (optional != null) && optional.asBoolean(),
              (export != null) && export.asBoolean()));
    }
    if (overrides != null)
      return overrides
          .applyOverrides(module, version, new ModuleInfo(null, result))
          .getDependencies();
    return result;
  }