001: /*
002: * Copyright (c) 1998-2004 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Sam
027: */
028:
029: package com.caucho.widget;
030:
031: import com.caucho.util.L10N;
032:
033: import java.io.IOException;
034: import java.util.Enumeration;
035: import java.util.Locale;
036: import java.util.Map;
037: import java.util.logging.Logger;
038:
039: abstract public class WidgetConnection {
040: private static L10N L = new L10N(WidgetConnection.class);
041:
042: static protected final Logger log = Logger
043: .getLogger(WidgetConnection.class.getName());
044:
045: public <S extends WidgetState> S prepare(Widget<S> top)
046: throws WidgetException {
047: if (top == null)
048: throw new IllegalArgumentException(L.l(
049: "`{0}' cannot be null", "top"));
050:
051: String attributeName = "com.caucho.widget."
052: + System.identityHashCode(top);
053:
054: S widgetState = null;
055: widgetState = (S) getAttribute(attributeName);
056:
057: if (widgetState == null) {
058: widgetState = top.decode(this );
059: setAttribute(attributeName, widgetState);
060: }
061:
062: return widgetState;
063: }
064:
065: public <S extends WidgetState> S render(Widget<S> top)
066: throws WidgetException, IOException {
067: S widgetState = prepare(top);
068:
069: top.render(this , widgetState);
070:
071: return widgetState;
072: }
073:
074: abstract public <S extends WidgetState> WidgetURL createURL()
075: throws WidgetException;
076:
077: abstract public String[] getPreferenceValues(String name,
078: String[] defaults);
079:
080: abstract public Object getAttribute(String name);
081:
082: abstract public void setAttribute(String name, Object object);
083:
084: abstract public void removeAttribute(String name);
085:
086: abstract public Locale getLocale();
087:
088: abstract public String getContentType();
089:
090: abstract public Enumeration getAttributeNames();
091:
092: abstract public String getParameter(String name);
093:
094: abstract public String[] getParameterValues(String name);
095:
096: abstract public Map getParameterMap();
097:
098: abstract public Enumeration getParameterNames();
099:
100: abstract public String getRemoteUser();
101:
102: abstract public java.security.Principal getUserPrincipal();
103:
104: abstract public boolean isUserInRole(String role);
105:
106: abstract public boolean isSecure();
107:
108: /**
109: * Resolve a url to a resource.
110: *
111: * The <code>path</code> may be an absolute URL ("http://myserver/...")
112: * or a URI with a full path ("/myapp/mypath/....").
113: *
114: * <code>path</code> may also be a relative path ("images/myimage.gif"), in
115: * which case it is a url to a resource in the current servlet or portal.
116: *
117: * The returned URL is always an absolute url. Some browsers do not
118: * understand relative url's supplied for certain parameters (such as the
119: * location of css files).
120: *
121: * @return an absolute URL
122: */
123: abstract public String resolveURL(String path);
124:
125: abstract public WidgetWriter getWriter() throws IOException;
126:
127: /**
128: * Finish with this connection, allowing it to be reused for a new connection.
129: */
130: abstract public void finish();
131: }
|