01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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.pluto.internal.impl;
18:
19: import org.apache.pluto.internal.InternalPortletRequest;
20: import org.apache.pluto.internal.InternalPortletResponse;
21: import org.apache.pluto.wrappers.PortletRequestWrapper;
22: import org.apache.pluto.wrappers.PortletResponseWrapper;
23:
24: import javax.portlet.PortletRequest;
25: import javax.portlet.PortletResponse;
26:
27: /**
28: * Static class that provides utility methods to convert a generic
29: * PortletRequest or PortletResponse object into an Internal respresentation
30: * of the same object.
31: */
32: class InternalImplConverter {
33:
34: /**
35: * Private constructor that prevents external instantiation.
36: */
37: private InternalImplConverter() {
38: // Do nothing.
39: }
40:
41: // Public Static Utility Methods -------------------------------------------
42:
43: /**
44: * The scary part about this is that there is not yet a
45: * PortletRequestWrapper defined by the spec. Because of this, there's a
46: * chance someone might implement their own wrapper and we won't be able to
47: * get the real internal one!
48: * @param request the portlet request to be converted.
49: * @return the internal request.
50: */
51: public static InternalPortletRequest getInternalRequest(
52: PortletRequest request) {
53: while (!(request instanceof InternalPortletRequest)) {
54: request = ((PortletRequestWrapper) request)
55: .getPortletRequest();
56: if (request == null) {
57: throw new IllegalStateException(
58: "The internal portlet request cannot be found.");
59: }
60: }
61: return (InternalPortletRequest) request;
62: }
63:
64: /**
65: * The scary part about this is that there is not yet a
66: * PortletRequestWrapper defined by the spec. Because of this, there's a
67: * chance someone might implement their own wrapper and we won't be able to
68: * get the real internal one!
69: * @param response the portlet response to be converted.
70: * @return the internal response.
71: */
72: public static InternalPortletResponse getInternalResponse(
73: PortletResponse response) {
74: while (!(response instanceof InternalPortletResponse)) {
75: response = ((PortletResponseWrapper) response)
76: .getPortletResponse();
77: if (response == null) {
78: throw new IllegalStateException(
79: "The internal portlet response cannot be found.");
80: }
81: }
82: return (InternalPortletResponse) response;
83: }
84:
85: }
|