001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.jetspeed.factory;
018:
019: import java.io.IOException;
020:
021: import javax.portlet.ActionRequest;
022: import javax.portlet.ActionResponse;
023: import javax.portlet.Portlet;
024: import javax.portlet.PortletConfig;
025: import javax.portlet.PortletException;
026: import javax.portlet.RenderRequest;
027: import javax.portlet.RenderResponse;
028: import javax.portlet.UnavailableException;
029:
030: import org.apache.jetspeed.factory.PortletInstance;
031:
032: /**
033: * JetspeedPortletInstance
034: *
035: * @author <a href="mailto:ate@douma.nu">Ate Douma</a>
036: * @version $Id: JetspeedPortletInstance.java 516448 2007-03-09 16:25:47Z ate $
037: *
038: */
039: public class JetspeedPortletInstance implements PortletInstance {
040: private Portlet portlet;
041: private PortletConfig config;
042: private boolean destroyed;
043: private final String portletName;
044:
045: public JetspeedPortletInstance(String portletName, Portlet portlet) {
046: this .portletName = portletName;
047: this .portlet = portlet;
048: }
049:
050: private void checkAvailable() throws UnavailableException {
051: if (destroyed) {
052: throw new UnavailableException("Portlet " + portletName
053: + " no longer available");
054: }
055: }
056:
057: public void destroy() {
058: if (!destroyed) {
059: destroyed = true;
060: if (config != null) {
061: // Portlet really has been put into service, now destroy it.
062: portlet.destroy();
063: }
064: }
065: }
066:
067: public boolean equals(Object obj) {
068: return portlet.equals(obj);
069: }
070:
071: public int hashCode() {
072: return portlet.hashCode();
073: }
074:
075: public void init(PortletConfig config) throws PortletException {
076: portlet.init(config);
077: this .config = config;
078: }
079:
080: public PortletConfig getConfig() {
081: return config;
082: }
083:
084: public void processAction(ActionRequest request,
085: ActionResponse response) throws PortletException,
086: IOException {
087: checkAvailable();
088: portlet.processAction(request, response);
089: }
090:
091: public void render(RenderRequest request, RenderResponse response)
092: throws PortletException, IOException {
093: checkAvailable();
094: portlet.render(request, response);
095: }
096:
097: public String toString() {
098: return portlet.toString();
099: }
100:
101: /**
102: * @return Returns the portlet.
103: */
104: public Portlet getRealPortlet() {
105: return portlet;
106: }
107: }
|