Search in sources :

Example 16 with ImmediateValue

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());
        }
    }
}
Also used : JBossServiceDependencyConfig(org.jboss.as.service.descriptor.JBossServiceDependencyConfig) ObjectName(javax.management.ObjectName) ImmediateValue(org.jboss.msc.value.ImmediateValue)

Example 17 with ImmediateValue

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));
}
Also used : ValueFactoryParameter(org.jboss.as.service.descriptor.JBossServiceAttributeConfig.ValueFactoryParameter) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) Value(org.jboss.msc.value.Value) ImmediateValue(org.jboss.msc.value.ImmediateValue) MethodValue(org.jboss.msc.value.MethodValue)

Example 18 with ImmediateValue

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()));
}
Also used : Method(java.lang.reflect.Method) ImmediateValue(org.jboss.msc.value.ImmediateValue)

Example 19 with ImmediateValue

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();
}
Also used : Constructor(java.lang.reflect.Constructor) ConstructorConfig(org.jboss.as.pojo.descriptor.ConstructorConfig) FactoryConfig(org.jboss.as.pojo.descriptor.FactoryConfig) Method(java.lang.reflect.Method) ImmediateValue(org.jboss.msc.value.ImmediateValue) ValueConfig(org.jboss.as.pojo.descriptor.ValueConfig) StartException(org.jboss.msc.service.StartException)

Example 20 with ImmediateValue

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();
}
Also used : InMemorySingleSignOnManager(io.undertow.security.impl.InMemorySingleSignOnManager) ServiceName(org.jboss.msc.service.ServiceName) PathAddress(org.jboss.as.controller.PathAddress) ServiceTarget(org.jboss.msc.service.ServiceTarget) DistributableHostSingleSignOnManagerBuilder(org.wildfly.extension.undertow.security.sso.DistributableHostSingleSignOnManagerBuilder) ImmediateValue(org.jboss.msc.value.ImmediateValue)

Aggregations

ImmediateValue (org.jboss.msc.value.ImmediateValue)20 BinderService (org.jboss.as.naming.service.BinderService)6 ServiceName (org.jboss.msc.service.ServiceName)6 ValueManagedReferenceFactory (org.jboss.as.naming.ValueManagedReferenceFactory)5 Method (java.lang.reflect.Method)3 ContextNames (org.jboss.as.naming.deployment.ContextNames)3 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)3 ServiceTarget (org.jboss.msc.service.ServiceTarget)3 ArrayList (java.util.ArrayList)2 ObjectName (javax.management.ObjectName)2 ClassLoaderThreadFactory (org.jboss.as.clustering.jgroups.ClassLoaderThreadFactory)2 CapabilityServiceSupport (org.jboss.as.controller.capability.CapabilityServiceSupport)2 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)2 PersistenceUnitServiceImpl (org.jboss.as.jpa.service.PersistenceUnitServiceImpl)2 PhaseOnePersistenceUnitServiceImpl (org.jboss.as.jpa.service.PhaseOnePersistenceUnitServiceImpl)2 ManagedReferenceFactory (org.jboss.as.naming.ManagedReferenceFactory)2 ServiceBasedNamingStore (org.jboss.as.naming.ServiceBasedNamingStore)2 JBossServiceDependencyConfig (org.jboss.as.service.descriptor.JBossServiceDependencyConfig)2 Module (org.jboss.modules.Module)2 CastingInjector (org.jboss.msc.inject.CastingInjector)2