use of org.springframework.beans.factory.FactoryBean in project cas by apereo.
the class CasCoreWebConfiguration method urlValidator.
@Bean
public FactoryBean<UrlValidator> urlValidator() {
final HttpClientProperties httpClient = this.casProperties.getHttpClient();
final boolean allowLocalLogoutUrls = httpClient.isAllowLocalLogoutUrls();
final String authorityValidationRegEx = httpClient.getAuthorityValidationRegEx();
final boolean authorityValidationRegExCaseSensitive = httpClient.isAuthorityValidationRegExCaseSensitive();
return new SimpleUrlValidatorFactoryBean(allowLocalLogoutUrls, authorityValidationRegEx, authorityValidationRegExCaseSensitive);
}
use of org.springframework.beans.factory.FactoryBean in project cas by apereo.
the class CasCoreHttpConfiguration method httpClient.
@ConditionalOnMissingBean(name = "httpClient")
@Bean
public FactoryBean<SimpleHttpClient> httpClient() {
final SimpleHttpClientFactoryBean.DefaultHttpClient c = new SimpleHttpClientFactoryBean.DefaultHttpClient();
final HttpClientProperties httpClient = casProperties.getHttpClient();
c.setConnectionTimeout(Beans.newDuration(httpClient.getConnectionTimeout()).toMillis());
c.setReadTimeout((int) Beans.newDuration(httpClient.getReadTimeout()).toMillis());
return c;
}
use of org.springframework.beans.factory.FactoryBean in project geronimo-xbean by apache.
the class NamedConstructorArgs method processParameters.
public void processParameters(BeanDefinitionHolder definitionHolder, MappingMetaData metadata) throws BeansException {
// this only works if we have an abstsract bean definition
if (!(definitionHolder.getBeanDefinition() instanceof AbstractBeanDefinition)) {
return;
}
AbstractBeanDefinition beanDefinition = (AbstractBeanDefinition) definitionHolder.getBeanDefinition();
ConstructorArgumentValues constructorArgumentValues = beanDefinition.getConstructorArgumentValues();
// if this bean already has constructor arguments defined, don't mess with them
if (constructorArgumentValues.getArgumentCount() > 0) {
return;
}
// try to get a list of constructor arg names to use
ConstructionInfo constructionInfo = selectConstructionMethod(beanDefinition, metadata);
if (constructionInfo == null) {
return;
}
// remove each named property and add an indexed constructor arg
MutablePropertyValues propertyValues = beanDefinition.getPropertyValues();
String[] parameterNames = constructionInfo.parameterNames;
Class[] parameterTypes = constructionInfo.parameterTypes;
for (int i = 0; i < parameterNames.length; i++) {
String parameterName = parameterNames[i];
Class parameterType = parameterTypes[i];
PropertyValue propertyValue = propertyValues.getPropertyValue(parameterName);
if (propertyValue != null) {
propertyValues.removePropertyValue(parameterName);
constructorArgumentValues.addIndexedArgumentValue(i, propertyValue.getValue(), parameterType.getName());
} else {
Object defaultValue = defaultValues.get(new PropertyKey(parameterName, parameterType));
if (defaultValue == null) {
defaultValue = DEFAULT_VALUE.get(parameterType);
}
if (defaultValue instanceof FactoryBean) {
try {
defaultValue = ((FactoryBean) defaultValue).getObject();
} catch (Exception e) {
throw new FatalBeanException("Unable to get object value from bean factory", e);
}
}
constructorArgumentValues.addIndexedArgumentValue(i, defaultValue, parameterType.getName());
}
}
// todo set any usable default values on the bean definition
}
use of org.springframework.beans.factory.FactoryBean in project cxf by apache.
the class AbstractFactoryBeanDefinitionParser method doParse.
@Override
protected void doParse(Element element, ParserContext ctx, BeanDefinitionBuilder bean) {
Class<?> factoryClass = getFactoryClass();
BeanDefinitionBuilder factoryBean = bean;
if (!FactoryBean.class.isAssignableFrom(factoryClass)) {
factoryBean = BeanDefinitionBuilder.rootBeanDefinition(getFactoryClass());
}
NamedNodeMap atts = element.getAttributes();
boolean createdFromAPI = false;
boolean setBus = false;
for (int i = 0; i < atts.getLength(); i++) {
Attr node = (Attr) atts.item(i);
String val = node.getValue();
String pre = node.getPrefix();
String name = node.getLocalName();
if ("createdFromAPI".equals(name)) {
factoryBean.setAbstract(true);
bean.setAbstract(true);
createdFromAPI = true;
} else if ("abstract".equals(name)) {
factoryBean.setAbstract(true);
bean.setAbstract(true);
} else if ("depends-on".equals(name)) {
factoryBean.addDependsOn(val);
bean.addDependsOn(val);
} else if (!"id".equals(name) && !"name".equals(name) && isAttribute(pre, name)) {
if ("bus".equals(name)) {
setBus = true;
if (!val.startsWith("#")) {
// bus attributes always need to be a reference
val = "#" + val;
}
}
mapAttribute(factoryBean, element, name, val);
}
}
if (!setBus) {
addBusWiringAttribute(factoryBean, BusWiringType.PROPERTY);
}
Node node = element.getFirstChild();
while (node != null) {
if (node.getNodeType() == Node.ELEMENT_NODE) {
String name = node.getLocalName();
mapElement(ctx, factoryBean, (Element) node, name);
}
node = node.getNextSibling();
}
String id = getIdOrName(element);
BeanDefinition container = ctx.getContainingBeanDefinition();
boolean noFactory = false;
if (StringUtils.isEmpty(id)) {
if (container == null) {
id = BeanDefinitionReaderUtils.generateBeanName(bean.getBeanDefinition(), ctx.getRegistry(), false);
} else {
id = BeanDefinitionReaderUtils.generateBeanName(bean.getBeanDefinition(), ctx.getRegistry(), true);
noFactory = true;
// inner bean, no need for the factory to be public at all
}
}
if (createdFromAPI) {
id = id + getSuffix();
}
if (FactoryBean.class.isAssignableFrom(getFactoryClass())) {
if (!noFactory) {
AbstractBeanDefinition def = factoryBean.getRawBeanDefinition().cloneBeanDefinition();
def.setBeanClass(getRawFactoryClass());
def.setAbstract(factoriesAreAbstract);
def.setLazyInit(true);
ctx.getRegistry().registerBeanDefinition(id + getFactoryIdSuffix(), def);
}
bean.getBeanDefinition().setAttribute("id", id);
} else {
String factoryId = id + getFactoryIdSuffix();
ctx.getRegistry().registerBeanDefinition(factoryId, factoryBean.getBeanDefinition());
bean.getRawBeanDefinition().setAttribute("id", id);
bean.getRawBeanDefinition().setFactoryBeanName(factoryId);
bean.getRawBeanDefinition().setFactoryMethodName("create");
}
if (getDestroyMethod() != null) {
bean.setDestroyMethodName(getDestroyMethod());
}
}
use of org.springframework.beans.factory.FactoryBean in project tutorials by eugenp.
the class JmsClient method invoker.
@Bean
FactoryBean invoker(ConnectionFactory factory, Queue queue) {
JmsInvokerProxyFactoryBean factoryBean = new JmsInvokerProxyFactoryBean();
factoryBean.setConnectionFactory(factory);
factoryBean.setServiceInterface(CabBookingService.class);
factoryBean.setQueue(queue);
return factoryBean;
}
Aggregations