Search in sources :

Example 6 with ValueManagedReferenceFactory

use of org.jboss.as.naming.ValueManagedReferenceFactory in project wildfly by wildfly.

the class BeanValidationFactoryDeployer method bindServices.

/**
     *
     * @param factory The ValidatorFactory to bind
     * @param serviceTarget The service target
     * @param contextServiceName The service name of the context to bind to
     */
private void bindServices(LazyValidatorFactory factory, ServiceTarget serviceTarget, EEModuleDescription description, String componentName, ServiceName contextServiceName) {
    BinderService validatorFactoryBindingService = new BinderService("ValidatorFactory");
    validatorFactoryBindingService.getManagedObjectInjector().inject(new ValueManagedReferenceFactory(new ImmediateValue<Object>(factory)));
    serviceTarget.addService(contextServiceName.append("ValidatorFactory"), validatorFactoryBindingService).addDependency(contextServiceName, ServiceBasedNamingStore.class, validatorFactoryBindingService.getNamingStoreInjector()).install();
    BinderService validatorBindingService = new BinderService("Validator");
    validatorBindingService.getManagedObjectInjector().inject(new ValidatorJndiInjectable(factory));
    serviceTarget.addService(contextServiceName.append("Validator"), validatorBindingService).addDependency(contextServiceName, ServiceBasedNamingStore.class, validatorBindingService.getNamingStoreInjector()).install();
}
Also used : BinderService(org.jboss.as.naming.service.BinderService) ValueManagedReferenceFactory(org.jboss.as.naming.ValueManagedReferenceFactory) ServiceBasedNamingStore(org.jboss.as.naming.ServiceBasedNamingStore) ImmediateValue(org.jboss.msc.value.ImmediateValue)

Example 7 with ValueManagedReferenceFactory

use of org.jboss.as.naming.ValueManagedReferenceFactory in project wildfly by wildfly.

the class CorbaServiceUtil method bindObject.

/**
     * <p>
     * Adds a {@code BinderService} to the specified target. The service binds the specified value to JNDI under the
     * {@code java:/jboss/contextName} context.
     * </p>
     *
     * @param target      the {@code ServiceTarget} where the service will be added.
     * @param contextName the JNDI context name where the value will be bound.
     * @param value       the value to be bound.
     */
public static void bindObject(final ServiceTarget target, final String contextName, final Object value) {
    final BinderService binderService = new BinderService(contextName);
    target.addService(ContextNames.buildServiceName(ContextNames.JBOSS_CONTEXT_SERVICE_NAME, contextName), binderService).addDependency(ContextNames.JBOSS_CONTEXT_SERVICE_NAME, ServiceBasedNamingStore.class, binderService.getNamingStoreInjector()).addInjection(binderService.getManagedObjectInjector(), new ValueManagedReferenceFactory(Values.immediateValue(value))).setInitialMode(ServiceController.Mode.ACTIVE).install();
}
Also used : BinderService(org.jboss.as.naming.service.BinderService) ServiceBasedNamingStore(org.jboss.as.naming.ServiceBasedNamingStore) ValueManagedReferenceFactory(org.jboss.as.naming.ValueManagedReferenceFactory)

Example 8 with ValueManagedReferenceFactory

use of org.jboss.as.naming.ValueManagedReferenceFactory in project wildfly by wildfly.

the class NamingBindingAdd method doRebind.

void doRebind(OperationContext context, ModelNode model, BinderService service) throws OperationFailedException {
    ManagedReferenceFactory ref = service.getManagedObjectInjector().getValue();
    if (ref instanceof MutableManagedReferenceFactory) {
        MutableManagedReferenceFactory factory = (MutableManagedReferenceFactory) ref;
        final BindingType type = BindingType.forName(NamingBindingResourceDefinition.BINDING_TYPE.resolveModelAttribute(context, model).asString());
        if (type == BindingType.SIMPLE) {
            Object bindValue = createSimpleBinding(context, model);
            factory.setFactory(new ValueManagedReferenceFactory(new ImmediateValue<Object>(bindValue)));
            service.setSource(bindValue);
        } else if (type == BindingType.OBJECT_FACTORY) {
            final ObjectFactory objectFactoryClassInstance = createObjectFactory(context, model);
            final Hashtable<String, String> environment = getObjectFactoryEnvironment(context, model);
            factory.setFactory(new ObjectFactoryManagedReference(objectFactoryClassInstance, service.getName(), environment));
            service.setSource(objectFactoryClassInstance);
        } else if (type == BindingType.LOOKUP) {
            final String lookup = NamingBindingResourceDefinition.LOOKUP.resolveModelAttribute(context, model).asString();
            factory.setFactory(new LookupManagedReferenceFactory(lookup));
            service.setSource(null);
        } else if (type == BindingType.EXTERNAL_CONTEXT) {
            throw NamingLogger.ROOT_LOGGER.cannotRebindExternalContext();
        } else {
            throw NamingLogger.ROOT_LOGGER.unknownBindingType(type.toString());
        }
    } else {
        throw NamingLogger.ROOT_LOGGER.cannotRebindExternalContext();
    }
}
Also used : ObjectFactory(javax.naming.spi.ObjectFactory) ExternalContextObjectFactory(org.jboss.as.naming.ExternalContextObjectFactory) ValueManagedReferenceFactory(org.jboss.as.naming.ValueManagedReferenceFactory) ContextListAndJndiViewManagedReferenceFactory(org.jboss.as.naming.ContextListAndJndiViewManagedReferenceFactory) ContextListManagedReferenceFactory(org.jboss.as.naming.ContextListManagedReferenceFactory) ManagedReferenceFactory(org.jboss.as.naming.ManagedReferenceFactory) ValueManagedReferenceFactory(org.jboss.as.naming.ValueManagedReferenceFactory) Hashtable(java.util.Hashtable) ImmediateValue(org.jboss.msc.value.ImmediateValue)

Example 9 with ValueManagedReferenceFactory

use of org.jboss.as.naming.ValueManagedReferenceFactory in project wildfly by wildfly.

the class PersistenceUnitServiceHandler method entityManagerBind.

private static void entityManagerBind(EEModuleDescription eeModuleDescription, ServiceTarget serviceTarget, final PersistenceUnitMetadata pu, ServiceName puServiceName, TransactionManager transactionManager, TransactionSynchronizationRegistry transactionSynchronizationRegistry) {
    if (pu.getProperties().containsKey(ENTITYMANAGER_JNDI_PROPERTY)) {
        String jndiName = pu.getProperties().get(ENTITYMANAGER_JNDI_PROPERTY).toString();
        final ContextNames.BindInfo bindingInfo;
        if (jndiName.startsWith("java:")) {
            bindingInfo = ContextNames.bindInfoForEnvEntry(eeModuleDescription.getApplicationName(), eeModuleDescription.getModuleName(), eeModuleDescription.getModuleName(), false, jndiName);
        } else {
            bindingInfo = ContextNames.bindInfoFor(jndiName);
        }
        ROOT_LOGGER.tracef("binding the transaction scoped entity manager to jndi name '%s'", bindingInfo.getAbsoluteJndiName());
        final BinderService binderService = new BinderService(bindingInfo.getBindName());
        serviceTarget.addService(bindingInfo.getBinderServiceName(), binderService).addDependency(bindingInfo.getParentContextServiceName(), ServiceBasedNamingStore.class, binderService.getNamingStoreInjector()).addDependency(puServiceName, PersistenceUnitServiceImpl.class, new Injector<PersistenceUnitServiceImpl>() {

            @Override
            public void inject(final PersistenceUnitServiceImpl value) throws InjectionException {
                binderService.getManagedObjectInjector().inject(new ValueManagedReferenceFactory(new ImmediateValue<Object>(new TransactionScopedEntityManager(pu.getScopedPersistenceUnitName(), Collections.emptyMap(), value.getEntityManagerFactory(), SynchronizationType.SYNCHRONIZED, transactionSynchronizationRegistry, transactionManager))));
            }

            @Override
            public void uninject() {
                binderService.getNamingStoreInjector().uninject();
            }
        }).install();
    }
}
Also used : BinderService(org.jboss.as.naming.service.BinderService) PhaseOnePersistenceUnitServiceImpl(org.jboss.as.jpa.service.PhaseOnePersistenceUnitServiceImpl) PersistenceUnitServiceImpl(org.jboss.as.jpa.service.PersistenceUnitServiceImpl) TransactionScopedEntityManager(org.jboss.as.jpa.container.TransactionScopedEntityManager) ValueManagedReferenceFactory(org.jboss.as.naming.ValueManagedReferenceFactory) CastingInjector(org.jboss.msc.inject.CastingInjector) Injector(org.jboss.msc.inject.Injector) ContextNames(org.jboss.as.naming.deployment.ContextNames) ImmediateValue(org.jboss.msc.value.ImmediateValue)

Example 10 with ValueManagedReferenceFactory

use of org.jboss.as.naming.ValueManagedReferenceFactory in project wildfly by wildfly.

the class PersistenceUnitServiceHandler method entityManagerFactoryBind.

private static void entityManagerFactoryBind(EEModuleDescription eeModuleDescription, ServiceTarget serviceTarget, PersistenceUnitMetadata pu, ServiceName puServiceName) {
    if (pu.getProperties().containsKey(ENTITYMANAGERFACTORY_JNDI_PROPERTY)) {
        String jndiName = pu.getProperties().get(ENTITYMANAGERFACTORY_JNDI_PROPERTY).toString();
        final ContextNames.BindInfo bindingInfo;
        if (jndiName.startsWith("java:")) {
            bindingInfo = ContextNames.bindInfoForEnvEntry(eeModuleDescription.getApplicationName(), eeModuleDescription.getModuleName(), eeModuleDescription.getModuleName(), false, jndiName);
        } else {
            bindingInfo = ContextNames.bindInfoFor(jndiName);
        }
        ROOT_LOGGER.tracef("binding the entity manager factory to jndi name '%s'", bindingInfo.getAbsoluteJndiName());
        final BinderService binderService = new BinderService(bindingInfo.getBindName());
        serviceTarget.addService(bindingInfo.getBinderServiceName(), binderService).addDependency(bindingInfo.getParentContextServiceName(), ServiceBasedNamingStore.class, binderService.getNamingStoreInjector()).addDependency(puServiceName, PersistenceUnitServiceImpl.class, new Injector<PersistenceUnitServiceImpl>() {

            @Override
            public void inject(final PersistenceUnitServiceImpl value) throws InjectionException {
                binderService.getManagedObjectInjector().inject(new ValueManagedReferenceFactory(new ImmediateValue<Object>(value.getEntityManagerFactory())));
            }

            @Override
            public void uninject() {
                binderService.getNamingStoreInjector().uninject();
            }
        }).install();
    }
}
Also used : BinderService(org.jboss.as.naming.service.BinderService) PhaseOnePersistenceUnitServiceImpl(org.jboss.as.jpa.service.PhaseOnePersistenceUnitServiceImpl) PersistenceUnitServiceImpl(org.jboss.as.jpa.service.PersistenceUnitServiceImpl) ValueManagedReferenceFactory(org.jboss.as.naming.ValueManagedReferenceFactory) CastingInjector(org.jboss.msc.inject.CastingInjector) Injector(org.jboss.msc.inject.Injector) ContextNames(org.jboss.as.naming.deployment.ContextNames) ImmediateValue(org.jboss.msc.value.ImmediateValue)

Aggregations

ValueManagedReferenceFactory (org.jboss.as.naming.ValueManagedReferenceFactory)15 BinderService (org.jboss.as.naming.service.BinderService)13 ServiceName (org.jboss.msc.service.ServiceName)7 ServiceBasedNamingStore (org.jboss.as.naming.ServiceBasedNamingStore)6 ImmediateValue (org.jboss.msc.value.ImmediateValue)5 ManagedReferenceFactory (org.jboss.as.naming.ManagedReferenceFactory)4 ContextNames (org.jboss.as.naming.deployment.ContextNames)3 BindInfo (org.jboss.as.naming.deployment.ContextNames.BindInfo)3 ServiceTarget (org.jboss.msc.service.ServiceTarget)3 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)2 PersistenceUnitServiceImpl (org.jboss.as.jpa.service.PersistenceUnitServiceImpl)2 PhaseOnePersistenceUnitServiceImpl (org.jboss.as.jpa.service.PhaseOnePersistenceUnitServiceImpl)2 ContextListAndJndiViewManagedReferenceFactory (org.jboss.as.naming.ContextListAndJndiViewManagedReferenceFactory)2 ContextListManagedReferenceFactory (org.jboss.as.naming.ContextListManagedReferenceFactory)2 NamingStoreService (org.jboss.as.naming.service.NamingStoreService)2 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)2 CastingInjector (org.jboss.msc.inject.CastingInjector)2 InjectionException (org.jboss.msc.inject.InjectionException)2 Injector (org.jboss.msc.inject.Injector)2 HashSet (java.util.HashSet)1