use of org.jboss.msc.value.ImmediateValue in project wildfly by wildfly.
the class ParsedServiceDeploymentProcessor method addDependencies.
private void addDependencies(final JBossServiceDependencyConfig[] dependencyConfigs, final List<ClassReflectionIndex> mBeanClassHierarchy, final MBeanServices mBeanServices) throws DeploymentUnitProcessingException {
if (dependencyConfigs != null) {
final Service<Object> createDestroyService = mBeanServices.getCreateDestroyService();
for (final JBossServiceDependencyConfig dependencyConfig : dependencyConfigs) {
final String optionalAttributeName = dependencyConfig.getOptionalAttributeName();
if (optionalAttributeName != null) {
final Injector<Object> injector = getOptionalAttributeInjector(optionalAttributeName, mBeanClassHierarchy, createDestroyService);
final ObjectName dependencyObjectName = createDependencyObjectName(dependencyConfig.getDependencyName());
final ImmediateValue<ObjectName> dependencyNameValue = new ImmediateValue<ObjectName>(dependencyObjectName);
mBeanServices.addInjectionValue(injector, dependencyNameValue);
}
mBeanServices.addDependency(dependencyConfig.getDependencyName());
}
}
}
use of org.jboss.msc.value.ImmediateValue in project wildfly by wildfly.
the class ParsedServiceDeploymentProcessor method getValue.
private static Value<?> getValue(final ValueFactory valueFactory, final ClassLoader classLoader) throws DeploymentUnitProcessingException {
final String methodName = valueFactory.getMethodName();
final ValueFactoryParameter[] parameters = valueFactory.getParameters();
final List<Class<?>> paramTypes = new ArrayList<Class<?>>(parameters.length);
final List<Value<?>> paramValues = new ArrayList<Value<?>>(parameters.length);
for (ValueFactoryParameter parameter : parameters) {
final Class<?> attributeTypeValue = ReflectionUtils.getClass(parameter.getType(), classLoader);
paramTypes.add(attributeTypeValue);
paramValues.add(new ImmediateValue<Object>(newValue(attributeTypeValue, parameter.getValue())));
}
final Value<Method> methodValue = new InjectedBeanMethodValue(Values.injectedValue(), new InjectedBeanMethodValue.MethodFinder() {
@Override
public Method find(Class<?> clazz) {
return ReflectionUtils.getMethod(clazz, methodName, paramTypes.toArray(new Class<?>[0]));
}
});
return cached(new MethodValue<Object>(methodValue, Values.injectedValue(), paramValues));
}
use of org.jboss.msc.value.ImmediateValue in project wildfly by wildfly.
the class ParsedServiceDeploymentProcessor method getValue.
private static Value<?> getValue(final JBossServiceAttributeConfig attributeConfig, final List<ClassReflectionIndex> mBeanClassHierarchy) {
final String attributeName = attributeConfig.getName();
final Method setterMethod = ReflectionUtils.getSetter(mBeanClassHierarchy, attributeName);
final Class<?> setterType = setterMethod.getParameterTypes()[0];
return new ImmediateValue<Object>(newValue(setterType, attributeConfig.getValue()));
}
use of org.jboss.msc.value.ImmediateValue in project wildfly by wildfly.
the class BeanUtils method instantiateBean.
/**
* Instantiate bean.
*
* @param beanConfig the bean metadata config, must not be null
* @param beanInfo the bean info, can be null if enough info
* @param index the reflection index, must not be null
* @param module the current CL module, must not be null
* @return new bean instance
* @throws Throwable for any error
*/
public static Object instantiateBean(BeanMetaDataConfig beanConfig, BeanInfo beanInfo, DeploymentReflectionIndex index, Module module) throws Throwable {
Joinpoint instantiateJoinpoint = null;
ValueConfig[] parameters = new ValueConfig[0];
String[] types = Configurator.NO_PARAMS_TYPES;
ConstructorConfig ctorConfig = beanConfig.getConstructor();
if (ctorConfig != null) {
parameters = ctorConfig.getParameters();
types = Configurator.getTypes(parameters);
String factoryClass = ctorConfig.getFactoryClass();
FactoryConfig factory = ctorConfig.getFactory();
if (factoryClass != null || factory != null) {
String factoryMethod = ctorConfig.getFactoryMethod();
if (factoryMethod == null)
throw PojoLogger.ROOT_LOGGER.missingFactoryMethod(beanConfig);
if (factoryClass != null) {
// static factory
Class<?> factoryClazz = Class.forName(factoryClass, false, module.getClassLoader());
Method method = Configurator.findMethod(index, factoryClazz, factoryMethod, types, true, true, true);
MethodJoinpoint mj = new MethodJoinpoint(method);
// null, since this is static call
mj.setTarget(new ImmediateValue<Object>(null));
mj.setParameters(parameters);
instantiateJoinpoint = mj;
} else if (factory != null) {
ReflectionJoinpoint rj = new ReflectionJoinpoint(factory.getBeanInfo(), factoryMethod, types);
// null type is ok, as this should be plain injection
rj.setTarget(new ImmediateValue<Object>(factory.getValue(null)));
rj.setParameters(parameters);
instantiateJoinpoint = rj;
}
}
}
// plain bean's ctor
if (instantiateJoinpoint == null) {
if (beanInfo == null)
throw new StartException(PojoLogger.ROOT_LOGGER.missingBeanInfo(beanConfig));
Constructor ctor = (types.length == 0) ? beanInfo.getConstructor() : beanInfo.findConstructor(types);
ConstructorJoinpoint constructorJoinpoint = new ConstructorJoinpoint(ctor);
constructorJoinpoint.setParameters(parameters);
instantiateJoinpoint = constructorJoinpoint;
}
return instantiateJoinpoint.dispatch();
}
use of org.jboss.msc.value.ImmediateValue in project wildfly by wildfly.
the class HostSingleSignOnServiceHandler method installServices.
@Override
public void installServices(OperationContext context, ModelNode model) throws OperationFailedException {
PathAddress address = context.getCurrentAddress();
PathAddress hostAddress = address.getParent();
PathAddress serverAddress = hostAddress.getParent();
String hostName = hostAddress.getLastElement().getValue();
String serverName = serverAddress.getLastElement().getValue();
String domain = ModelNodes.optionalString(DOMAIN.resolveModelAttribute(context, model)).orElse(null);
String path = PATH.resolveModelAttribute(context, model).asString();
boolean secure = SECURE.resolveModelAttribute(context, model).asBoolean();
boolean httpOnly = HTTP_ONLY.resolveModelAttribute(context, model).asBoolean();
String cookieName = COOKIE_NAME.resolveModelAttribute(context, model).asString();
ServiceName serviceName = UndertowService.ssoServiceName(serverName, hostName);
ServiceName virtualHostServiceName = UndertowService.virtualHostName(serverName, hostName);
ServiceTarget target = context.getServiceTarget();
ServiceName managerServiceName = serviceName.append("manager");
if (DistributableHostSingleSignOnManagerBuilder.INSTANCE.isPresent()) {
DistributableHostSingleSignOnManagerBuilder builder = DistributableHostSingleSignOnManagerBuilder.INSTANCE.get();
builder.build(target, managerServiceName, context.getCapabilityServiceSupport(), serverName, hostName).setInitialMode(ServiceController.Mode.ON_DEMAND).install();
} else {
target.addService(managerServiceName, new ValueService<>(new ImmediateValue<>(new InMemorySingleSignOnManager()))).setInitialMode(ServiceController.Mode.ON_DEMAND).install();
}
SingleSignOnService service = new SingleSignOnService(domain, path, httpOnly, secure, cookieName);
target.addService(serviceName, service).addDependency(virtualHostServiceName, Host.class, service.getHost()).addDependency(managerServiceName, SingleSignOnManager.class, service.getSingleSignOnSessionManager()).setInitialMode(ServiceController.Mode.ACTIVE).install();
}
Aggregations