Source Code Cross Referenced for NamespaceHandlerSupport.java in  » J2EE » spring-framework-2.0.6 » org » springframework » beans » factory » xml » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » spring framework 2.0.6 » org.springframework.beans.factory.xml 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2002-2007 the original author or authors.
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:
017:        package org.springframework.beans.factory.xml;
018:
019:        import java.util.HashMap;
020:        import java.util.Map;
021:
022:        import org.w3c.dom.Attr;
023:        import org.w3c.dom.Element;
024:        import org.w3c.dom.Node;
025:
026:        import org.springframework.beans.factory.config.BeanDefinition;
027:        import org.springframework.beans.factory.config.BeanDefinitionHolder;
028:
029:        /**
030:         * Support class for implementing custom {@link NamespaceHandler NamespaceHandlers}. Parsing and
031:         * decorating of individual {@link Node Nodes} is done via {@link BeanDefinitionParser} and
032:         * {@link BeanDefinitionDecorator} strategy interfaces respectively. Provides the
033:         * {@link #registerBeanDefinitionParser}, {@link #registerBeanDefinitionDecorator} methods
034:         * for registering a {@link BeanDefinitionParser} or {@link BeanDefinitionDecorator} to handle
035:         * a specific element.
036:         *
037:         * @author Rob Harrop
038:         * @author Juergen Hoeller
039:         * @since 2.0
040:         * @see #registerBeanDefinitionParser(String, BeanDefinitionParser)
041:         * @see #registerBeanDefinitionDecorator(String, BeanDefinitionDecorator)
042:         */
043:        public abstract class NamespaceHandlerSupport implements 
044:                NamespaceHandler {
045:
046:            /**
047:             * Stores the {@link BeanDefinitionParser} implementations keyed by the
048:             * local name of the {@link Element Elements} they handle.
049:             */
050:            private final Map parsers = new HashMap();
051:
052:            /**
053:             * Stores the {@link BeanDefinitionDecorator} implementations keyed by the
054:             * local name of the {@link Element Elements} they handle.
055:             */
056:            private final Map decorators = new HashMap();
057:
058:            /**
059:             * Stores the {@link BeanDefinitionParser} implementations keyed by the local
060:             * name of the {@link Attr Attrs} they handle.
061:             */
062:            private final Map attributeDecorators = new HashMap();
063:
064:            /**
065:             * Parses the supplied {@link Element} by delegating to the {@link BeanDefinitionParser} that is
066:             * registered for that {@link Element}.
067:             */
068:            public final BeanDefinition parse(Element element,
069:                    ParserContext parserContext) {
070:                return findParserForElement(element, parserContext).parse(
071:                        element, parserContext);
072:            }
073:
074:            /**
075:             * Locates the {@link BeanDefinitionParser} from the register implementations using
076:             * the local name of the supplied {@link Element}.
077:             */
078:            private BeanDefinitionParser findParserForElement(Element element,
079:                    ParserContext parserContext) {
080:                BeanDefinitionParser parser = (BeanDefinitionParser) this .parsers
081:                        .get(element.getLocalName());
082:                if (parser == null) {
083:                    parserContext.getReaderContext().fatal(
084:                            "Cannot locate BeanDefinitionParser for element ["
085:                                    + element.getLocalName() + "]", element);
086:                }
087:                return parser;
088:            }
089:
090:            /**
091:             * Locate the {@link BeanDefinitionParser} from the register implementations using
092:             * the local name of the supplied {@link Element}.
093:             * @deprecated as of Spring 2.0.2; there should be no need to call this directly.
094:             */
095:            protected final BeanDefinitionParser findParserForElement(
096:                    Element element) {
097:                BeanDefinitionParser parser = (BeanDefinitionParser) this .parsers
098:                        .get(element.getLocalName());
099:                if (parser == null) {
100:                    throw new IllegalStateException(
101:                            "Cannot locate BeanDefinitionParser for element ["
102:                                    + element.getLocalName() + "]");
103:                }
104:                return parser;
105:            }
106:
107:            /**
108:             * Decorates the supplied {@link Node} by delegating to the {@link BeanDefinitionDecorator} that
109:             * is registered to handle that {@link Node}.
110:             */
111:            public final BeanDefinitionHolder decorate(Node node,
112:                    BeanDefinitionHolder definition, ParserContext parserContext) {
113:
114:                return findDecoratorForNode(node, parserContext).decorate(node,
115:                        definition, parserContext);
116:            }
117:
118:            /**
119:             * Locates the {@link BeanDefinitionParser} from the register implementations using
120:             * the local name of the supplied {@link Node}. Supports both {@link Element Elements}
121:             * and {@link Attr Attrs}.
122:             */
123:            private BeanDefinitionDecorator findDecoratorForNode(Node node,
124:                    ParserContext parserContext) {
125:                BeanDefinitionDecorator decorator = null;
126:                if (node instanceof  Element) {
127:                    decorator = (BeanDefinitionDecorator) this .decorators
128:                            .get(node.getLocalName());
129:                } else if (node instanceof  Attr) {
130:                    decorator = (BeanDefinitionDecorator) this .attributeDecorators
131:                            .get(node.getLocalName());
132:                } else {
133:                    parserContext.getReaderContext().fatal(
134:                            "Cannot decorate based on Nodes of type ["
135:                                    + node.getClass().getName() + "]", node);
136:                }
137:                if (decorator == null) {
138:                    parserContext.getReaderContext().fatal(
139:                            "Cannot locate BeanDefinitionDecorator for "
140:                                    + (node instanceof  Element ? "element"
141:                                            : "attribute") + " ["
142:                                    + node.getLocalName() + "]", node);
143:                }
144:                return decorator;
145:            }
146:
147:            /**
148:             * Locate the {@link BeanDefinitionParser} from the register implementations using
149:             * the local name of the supplied {@link Node}. Supports both {@link Element Elements}
150:             * and {@link Attr Attrs}.
151:             * @deprecated as of Spring 2.0.2; there should be no need to call this directly.
152:             */
153:            protected final BeanDefinitionDecorator findDecoratorForNode(
154:                    Node node) {
155:                BeanDefinitionDecorator decorator = null;
156:                if (node instanceof  Element) {
157:                    decorator = (BeanDefinitionDecorator) this .decorators
158:                            .get(node.getLocalName());
159:                } else if (node instanceof  Attr) {
160:                    decorator = (BeanDefinitionDecorator) this .attributeDecorators
161:                            .get(node.getLocalName());
162:                } else {
163:                    throw new IllegalStateException(
164:                            "Cannot decorate based on Nodes of type ["
165:                                    + node.getClass().getName() + "]");
166:                }
167:                if (decorator == null) {
168:                    throw new IllegalStateException(
169:                            "Cannot locate BeanDefinitionDecorator for "
170:                                    + (node instanceof  Element ? "element"
171:                                            : "attribute") + " ["
172:                                    + node.getLocalName() + "]");
173:                }
174:                return decorator;
175:            }
176:
177:            /**
178:             * Subclasses can call this to register the supplied {@link BeanDefinitionParser} to
179:             * handle the specified element. The element name is the local (non-namespace qualified)
180:             * name.
181:             */
182:            protected final void registerBeanDefinitionParser(
183:                    String elementName, BeanDefinitionParser parser) {
184:                this .parsers.put(elementName, parser);
185:            }
186:
187:            /**
188:             * Subclasses can call this to register the supplied {@link BeanDefinitionDecorator} to
189:             * handle the specified element. The element name is the local (non-namespace qualified)
190:             * name.
191:             */
192:            protected final void registerBeanDefinitionDecorator(
193:                    String elementName, BeanDefinitionDecorator decorator) {
194:                this .decorators.put(elementName, decorator);
195:            }
196:
197:            /**
198:             * Subclasses can call this to register the supplied {@link BeanDefinitionDecorator} to
199:             * handle the specified attribute. The attribute name is the local (non-namespace qualified)
200:             * name.
201:             */
202:            protected final void registerBeanDefinitionDecoratorForAttribute(
203:                    String attributeName, BeanDefinitionDecorator decorator) {
204:
205:                this.attributeDecorators.put(attributeName, decorator);
206:            }
207:
208:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.