01: /*
02: * Copyright 2008 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: package org.directwebremoting.spring;
17:
18: import org.springframework.beans.factory.config.BeanDefinition;
19: import org.springframework.beans.factory.support.BeanDefinitionBuilder;
20: import org.springframework.beans.factory.xml.BeanDefinitionParser;
21: import org.springframework.beans.factory.xml.ParserContext;
22: import org.w3c.dom.Element;
23:
24: /**
25: * Adds the missing elements to the DWR namespace handling. Namely <dwr:annotation-config />
26: *
27: * @author Jose Noheda [jose.noheda@gmail.com]
28: */
29: public class DwrAnnotationNamespaceHandler extends DwrNamespaceHandler {
30:
31: /**
32: * Add a new Parser to register <dwr:annotation-config />
33: *
34: * @see org.directwebremoting.spring.DwrNamespaceHandler#init()
35: */
36: @Override
37: public void init() {
38: super .init();
39: registerBeanDefinitionParser("annotation-config",
40: new AnnotationConfigBeanDefinitionParser());
41: }
42:
43: /**
44: * Register a new bean definition for each Spring bean that is annotated with
45: * {@link org.directwebremoting.annotations.RemoteProxy}.
46: *
47: * @author Jose Noheda [jose.noheda@gmail.com]
48: */
49: protected class AnnotationConfigBeanDefinitionParser implements
50: BeanDefinitionParser {
51:
52: /**
53: * Creates a post-processor that will scan the context for candidate beans.
54: *
55: * @param element <dwr:annotation-config />
56: * @param parserContext a reference to the bean registry
57: */
58: public BeanDefinition parse(Element element,
59: ParserContext parserContext) {
60: BeanDefinitionBuilder builder = BeanDefinitionBuilder
61: .rootBeanDefinition(DwrAnnotationPostProcessor.class);
62: parserContext.getRegistry().registerBeanDefinition(
63: "dwrAnnotationPostProcessor",
64: builder.getBeanDefinition());
65: return parserContext.getRegistry().getBeanDefinition(
66: "dwrAnnotationPostProcessor");
67: }
68:
69: }
70:
71: }
|