costin 01/07/12 23:04:35
Modified: src/share/org/apache/tomcat/core Context.java
ContextManager.java
Log:
Added back the context's name. It was removed during the initial refactoring,
as many apps used it in a wrong way ( it was not unique, but based only
on the path - and that created problems with virtual hosts ).
Now all internal apps (admin, etc ) are cleaned and know how to deal with
virtual hosts, and it is usefull to add back the method ( with a correct
behavior ).
Thanks Leong Mun Wai for reminding me that.
Revision Changes Path
1.145 +18 -2 jakarta-tomcat/src/share/org/apache/tomcat/core/Context.java
Index: Context.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Context.java,v
retrieving revision 1.144
retrieving revision 1.145
diff -u -r1.144 -r1.145
--- Context.java 2001/06/16 22:05:04 1.144
+++ Context.java 2001/07/13 06:04:28 1.145
@@ -532,7 +532,22 @@
// -------------------- Basic properties --------------------
+ String name;
+
+ /** Return a name ( id ) for this context. Currently it's composed
+ from the virtual host and path, or set explicitely by the app.
+ */
+ public String getName() {
+ if(name!=null ) return name;
+ name=(vhost==null ? "DEFAULT:" : vhost + ":" ) +
+ ("".equals(path) ? "/ROOT" : path);
+ return name;
+ }
+ public void setName( String s ) {
+ name=s;
+ }
+
/** Base URL for this context
*/
public final String getPath() {
@@ -549,6 +564,7 @@
this.path = path;
loghelper=Log.getLog("org/apache/tomcat/core",
"Ctx("+ getId() +") ");
+ name=null;
}
/**
@@ -557,6 +573,7 @@
*/
public final void setHost( String h ) {
vhost=h;
+ name=null;
}
/**
@@ -992,8 +1009,7 @@
}
public final String toString() {
- return (vhost==null ? "DEFAULT:" : vhost + ":" ) +
- ("".equals(path) ? "/ROOT" : path);
+ return getName();
}
// ------------------- Logging ---------------
1.183 +11 -0
jakarta-tomcat/src/share/org/apache/tomcat/core/ContextManager.java
Index: ContextManager.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ContextManager.java,v
retrieving revision 1.182
retrieving revision 1.183
diff -u -r1.182 -r1.183
--- ContextManager.java 2001/06/28 07:43:05 1.182
+++ ContextManager.java 2001/07/13 06:04:30 1.183
@@ -190,6 +190,7 @@
// All contexts managed by the server ( can belong to different
// virtual hosts )
private Vector contextsV=new Vector();
+ private Hashtable contexts=new Hashtable();
private int debug=0;
@@ -673,6 +674,14 @@
return contextsV.elements();
}
+ public final Enumeration getContextNames() {
+ return contexts.keys();
+ }
+
+ public Context getContext(String name ) {
+ return (Context)contexts.get( name );
+ }
+
/**
* Adds a new Context to the set managed by this ContextManager.
* It'll also init the server if it hasn't been already.
@@ -689,6 +698,7 @@
ctx.setState( Context.STATE_NEW );
contextsV.addElement( ctx );
+ contexts.put( ctx.getName(), ctx );
if( getState() == STATE_NEW )
return;
@@ -718,6 +728,7 @@
log( "Removing context " + context.toString());
contextsV.removeElement(context);
+ contexts.remove( context.getName());
if( getState() == STATE_NEW )
return; // we are not even initialized