Browse Source
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4304 50f2f4bb-b051-0410-bef5-90022cba6387pull/1/merge
10 changed files with 184 additions and 140 deletions
@ -1,57 +0,0 @@
@@ -1,57 +0,0 @@
|
||||
/* |
||||
* Copyright 2002-2010 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.web.servlet.config; |
||||
|
||||
import org.w3c.dom.Element; |
||||
|
||||
import org.springframework.beans.factory.config.BeanDefinition; |
||||
import org.springframework.beans.factory.parsing.BeanComponentDefinition; |
||||
import org.springframework.beans.factory.support.RootBeanDefinition; |
||||
import org.springframework.beans.factory.xml.BeanDefinitionParser; |
||||
import org.springframework.beans.factory.xml.ParserContext; |
||||
import org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter; |
||||
|
||||
/** |
||||
* Abstract base class for {@link BeanDefinitonParser}s that register an HttpRequestHandler. |
||||
* |
||||
* @author Jeremy Grelle |
||||
* @since 3.0.4 |
||||
*/ |
||||
abstract class AbstractHttpRequestHandlerBeanDefinitionParser implements BeanDefinitionParser{ |
||||
|
||||
private static final String HANDLER_ADAPTER_BEAN_NAME = "org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter"; |
||||
|
||||
public BeanDefinition parse(Element element, ParserContext parserContext) { |
||||
Object source = parserContext.extractSource(element); |
||||
registerHandlerAdapterIfNecessary(parserContext, source); |
||||
doParse(element, parserContext); |
||||
return null; |
||||
} |
||||
|
||||
public abstract void doParse(Element element, ParserContext parserContext); |
||||
|
||||
private void registerHandlerAdapterIfNecessary(ParserContext parserContext, Object source) { |
||||
if (!parserContext.getRegistry().containsBeanDefinition(HANDLER_ADAPTER_BEAN_NAME)) { |
||||
RootBeanDefinition handlerAdapterDef = new RootBeanDefinition(HttpRequestHandlerAdapter.class); |
||||
handlerAdapterDef.setSource(source); |
||||
handlerAdapterDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); |
||||
parserContext.getRegistry().registerBeanDefinition(HANDLER_ADAPTER_BEAN_NAME, handlerAdapterDef); |
||||
parserContext.registerComponent(new BeanComponentDefinition(handlerAdapterDef, HANDLER_ADAPTER_BEAN_NAME)); |
||||
} |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,80 @@
@@ -0,0 +1,80 @@
|
||||
/* |
||||
* Copyright 2002-2010 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.web.servlet.config; |
||||
|
||||
import org.springframework.beans.factory.config.BeanDefinition; |
||||
import org.springframework.beans.factory.parsing.BeanComponentDefinition; |
||||
import org.springframework.beans.factory.support.RootBeanDefinition; |
||||
import org.springframework.beans.factory.xml.ParserContext; |
||||
import org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping; |
||||
import org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter; |
||||
import org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter; |
||||
|
||||
/** |
||||
* Convenience methods for MVC namespace handlers. |
||||
* |
||||
* @author Rossen Stoyanchev |
||||
* @since 3.1 |
||||
*/ |
||||
abstract class MvcNamespaceUtils { |
||||
|
||||
private static final String BEAN_NAME_URL_HANDLER_MAPPING = |
||||
"org.springframework.web.servlet.handler.beanNameUrlHandlerMapping"; |
||||
|
||||
private static final String VIEW_CONTROLLER_HANDLER_ADAPTER = |
||||
"org.springframework.web.servlet.config.viewControllerHandlerAdapter"; |
||||
|
||||
private static final String HTTP_REQUEST_HANDLER_ADAPTER = |
||||
"org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter"; |
||||
|
||||
public static void registerDefaultHandlerAdapters(ParserContext parserContext, Object source) { |
||||
registerHttpRequestHandlerAdapter(parserContext, source); |
||||
registerSimpleControllerHandlerAdapter(parserContext, source); |
||||
} |
||||
|
||||
public static void registerBeanNameUrlHandlerMapping(ParserContext parserContext, Object source) { |
||||
if (!parserContext.getRegistry().containsBeanDefinition(BEAN_NAME_URL_HANDLER_MAPPING)){ |
||||
RootBeanDefinition beanNameMappingDef = new RootBeanDefinition(BeanNameUrlHandlerMapping.class); |
||||
beanNameMappingDef.setSource(source); |
||||
beanNameMappingDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); |
||||
beanNameMappingDef.getPropertyValues().add("order", 2); // consistent with MvcConfiguration
|
||||
parserContext.getRegistry().registerBeanDefinition(BEAN_NAME_URL_HANDLER_MAPPING, beanNameMappingDef); |
||||
parserContext.registerComponent(new BeanComponentDefinition(beanNameMappingDef, BEAN_NAME_URL_HANDLER_MAPPING)); |
||||
} |
||||
} |
||||
|
||||
public static void registerHttpRequestHandlerAdapter(ParserContext parserContext, Object source) { |
||||
if (!parserContext.getRegistry().containsBeanDefinition(HTTP_REQUEST_HANDLER_ADAPTER)) { |
||||
RootBeanDefinition handlerAdapterDef = new RootBeanDefinition(HttpRequestHandlerAdapter.class); |
||||
handlerAdapterDef.setSource(source); |
||||
handlerAdapterDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); |
||||
parserContext.getRegistry().registerBeanDefinition(HTTP_REQUEST_HANDLER_ADAPTER, handlerAdapterDef); |
||||
parserContext.registerComponent(new BeanComponentDefinition(handlerAdapterDef, HTTP_REQUEST_HANDLER_ADAPTER)); |
||||
} |
||||
} |
||||
|
||||
public static void registerSimpleControllerHandlerAdapter(ParserContext parserContext, Object source) { |
||||
if (!parserContext.getRegistry().containsBeanDefinition(VIEW_CONTROLLER_HANDLER_ADAPTER)) { |
||||
RootBeanDefinition handlerAdapterDef = new RootBeanDefinition(SimpleControllerHandlerAdapter.class); |
||||
handlerAdapterDef.setSource(source); |
||||
handlerAdapterDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); |
||||
parserContext.getRegistry().registerBeanDefinition(VIEW_CONTROLLER_HANDLER_ADAPTER, handlerAdapterDef); |
||||
parserContext.registerComponent(new BeanComponentDefinition(handlerAdapterDef, VIEW_CONTROLLER_HANDLER_ADAPTER)); |
||||
} |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,10 @@
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:mvc="http://www.springframework.org/schema/mvc" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd |
||||
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> |
||||
|
||||
<mvc:view-controller path="/" view-name="home"/> |
||||
|
||||
</beans> |
||||
Loading…
Reference in new issue