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