]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/xml/AsFlowDecorator.java
Improve system calls
[gpl/argeo-slc.git] / runtime / org.argeo.slc.core / src / main / java / org / argeo / slc / core / execution / xml / AsFlowDecorator.java
1 /*
2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package org.argeo.slc.core.execution.xml;
18
19 import org.apache.commons.logging.Log;
20 import org.apache.commons.logging.LogFactory;
21 import org.argeo.slc.SlcException;
22 import org.argeo.slc.core.execution.DefaultExecutionFlow;
23 import org.springframework.beans.factory.config.BeanDefinitionHolder;
24 import org.springframework.beans.factory.config.RuntimeBeanReference;
25 import org.springframework.beans.factory.support.BeanDefinitionBuilder;
26 import org.springframework.beans.factory.support.ManagedList;
27 import org.springframework.beans.factory.xml.BeanDefinitionDecorator;
28 import org.springframework.beans.factory.xml.ParserContext;
29 import org.w3c.dom.Attr;
30 import org.w3c.dom.Node;
31
32 public class AsFlowDecorator implements BeanDefinitionDecorator {
33 private Log log = LogFactory.getLog(AsFlowDecorator.class);
34
35 @SuppressWarnings("unchecked")
36 public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder bean,
37 ParserContext ctx) {
38 String attrValue = ((Attr) node).getValue();
39 if (attrValue.charAt(attrValue.length() - 1) == '/')
40 throw new SlcException(attrValue + " cannot end with a path");
41 // int lastSlash = attrValue.lastIndexOf('/');
42 // String path;
43 // String flowBeanName;
44 // if (lastSlash > 0) {
45 // flowBeanName = attrValue.substring(lastSlash + 1);
46 // path = attrValue.substring(0, lastSlash);
47 // } else if (lastSlash == 0) {
48 // flowBeanName = attrValue.substring(lastSlash + 1);
49 // path = null;
50 // } else {
51 // flowBeanName = attrValue;
52 // path = null;
53 // }
54 //
55 final String flowBeanName = attrValue;
56 final String path = null;
57
58 if (log.isTraceEnabled())
59 log.debug("path=" + path + ", flowBeanName=" + flowBeanName);
60
61 if (ctx.getRegistry().containsBeanDefinition(flowBeanName))
62 throw new SlcException("A bean named " + flowBeanName
63 + " is already defined.");
64 BeanDefinitionBuilder flow = BeanDefinitionBuilder
65 .rootBeanDefinition(DefaultExecutionFlow.class);
66 ManagedList executables = new ManagedList(1);
67
68 String beanName = bean.getBeanName();
69 if (beanName == null)
70 executables.add(bean.getBeanDefinition());
71 else
72 executables.add(new RuntimeBeanReference(beanName));
73
74 if (path != null)
75 flow.addPropertyValue("path", path);
76 flow.addPropertyValue("executables", executables);
77
78 if (beanName != null)
79 ctx.getRegistry().registerBeanDefinition(flowBeanName,
80 flow.getBeanDefinition());
81 return bean;
82 }
83
84 }