Search in sources :

Example 1 with ValueConfig

use of org.jboss.as.pojo.descriptor.ValueConfig in project wildfly by wildfly.

the class AbstractPojoPhase method createJoinpoint.

protected Joinpoint createJoinpoint(InstallConfig config) {
    String methodName = config.getMethodName();
    if (methodName == null)
        throw PojoLogger.ROOT_LOGGER.nullMethodName();
    ValueConfig[] parameters = config.getParameters();
    String[] types = Configurator.getTypes(parameters);
    String dependency = config.getDependency();
    Value<Object> target = (dependency != null) ? config.getBean() : new ImmediateValue<Object>(getBean());
    BeanInfo beanInfo = (dependency != null) ? config.getBeanInfo().getValue() : getBeanInfo();
    Method method = beanInfo.findMethod(methodName, types);
    MethodJoinpoint joinpoint = new MethodJoinpoint(method);
    joinpoint.setTarget(target);
    joinpoint.setParameters(parameters);
    return joinpoint;
}
Also used : ValueConfig(org.jboss.as.pojo.descriptor.ValueConfig) Method(java.lang.reflect.Method)

Example 2 with ValueConfig

use of org.jboss.as.pojo.descriptor.ValueConfig in project wildfly by wildfly.

the class BeanUtils method configure.

private static void configure(BeanInfo beanInfo, Module module, Object bean, PropertyConfig pc, boolean nullify) throws Throwable {
    ValueConfig value = pc.getValue();
    Class<?> clazz = null;
    // check property
    String type = pc.getType();
    if (type == null)
        // check value
        type = value.getType();
    if (type != null)
        clazz = module.getClassLoader().loadClass(type);
    Method setter = beanInfo.getSetter(pc.getPropertyName(), clazz);
    MethodJoinpoint joinpoint = new MethodJoinpoint(setter);
    ValueConfig param = (nullify == false) ? value : null;
    joinpoint.setParameters(new ValueConfig[] { param });
    joinpoint.setTarget(new ImmediateValue<Object>(bean));
    joinpoint.dispatch();
}
Also used : ValueConfig(org.jboss.as.pojo.descriptor.ValueConfig) Method(java.lang.reflect.Method)

Example 3 with ValueConfig

use of org.jboss.as.pojo.descriptor.ValueConfig 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 4 with ValueConfig

use of org.jboss.as.pojo.descriptor.ValueConfig in project wildfly by wildfly.

the class BeanUtils method createJoinpoint.

private static Joinpoint createJoinpoint(BeanInfo beanInfo, Object bean, LifecycleConfig config, String defaultMethod) {
    Method method;
    ValueConfig[] params = null;
    if (config == null) {
        try {
            method = beanInfo.getMethod(defaultMethod);
        } catch (Exception t) {
            PojoLogger.ROOT_LOGGER.tracef(t, "Ignoring default %s invocation.", defaultMethod);
            return null;
        }
    } else {
        String methodName = config.getMethodName();
        if (methodName == null) {
            methodName = defaultMethod;
        }
        ValueConfig[] parameters = config.getParameters();
        String[] types = Configurator.getTypes(parameters);
        method = beanInfo.findMethod(methodName, types);
        params = parameters;
    }
    MethodJoinpoint joinpoint = new MethodJoinpoint(method);
    joinpoint.setTarget(new ImmediateValue<Object>(bean));
    joinpoint.setParameters(params);
    return joinpoint;
}
Also used : ValueConfig(org.jboss.as.pojo.descriptor.ValueConfig) Method(java.lang.reflect.Method) StartException(org.jboss.msc.service.StartException)

Example 5 with ValueConfig

use of org.jboss.as.pojo.descriptor.ValueConfig in project wildfly by wildfly.

the class Callback method dispatch.

public void dispatch(final Object dependency) throws Throwable {
    MethodJoinpoint joinpoint = new MethodJoinpoint(getMethod());
    joinpoint.setTarget(new ImmediateValue<Object>(bean));
    ValueConfig param = new ValueConfig() {

        protected Object getClassValue(Class<?> type) {
            return dependency;
        }
    };
    joinpoint.setParameters(new ValueConfig[] { param });
    joinpoint.dispatch();
}
Also used : ValueConfig(org.jboss.as.pojo.descriptor.ValueConfig)

Aggregations

ValueConfig (org.jboss.as.pojo.descriptor.ValueConfig)5 Method (java.lang.reflect.Method)4 StartException (org.jboss.msc.service.StartException)2 Constructor (java.lang.reflect.Constructor)1 ConstructorConfig (org.jboss.as.pojo.descriptor.ConstructorConfig)1 FactoryConfig (org.jboss.as.pojo.descriptor.FactoryConfig)1 ImmediateValue (org.jboss.msc.value.ImmediateValue)1