KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jk > core > WorkerEnv


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.jk.core;
18
19 import java.util.Hashtable JavaDoc;
20 import javax.management.ObjectName JavaDoc;
21
22 /**
23  * The controller object. It manages all other jk objects, acting as the root of
24  * the jk object model.
25  *
26  * @author Gal Shachor
27  * @author Henri Gomez [hgomez@apache.org]
28  * @author Dan Milstein [danmil@shore.net]
29  * @author Keith Wannamaker [Keith@Wannamaker.org]
30  * @author Kevin Seguin
31  * @author Costin Manolache
32  */

33 public class WorkerEnv {
34
35     Hashtable JavaDoc properties;
36
37     public static final int ENDPOINT_NOTE=0;
38     public static final int REQUEST_NOTE=1;
39     public static final int SSL_CERT_NOTE=16;
40     int noteId[]=new int[4];
41     String JavaDoc noteName[][]=new String JavaDoc[4][];
42     private Object JavaDoc notes[]=new Object JavaDoc[32];
43
44     Hashtable JavaDoc handlersMap=new Hashtable JavaDoc();
45     JkHandler handlersTable[]=new JkHandler[20];
46     int handlerCount=0;
47     
48     // base dir for the jk webapp
49
String JavaDoc home;
50     int localId=0;
51     
52     public WorkerEnv() {
53         for( int i=0; i<noteId.length; i++ ) {
54             noteId[i]=7;
55             noteName[i]=new String JavaDoc[20];
56         }
57     }
58
59     public void setLocalId(int id) {
60         localId=id;
61     }
62     
63     public int getLocalId() {
64         return localId;
65     }
66     
67     public void setJkHome( String JavaDoc s ) {
68         home=s;
69     }
70
71     public String JavaDoc getJkHome() {
72         return home;
73     }
74     
75     public final Object JavaDoc getNote(int i ) {
76         return notes[i];
77     }
78
79     public final void setNote(int i, Object JavaDoc o ) {
80         notes[i]=o;
81     }
82
83     public int getNoteId( int type, String JavaDoc name ) {
84         for( int i=0; i<noteId[type]; i++ ) {
85             if( name.equals( noteName[type][i] ))
86                 return i;
87         }
88         int id=noteId[type]++;
89         noteName[type][id]=name;
90         return id;
91     }
92
93     public void addHandler( String JavaDoc name, JkHandler w ) {
94         JkHandler oldH = getHandler(name);
95         if(oldH == w) {
96             // Already added
97
return;
98         }
99         w.setWorkerEnv( this );
100         w.setName( name );
101         handlersMap.put( name, w );
102         if( handlerCount > handlersTable.length ) {
103             JkHandler newT[]=new JkHandler[ 2 * handlersTable.length ];
104             System.arraycopy( handlersTable, 0, newT, 0, handlersTable.length );
105             handlersTable=newT;
106         }
107         if(oldH == null) {
108             handlersTable[handlerCount]=w;
109             w.setId( handlerCount );
110             handlerCount++;
111         } else {
112             handlersTable[oldH.getId()]=w;
113             w.setId(oldH.getId());
114         }
115
116         // Notify all other handlers of the new one
117
// XXX Could be a Coyote action ?
118
for( int i=0; i< handlerCount ; i++ ) {
119             handlersTable[i].addHandlerCallback( w );
120         }
121     }
122
123     public final JkHandler getHandler( String JavaDoc name ) {
124         return (JkHandler)handlersMap.get(name);
125     }
126
127     public final JkHandler getHandler( int id ) {
128         return handlersTable[id];
129     }
130
131     public final int getHandlerCount() {
132         return handlerCount;
133     }
134     
135     public ObjectName JavaDoc[] getHandlersObjectName() {
136         
137         ObjectName JavaDoc onames[]=new ObjectName JavaDoc[ handlerCount ];
138         for( int i=0; i<handlerCount; i++ ) {
139             onames[i]=handlersTable[i].getObjectName();
140         }
141         return onames;
142     }
143
144 }
145
Popular Tags