01: /*
02: * Copyright 2002-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.springframework.web.servlet.view;
18:
19: import org.springframework.beans.factory.InitializingBean;
20:
21: /**
22: * Abstract base class for URL-based views. Provides a consistent way of
23: * holding the URL that a View wraps, in the form of a "url" bean property.
24: *
25: * @author Juergen Hoeller
26: * @since 13.12.2003
27: */
28: public abstract class AbstractUrlBasedView extends AbstractView
29: implements InitializingBean {
30:
31: private String url;
32:
33: /**
34: * Constructor for use as a bean.
35: */
36: protected AbstractUrlBasedView() {
37: }
38:
39: /**
40: * Create a new AbstractUrlBasedView with the given URL.
41: * @param url the URL to forward to
42: */
43: protected AbstractUrlBasedView(String url) {
44: this .url = url;
45: }
46:
47: /**
48: * Set the URL of the resource that this view wraps.
49: * The URL must be appropriate for the concrete View implementation.
50: */
51: public void setUrl(String url) {
52: this .url = url;
53: }
54:
55: /**
56: * Return the URL of the resource that this view wraps.
57: */
58: public String getUrl() {
59: return this .url;
60: }
61:
62: public void afterPropertiesSet() throws Exception {
63: if (getUrl() == null) {
64: throw new IllegalArgumentException(
65: "Property 'url' is required");
66: }
67: }
68:
69: public String toString() {
70: StringBuffer sb = new StringBuffer(super .toString());
71: sb.append("; URL [").append(getUrl()).append("]");
72: return sb.toString();
73: }
74:
75: }
|