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();
}
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();
}
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();
}
}
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();
}
}
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();
}
}
Aggregations