01: /*
02: * Copyright 2004-2006 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:
17: package org.compass.spring.web.mvc;
18:
19: import org.compass.core.Compass;
20: import org.compass.core.CompassTemplate;
21: import org.springframework.beans.factory.InitializingBean;
22: import org.springframework.web.servlet.mvc.AbstractCommandController;
23:
24: /**
25: * A general base class for Spring's MVC Command Controllers that use
26: * <code>Compass</code>.
27: * <p>
28: * Expects <code>Compass</code> instance to be injected, and provides access
29: * to both <code>Compass</code> and <code>CompassTemplate</code> instances.
30: *
31: * @author kimchy
32: */
33: public abstract class AbstractCompassCommandController extends
34: AbstractCommandController implements InitializingBean {
35:
36: private Compass compass;
37:
38: private CompassTemplate compassTemplate;
39:
40: public void afterPropertiesSet() throws Exception {
41: if (compass == null) {
42: throw new IllegalArgumentException(
43: "Must set compass property");
44: }
45: this .compassTemplate = new CompassTemplate(compass);
46: }
47:
48: /**
49: * Returns <code>Compass</code> instance.
50: *
51: * @return The compass instance.
52: */
53: public Compass getCompass() {
54: return compass;
55: }
56:
57: /**
58: * Sets the <code>Compass</code> instance.
59: *
60: * @param compass
61: */
62: public void setCompass(Compass compass) {
63: this .compass = compass;
64: }
65:
66: /**
67: * Returns a <code>CompassTemplate</code> that wraps the injected
68: * <code>Compass</code> instance.
69: *
70: * @return Compass template that wraps the injected Compass instance.
71: */
72: protected CompassTemplate getCompassTemplate() {
73: return this.compassTemplate;
74: }
75: }
|