View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.jetspeed.factory;
18  
19  import java.io.IOException;
20  
21  import javax.portlet.ActionRequest;
22  import javax.portlet.ActionResponse;
23  import javax.portlet.Portlet;
24  import javax.portlet.PortletConfig;
25  import javax.portlet.PortletException;
26  import javax.portlet.RenderRequest;
27  import javax.portlet.RenderResponse;
28  import javax.portlet.UnavailableException;
29  
30  import org.apache.jetspeed.factory.PortletInstance;
31  
32  /***
33   * JetspeedPortletInstance
34   * 
35   * @author <a href="mailto:ate@douma.nu">Ate Douma</a>
36   * @version $Id: JetspeedPortletInstance.java 516448 2007-03-09 16:25:47Z ate $
37   *
38   */
39  public class JetspeedPortletInstance implements PortletInstance
40  {
41    private Portlet portlet;
42    private PortletConfig config;
43    private boolean destroyed;
44    private final String portletName;
45    
46    public JetspeedPortletInstance(String portletName, Portlet portlet)
47    {
48        this.portletName = portletName;
49        this.portlet = portlet;
50    }
51    
52    private void checkAvailable() throws UnavailableException
53    {
54        if ( destroyed )
55        {
56            throw new UnavailableException("Portlet "+portletName+" no longer available");
57        }
58    }
59    
60    public void destroy()
61    {
62        if (!destroyed)
63        {
64            destroyed = true;
65            if ( config != null )
66            {
67                // Portlet really has been put into service, now destroy it.
68                portlet.destroy();
69            }
70        }
71    }
72    
73    public boolean equals(Object obj)
74    {
75      return portlet.equals(obj);
76    }
77    
78    public int hashCode()
79    {
80      return portlet.hashCode();
81    }
82    
83    public void init(PortletConfig config) throws PortletException
84    {
85      portlet.init(config);
86      this.config = config;
87    }
88    
89    public PortletConfig getConfig()
90    {
91        return config;
92    }
93    
94    public void processAction(ActionRequest request, ActionResponse response) throws PortletException, IOException
95    {
96      checkAvailable();
97      portlet.processAction(request, response);
98    }
99    
100   public void render(RenderRequest request, RenderResponse response) throws PortletException, IOException
101   {
102     checkAvailable();
103     portlet.render(request, response);
104   }
105   
106   public String toString()
107   {
108       return portlet.toString();
109   }
110 
111 
112 /***
113  * @return Returns the portlet.
114  */
115 public Portlet getRealPortlet()
116 {
117     return portlet;
118 }
119 }