@Override
protected void doParse(final Element element,
final ParserContext parserContext,
final BeanDefinitionBuilder builder) {
BeanDefinitionBuilder factoryBuilder = BeanDefinitionBuilder.genericBeanDefinition(FtpServerFactory.class);
List<Element> childs = SpringUtil.getChildElements(element);
for (Element childElm : childs) {
String childName = childElm.getLocalName();
if ("listeners".equals(childName)) {
Map<?, ?> listeners = parseListeners(childElm, parserContext, builder);
if (listeners.size() > 0) {
factoryBuilder.addPropertyValue("listeners", listeners);
}
} else if ("ftplets".equals(childName)) {
Map<?, ?> ftplets = parseFtplets(childElm, parserContext, builder);
factoryBuilder.addPropertyValue("ftplets", ftplets);
} else if ("file-user-manager".equals(childName)
|| "db-user-manager".equals(childName)) {
Object userManager = parserContext.getDelegate()
.parseCustomElement(childElm,
builder.getBeanDefinition());
factoryBuilder.addPropertyValue("userManager", userManager);
} else if ("user-manager".equals(childName)) {
factoryBuilder.addPropertyValue("userManager", SpringUtil
.parseSpringChildElement(childElm, parserContext,
builder));
} else if ("native-filesystem".equals(childName)) {
Object fileSystem = parserContext.getDelegate()
.parseCustomElement(childElm,
builder.getBeanDefinition());
factoryBuilder.addPropertyValue("fileSystem", fileSystem);
} else if ("filesystem".equals(childName)) {
factoryBuilder.addPropertyValue("fileSystem", SpringUtil
.parseSpringChildElement(childElm, parserContext,
builder));
} else if ("commands".equals(childName)) {
Object commandFactory = parserContext.getDelegate()
.parseCustomElement(childElm,
builder.getBeanDefinition());
factoryBuilder.addPropertyValue("commandFactory", commandFactory);
} else if ("messages".equals(childName)) {
MessageResource mr = parseMessageResource(childElm,
parserContext, builder);
factoryBuilder.addPropertyValue("messageResource", mr);
} else {
throw new FtpServerConfigurationException(
"Unknown configuration name: " + childName);
}
}
// Configure login limits
ConnectionConfigFactory connectionConfig = new ConnectionConfigFactory();
if (StringUtils.hasText(element.getAttribute("max-logins"))) {
connectionConfig.setMaxLogins(SpringUtil.parseInt(element,
"max-logins"));
}
if (StringUtils.hasText(element.getAttribute("max-threads"))) {
connectionConfig.setMaxThreads(SpringUtil.parseInt(element,
"max-threads"));
}
if (StringUtils.hasText(element.getAttribute("max-anon-logins"))) {
connectionConfig.setMaxAnonymousLogins(SpringUtil.parseInt(element,
"max-anon-logins"));
}
if (StringUtils.hasText(element.getAttribute("anon-enabled"))) {
connectionConfig.setAnonymousLoginEnabled(SpringUtil.parseBoolean(
element, "anon-enabled", true));
}
if (StringUtils.hasText(element.getAttribute("max-login-failures"))) {
connectionConfig.setMaxLoginFailures(SpringUtil.parseInt(element,
"max-login-failures"));
}
if (StringUtils.hasText(element.getAttribute("login-failure-delay"))) {
connectionConfig.setLoginFailureDelay(SpringUtil.parseInt(element,
"login-failure-delay"));
}
factoryBuilder.addPropertyValue("connectionConfig", connectionConfig.createConnectionConfig());
BeanDefinition factoryDefinition = factoryBuilder.getBeanDefinition();
String factoryName = parserContext.getReaderContext().generateBeanName(factoryDefinition);
BeanDefinitionHolder factoryHolder = new BeanDefinitionHolder(factoryDefinition, factoryName);
registerBeanDefinition(factoryHolder, parserContext.getRegistry());