KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > widget > WidgetConnection


1 /*
2  * Copyright (c) 1998-2004 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Sam
27  */

28
29
30 package com.caucho.widget;
31
32 import com.caucho.util.L10N;
33
34 import java.io.IOException JavaDoc;
35 import java.util.Enumeration JavaDoc;
36 import java.util.Locale JavaDoc;
37 import java.util.Map JavaDoc;
38 import java.util.logging.Logger JavaDoc;
39
40 abstract public class WidgetConnection
41 {
42   private static L10N L = new L10N( WidgetConnection.class );
43
44   static protected final Logger JavaDoc log =
45     Logger.getLogger( WidgetConnection.class.getName() );
46
47   public <S extends WidgetState> S prepare( Widget<S> top )
48     throws WidgetException
49   {
50     if ( top == null )
51       throw new IllegalArgumentException JavaDoc(
52           L.l( "`{0}' cannot be null", "top" ) );
53
54     String JavaDoc attributeName = "com.caucho.widget." + System.identityHashCode(top);
55
56     S widgetState = null;
57     widgetState = (S) getAttribute( attributeName );
58
59     if ( widgetState == null ) {
60       widgetState = top.decode( this );
61       setAttribute( attributeName, widgetState );
62     }
63
64     return widgetState;
65   }
66
67   public <S extends WidgetState> S render( Widget<S> top )
68     throws WidgetException, IOException JavaDoc
69   {
70     S widgetState = prepare( top );
71
72     top.render( this, widgetState );
73
74     return widgetState;
75   }
76
77   abstract public <S extends WidgetState> WidgetURL createURL()
78     throws WidgetException;
79
80   abstract public String JavaDoc[] getPreferenceValues( String JavaDoc name, String JavaDoc[] defaults );
81
82   abstract public Object JavaDoc getAttribute( String JavaDoc name );
83
84   abstract public void setAttribute( String JavaDoc name, Object JavaDoc object );
85
86   abstract public void removeAttribute( String JavaDoc name );
87
88   abstract public Locale JavaDoc getLocale();
89
90   abstract public String JavaDoc getContentType();
91
92   abstract public Enumeration JavaDoc getAttributeNames();
93
94   abstract public String JavaDoc getParameter(String JavaDoc name);
95
96   abstract public String JavaDoc[] getParameterValues(String JavaDoc name);
97
98   abstract public Map JavaDoc getParameterMap();
99
100   abstract public Enumeration JavaDoc getParameterNames();
101
102   abstract public String JavaDoc getRemoteUser();
103
104   abstract public java.security.Principal JavaDoc getUserPrincipal();
105
106   abstract public boolean isUserInRole(String JavaDoc role);
107
108   abstract public boolean isSecure();
109
110   /**
111    * Resolve a url to a resource.
112    *
113    * The <code>path</code> may be an absolute URL ("http://myserver/...")
114    * or a URI with a full path ("/myapp/mypath/....").
115    *
116    * <code>path</code> may also be a relative path ("images/myimage.gif"), in
117    * which case it is a url to a resource in the current servlet or portal.
118    *
119    * The returned URL is always an absolute url. Some browsers do not
120    * understand relative url's supplied for certain parameters (such as the
121    * location of css files).
122    *
123    * @return an absolute URL
124    */

125   abstract public String JavaDoc resolveURL( String JavaDoc path );
126
127   abstract public WidgetWriter getWriter()
128     throws IOException JavaDoc;
129
130   /**
131    * Finish with this connection, allowing it to be reused for a new connection.
132    */

133   abstract public void finish();
134 }
135
136
Popular Tags