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 java.util.HashMap;
19: import java.util.Map;
20:
21: import org.apache.commons.logging.Log;
22: import org.apache.commons.logging.LogFactory;
23: import org.springframework.beans.BeansException;
24: import org.springframework.util.Assert;
25: import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping;
26:
27: /**
28: * Automatically maps (at context startup) the URLs needed by DWR to a DWRController.
29: *
30: * @author Jose Noheda [jose.noheda@gmail.com]
31: */
32: public class DwrHandlerMapping extends SimpleUrlHandlerMapping {
33:
34: protected static final Log log = LogFactory
35: .getLog(DwrHandlerMapping.class);
36:
37: /**
38: * Maps the URLs (/engine.js, /util.js, /interface/**, /call/**) and continues.
39: */
40: @Override
41: public void initApplicationContext() throws BeansException {
42: String[] dwrControllerName = getApplicationContext()
43: .getBeanNamesForType(DwrController.class);
44: Assert.notEmpty(dwrControllerName,
45: "No DWR Controller bean definition found.");
46: Object handler = getApplicationContext().getBean(
47: dwrControllerName[0]);
48: Map<String, Object> mappings = new HashMap<String, Object>();
49: mappings.put("/engine.js", handler);
50: mappings.put("/util.js", handler);
51: mappings.put("/interface/**", handler);
52: mappings.put("/call/**", handler);
53: mappings.put("/test/**", handler);
54: if (log.isDebugEnabled()) {
55: log.debug("[engine.js] mapped to dwrController");
56: log.debug("[util.js] mapped to dwrController");
57: log
58: .debug("Interface beans and calls mapped to dwrController");
59: }
60: setUrlMap(mappings);
61: super.initApplicationContext();
62: }
63:
64: }
|