KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > web > portlet > context > PortletApplicationObjectSupport


1 /*
2  * Copyright 2002-2005 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.portlet.context;
18
19 import java.io.File JavaDoc;
20
21 import javax.portlet.PortletContext;
22
23 import org.springframework.context.support.ApplicationObjectSupport;
24 import org.springframework.web.portlet.util.PortletUtils;
25
26 /**
27  * Convenient superclass for application objects running in a Portlet ApplicationContext.
28  * Provides getApplicationContext, getServletContext, and getTempDir methods.
29  *
30  * @author Juergen Hoeller
31  * @since 2.0
32  */

33 public abstract class PortletApplicationObjectSupport extends ApplicationObjectSupport
34         implements PortletContextAware {
35
36     private PortletContext portletContext;
37
38
39     public void setPortletContext(PortletContext portletContext) {
40         this.portletContext = portletContext;
41     }
42
43
44     /**
45      * Overrides the base class behavior to enforce running in an ApplicationContext.
46      * All accessors will throw IllegalStateException if not running in a context.
47      * @see #getApplicationContext()
48      * @see #getMessageSourceAccessor()
49      * @see #getPortletContext()
50      * @see #getTempDir()
51      */

52     protected boolean isContextRequired() {
53         return true;
54     }
55
56     /**
57      * Return the current PortletContext.
58      * @throws IllegalStateException if not running within a PortletContext
59      */

60     protected final PortletContext getPortletContext() throws IllegalStateException JavaDoc {
61         if (this.portletContext == null) {
62             throw new IllegalStateException JavaDoc(
63                     "PortletApplicationObjectSupport instance [" + this + "] does not run within a PortletContext");
64         }
65         return this.portletContext;
66     }
67
68     /**
69      * Return the temporary directory for the current web application,
70      * as provided by the servlet container.
71      * @return the File representing the temporary directory
72      * @throws IllegalStateException if not running within a PortletContext
73      * @see org.springframework.web.portlet.util.PortletUtils#getTempDir(javax.portlet.PortletContext)
74      */

75     protected final File JavaDoc getTempDir() throws IllegalStateException JavaDoc {
76         return PortletUtils.getTempDir(getPortletContext());
77     }
78
79 }
80
Popular Tags