private String uniqueName(ResolutionContext context, final String jndiName) {
   StringBuilder name = new StringBuilder();
   name.append(context.getApplicationName() + "_");
   name.append(context.getModuleName() + "_");
   if (context.getComponentName() != null) {
     name.append(context.getComponentName() + "_");
   }
   name.append(jndiName);
   return name.toString();
 }
  public void getResourceValue(
      final ResolutionContext context,
      final ServiceBuilder<?> serviceBuilder,
      final DeploymentPhaseContext phaseContext,
      final Injector<ManagedReferenceFactory> injector)
      throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final Module module =
        deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
    final EEModuleDescription eeModuleDescription =
        deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
    final String poolName = uniqueName(context, jndiName);
    final ContextNames.BindInfo bindInfo =
        ContextNames.bindInfoForEnvEntry(
            context.getApplicationName(),
            context.getModuleName(),
            context.getComponentName(),
            !context.isCompUsesModule(),
            jndiName);
    final DeploymentReflectionIndex reflectionIndex =
        deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.REFLECTION_INDEX);
    final boolean securityEnabled =
        phaseContext.getDeploymentUnit().hasAttachment(SecurityAttachments.SECURITY_ENABLED);
    try {
      final Class<?> clazz = module.getClassLoader().loadClass(className);

      clearUnknownProperties(reflectionIndex, clazz, properties);
      populateProperties(reflectionIndex, clazz, properties);
      DsSecurityImpl dsSecurity = new DsSecurityImpl(user, password, null, null);

      if (XADataSource.class.isAssignableFrom(clazz) && transactional) {
        final DsXaPoolImpl xaPool =
            new DsXaPoolImpl(
                minPoolSize < 0 ? Defaults.MIN_POOL_SIZE : Integer.valueOf(minPoolSize),
                initialPoolSize < 0 ? Defaults.INITIAL_POOL_SIZE : Integer.valueOf(initialPoolSize),
                maxPoolSize < 1 ? Defaults.MAX_POOL_SIZE : Integer.valueOf(maxPoolSize),
                Defaults.PREFILL,
                Defaults.USE_STRICT_MIN,
                Defaults.FLUSH_STRATEGY,
                Defaults.IS_SAME_RM_OVERRIDE,
                Defaults.INTERLEAVING,
                Defaults.PAD_XID,
                Defaults.WRAP_XA_RESOURCE,
                Defaults.NO_TX_SEPARATE_POOL,
                Boolean.FALSE,
                null,
                Defaults.FAIR,
                null);
        final ModifiableXaDataSource dataSource =
            new ModifiableXaDataSource(
                transactionIsolation(),
                null,
                dsSecurity,
                null,
                null,
                null,
                null,
                null,
                null,
                poolName,
                true,
                jndiName,
                false,
                false,
                Defaults.CONNECTABLE,
                Defaults.TRACKING,
                Defaults.MCP,
                Defaults.ENLISTMENT_TRACE,
                properties,
                className,
                null,
                null,
                xaPool,
                null);
        final XaDataSourceService xds =
            new XaDataSourceService(
                bindInfo.getBinderServiceName().getCanonicalName(),
                bindInfo,
                module.getClassLoader());
        xds.getDataSourceConfigInjector().inject(dataSource);
        startDataSource(
            xds,
            bindInfo,
            eeModuleDescription,
            context,
            phaseContext.getServiceTarget(),
            serviceBuilder,
            injector,
            securityEnabled);
      } else {
        final DsPoolImpl commonPool =
            new DsPoolImpl(
                minPoolSize < 0 ? Defaults.MIN_POOL_SIZE : Integer.valueOf(minPoolSize),
                initialPoolSize < 0 ? Defaults.INITIAL_POOL_SIZE : Integer.valueOf(initialPoolSize),
                maxPoolSize < 1 ? Defaults.MAX_POOL_SIZE : Integer.valueOf(maxPoolSize),
                Defaults.PREFILL,
                Defaults.USE_STRICT_MIN,
                Defaults.FLUSH_STRATEGY,
                Boolean.FALSE,
                null,
                Defaults.FAIR,
                null);
        final ModifiableDataSource dataSource =
            new ModifiableDataSource(
                url,
                null,
                className,
                null,
                transactionIsolation(),
                properties,
                null,
                dsSecurity,
                null,
                null,
                null,
                null,
                null,
                false,
                poolName,
                true,
                jndiName,
                Defaults.SPY,
                Defaults.USE_CCM,
                transactional,
                Defaults.CONNECTABLE,
                Defaults.TRACKING,
                Defaults.MCP,
                Defaults.ENLISTMENT_TRACE,
                commonPool);
        final LocalDataSourceService ds =
            new LocalDataSourceService(
                bindInfo.getBinderServiceName().getCanonicalName(),
                bindInfo,
                module.getClassLoader());
        ds.getDataSourceConfigInjector().inject(dataSource);
        startDataSource(
            ds,
            bindInfo,
            eeModuleDescription,
            context,
            phaseContext.getServiceTarget(),
            serviceBuilder,
            injector,
            securityEnabled);
      }

    } catch (Exception e) {
      throw new DeploymentUnitProcessingException(e);
    }
  }
  private void startDataSource(
      final AbstractDataSourceService dataSourceService,
      final String jndiName,
      final EEModuleDescription moduleDescription,
      final ResolutionContext context,
      final ServiceTarget serviceTarget,
      final ServiceBuilder valueSourceServiceBuilder,
      final Injector<ManagedReferenceFactory> injector) {

    final ServiceName dataSourceServiceName =
        AbstractDataSourceService.SERVICE_NAME_BASE.append(
            "DataSourceDefinition",
            moduleDescription.getApplicationName(),
            moduleDescription.getModuleName(),
            jndiName);
    final ServiceBuilder<?> dataSourceServiceBuilder =
        Services.addServerExecutorDependency(
                serviceTarget.addService(dataSourceServiceName, dataSourceService),
                dataSourceService.getExecutorServiceInjector(),
                false)
            .addDependency(
                ConnectorServices.IRONJACAMAR_MDR,
                MetadataRepository.class,
                dataSourceService.getMdrInjector())
            .addDependency(
                ConnectorServices.RA_REPOSITORY_SERVICE,
                ResourceAdapterRepository.class,
                dataSourceService.getRaRepositoryInjector())
            .addDependency(ConnectorServices.BOOTSTRAP_CONTEXT_SERVICE.append(DEFAULT_NAME))
            .addDependency(
                ConnectorServices.TRANSACTION_INTEGRATION_SERVICE,
                TransactionIntegration.class,
                dataSourceService.getTransactionIntegrationInjector())
            .addDependency(
                ConnectorServices.MANAGEMENT_REPOSITORY_SERVICE,
                ManagementRepository.class,
                dataSourceService.getManagementRepositoryInjector())
            .addDependency(
                SubjectFactoryService.SERVICE_NAME,
                SubjectFactory.class,
                dataSourceService.getSubjectFactoryInjector())
            .addDependency(
                ConnectorServices.CCM_SERVICE,
                CachedConnectionManager.class,
                dataSourceService.getCcmInjector())
            .addDependency(
                ConnectorServices.JDBC_DRIVER_REGISTRY_SERVICE,
                DriverRegistry.class,
                dataSourceService.getDriverRegistryInjector())
            .addDependency(NamingService.SERVICE_NAME);
    final ContextNames.BindInfo bindInfo =
        ContextNames.bindInfoForEnvEntry(
            context.getApplicationName(),
            context.getModuleName(),
            context.getComponentName(),
            !context.isCompUsesModule(),
            jndiName);

    final DataSourceReferenceFactoryService referenceFactoryService =
        new DataSourceReferenceFactoryService();
    final ServiceName referenceFactoryServiceName =
        DataSourceReferenceFactoryService.SERVICE_NAME_BASE.append(bindInfo.getBinderServiceName());
    final ServiceBuilder<?> referenceBuilder =
        serviceTarget
            .addService(referenceFactoryServiceName, referenceFactoryService)
            .addDependency(
                dataSourceServiceName,
                javax.sql.DataSource.class,
                referenceFactoryService.getDataSourceInjector());

    final BinderService binderService = new BinderService(bindInfo.getBindName(), this);
    final ServiceBuilder<?> binderBuilder =
        serviceTarget
            .addService(bindInfo.getBinderServiceName(), binderService)
            .addDependency(
                referenceFactoryServiceName,
                ManagedReferenceFactory.class,
                binderService.getManagedObjectInjector())
            .addDependency(
                bindInfo.getParentContextServiceName(),
                ServiceBasedNamingStore.class,
                binderService.getNamingStoreInjector())
            .addListener(
                new AbstractServiceListener<Object>() {
                  public void transition(
                      final ServiceController<? extends Object> controller,
                      final ServiceController.Transition transition) {
                    switch (transition) {
                      case STARTING_to_UP:
                        {
                          SUBSYSTEM_DATASOURCES_LOGGER.boundDataSource(jndiName);
                          break;
                        }
                      case START_REQUESTED_to_DOWN:
                        {
                          SUBSYSTEM_DATASOURCES_LOGGER.unboundDataSource(jndiName);
                          break;
                        }
                      case REMOVING_to_REMOVED:
                        {
                          SUBSYSTEM_DATASOURCES_LOGGER.debugf(
                              "Removed JDBC Data-source [%s]", jndiName);
                          break;
                        }
                    }
                  }
                });

    dataSourceServiceBuilder.setInitialMode(ServiceController.Mode.ACTIVE).install();
    referenceBuilder.setInitialMode(ServiceController.Mode.ACTIVE).install();
    binderBuilder.setInitialMode(ServiceController.Mode.ACTIVE).install();

    valueSourceServiceBuilder.addDependency(
        bindInfo.getBinderServiceName(), ManagedReferenceFactory.class, injector);
  }