KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > teamkonzept > web > TKHttp


1 /*
2  * $Header: /cvsroot/webman-cms/source/webman/com/teamkonzept/web/Attic/TKHttp.java,v 1.10 2001/06/11 09:14:11 alex Exp $
3  *
4  */

5 package com.teamkonzept.web;
6
7 import java.io.*;
8
9 import com.teamkonzept.lib.*;
10
11 /**
12  * Methoden und variablen vom Interface TKHttpInterface und OracleWRBInterface werden
13  * zusanmmengefuehrt.
14  * siehe: TKHttpInterface in TKHttp.java
15  * siehe: Methoden in OracleWRBInterface.java
16  * Das Interface wurde in OracleWRBInterface implementiert und wird in der Klasse
17  * TKHttp oeffentlich zur Verfuegung gestellt.
18  *
19  * Hierbei sind alle Methoden:
20  * 1. static (globale Klassenmethoden)
21  * 2.final(die Methoden koennen nicht mehr ueberschrieben werden)
22  *
23  * Aufruf der Methoden: TKHttp.methodennamen()
24  */

25 public class TKHttp {
26
27     public TKHttpInterface httpInterface;
28     public TKHttpThread httpThread;
29     public PrintStream out;
30     
31     static public PrintStream _out = System.out;
32
33     public TKHttp (TKHttpThread httpThread, TKHttpInterface httpInterface) {
34     
35         this.httpInterface = httpInterface;
36         this.httpThread = httpThread;
37
38         /* Kann man sich auch schenken, aber aus Performance-Gr¸nden doch
39            vielleicht separat halten, soviel Threads gleichzeitig werden's
40            schon nicht werden (singh)
41         */

42         //this.out = httpThread.out;
43
}
44     
45     /************************************************************************
46        hier beginnt der statische Teil der Klasse
47      ************************************************************************/

48     
49     public static TKHashtable lookup = new TKHashtable();
50     
51     public static TKHttp setup (Thread JavaDoc myThread, TKHttpThread ahttpThread, TKHttpInterface aInterface) {
52
53         if (myThread == null) myThread = Thread.currentThread();
54         if (lookup == null) lookup = new TKHashtable();
55
56         TKHttp http = (TKHttp) lookup.get(myThread);
57         if (http != null) {
58             http.httpInterface = aInterface;
59             http.httpThread = ahttpThread;
60             return http;
61         }
62         
63         http = new TKHttp(ahttpThread,aInterface);
64         lookup.put( myThread, http );
65         
66         return http;
67     }
68
69     public static TKHttp setup (TKHttpThread ahttpThread, TKHttpInterface aInterface) {
70     
71         return setup (Thread.currentThread(), ahttpThread, aInterface);
72     }
73     
74     public static void cleanup (Thread JavaDoc myThread) {
75
76         if (myThread == null) myThread = Thread.currentThread();
77         if (lookup != null) lookup.remove ( myThread );
78     }
79     
80     public static void cleanup () {
81     
82         cleanup (Thread.currentThread());
83     }
84     
85     /**
86      * Die Klassenvariable httpInterface wird gestzt.
87      *
88      * @param Thread thread, es wird ein Thread-Objekt benoetigt
89      * @param TKHttpInterface aInterface , Templateparameter und Enviroment
90      */

91     static public final void register( Thread JavaDoc thread, TKHttpThread ahttpThread, TKHttpInterface aInterface )
92     {
93         setup (thread,ahttpThread,aInterface);
94     }
95     
96     /**
97      * Die Klassenvariable httpInterface wird auf null gestzt
98      *
99      * @param Thread thread, es wird ein Thread-Objekt benoetigt
100      */

101     static public final void deregister( Thread JavaDoc thread )
102     {
103         cleanup (thread);
104     }
105     
106     /**
107      * Das zum laufenden Thread gehˆrige lookup-Object wird zur¸ckgegeben
108      *
109      */

110      
111     static public final TKHttp getContext() {
112     
113         Thread JavaDoc myThread = Thread.currentThread();
114         return (TKHttp) (lookup != null ? lookup.get(myThread) : null);
115     }
116     
117     /**
118      * Der aktuelle out-PrintStream wird zur¸ckgegeben
119      *
120      * @return PrintStream
121      */

122     
123     static public final PrintStream out() {
124
125         TKHttp http = getContext();
126         return http != null ? http.out : _out;
127     }
128     
129     /**
130      * Der aktuelle out-PrintStream wird gesetzt
131      *
132      * @return PrintStream
133      */

134     
135     static public final void out(PrintStream ps) {
136
137         if (ps != null) _out = ps;
138
139     }
140     
141     /**
142      * Die aktulelle Klassenvariable httpInterface wird zurueckgegeben
143      *
144      * @return httpInterface
145      */

146     static public final TKHttpInterface getInterface()
147     {
148         TKHttp http = getContext();
149         return http != null ? http.httpInterface : null;
150     }
151     
152     /**
153      * Der Klassenvariablen httpInterface wird das uebergebende Objekt
154      * vom Typ TKHttpInterface zugewiesen.
155      *
156      * @param TKHttpInterface aInterface
157      */

158     static public final void setInterface( TKHttpInterface aInterface )
159     {
160         TKHttp http = getContext();
161         if (http != null) http.httpInterface = aInterface;
162     }
163     
164     /**
165      * Die Methode getParams gibt einen Hash zurueck, der die in einer
166      * URL enthaltenen Parameter zurckgibt.
167      *
168      * @return TKHashtable, Parameter einer URL
169      */

170     static public final TKHashtable getParams()
171     {
172         TKHttp http = getContext();
173         return http != null ? http.httpInterface.getParams() : null;
174     }
175     
176     /**
177      * Die Methode getEnviroment gibt einen Hash zurueck, der die
178      * aktuellen Enviroment-Variablen enthaelt.
179      *
180      * @return TKHashtable, Enviroment-Variablen
181      */

182     static public final TKHashtable getEnvironment()
183     {
184         TKHttp http = getContext();
185         return http != null ? http.httpInterface.getEnvironment() : null;
186     }
187     
188     /**
189      * Die Methode getParams gibt einen Hash zurueck, der die in einer
190      * URL enthaltenen Parameter zurckgibt
191      *
192      * @return TKHashtable, Parameter einer URL
193      */

194      /*
195     static public final OutputStream getOutputStream()
196     {
197         TKHttp http = getContext();
198         return http != null ? http.httpInterface.getOutputStream() : null;
199     }
200     */

201     /**
202      * PATH_INFO der CGI-Enviroment Variablen
203      *
204      * @return /Name der laufenden Applikation
205      */

206     static public final String JavaDoc getOwnName()
207     {
208         TKHttp http = getContext();
209         return http != null ? http.httpInterface.getOwnName() : null;
210     }
211
212     /**
213      * SCRIPT_NAME+PATH_INFO der CGI-Enviroment Variablen
214      * /java/Applikationsname
215      *
216      * @return /Name der laufenden Applikation und PATH_INFO
217      */

218     static public final String JavaDoc getOwnURL()
219     {
220         TKHttp http = getContext();
221         return http != null ? http.httpInterface.getOwnURL() : null;
222     }
223     
224     /**
225      *
226      * @return gemeinsame Documentroot fuer verschiedene Benutzer
227      */

228     static public final String JavaDoc getDocumentRoot()
229     {
230         TKHttp http = getContext();
231         return http != null ? http.httpInterface.getDocumentRoot() : null;
232     }
233     
234     /**
235      *
236      * @return den Servernamen
237      */

238     static public final String JavaDoc getServerName()
239     {
240         TKHttp http = getContext();
241         return http != null ? http.httpInterface.getServerName() : null;
242     }
243
244     /**
245      *
246      * @return Ergebnis z.B.: oracle.owas.wrb.services.logger.OutputLogStream@ed310af0
247      */

248     static public final OutputStream getLogStream()
249     {
250         TKHttp http = getContext();
251         return http != null ? http.httpInterface.getLogStream() : null;
252     }
253 }
254
255
Popular Tags