You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by co...@locus.apache.org on 2000/02/13 02:43:42 UTC

cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/core Context.java ServletWrapper.java

costin      00/02/12 17:43:41

  Modified:    src/j2ee/org/apache/tomcat/deployment
                        WebApplicationReader.java
               src/share/org/apache/tomcat/core Context.java
                        ServletWrapper.java
  Log:
  Removed few more "old" methods from Context.
  ( old == used by j2ee; fixed j2ee to use the current methods )
  
  Revision  Changes    Path
  1.3       +58 -14    jakarta-tomcat/src/j2ee/org/apache/tomcat/deployment/WebApplicationReader.java
  
  Index: WebApplicationReader.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/j2ee/org/apache/tomcat/deployment/WebApplicationReader.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- WebApplicationReader.java	2000/02/13 01:16:16	1.2
  +++ WebApplicationReader.java	2000/02/13 01:43:40	1.3
  @@ -777,8 +777,8 @@
   	    if (webComponentDescriptor instanceof ServletDescriptor) {
   		resourceName =
   		    ((ServletDescriptor)webComponentDescriptor).getClassName();
  -
  -		if ( ctx.containsServletByName(name)) {
  +		
  +		if ( ctx.getServletByName(name) != null) {
   // 		    String msg = sm.getString("context.dd.dropServlet",
   // 					      name + "(" + resourceName + ")" );
   		    
  @@ -801,17 +801,31 @@
   		    resourceName = "/" + resourceName;
   		}
   
  -		if (ctx.containsJSP(resourceName)) {
  +		
  +		if (containsJSP(ctx, resourceName)) {
   // 		    String msg = sm.getString("context.dd.dropServlet",
   // 					      resourceName);
   
   // 		    System.out.println(msg);
   		    
   		    removeResource = true;
  -		    ctx.removeJSP(resourceName);
  +		    Enumeration enum = ctx.getServletNames();
  +		    while (enum.hasMoreElements()) {
  +			String key = (String)enum.nextElement();
  +			ServletWrapper sw = ctx.getServletByName(key);
  +			if(resourceName.equals( (sw).getPath())) {
  +			    ctx.removeServletByName( sw.getServletName() );
  +			}
  +		    }
   		}
   
  -		ctx.addJSP(name, resourceName, description);
  +		ServletWrapper wrapper = new ServletWrapper();
  +		wrapper.setContext(ctx);
  +		wrapper.setServletName(name);
  +		wrapper.setServletDescription(description);
  +		wrapper.setPath(resourceName);
  +
  +		ctx.addServlet(wrapper);
   	    }
   
   
  @@ -827,19 +841,20 @@
   
   	    Enumeration enum =
   	        webComponentDescriptor.getInitializationParameters();
  -	    Hashtable initializationParameters = new Hashtable();
  +
  +	    String cName=webComponentDescriptor.getCanonicalName();
  +	    ServletWrapper sw=ctx.getServletByName( cName );
   
   	    while (enum.hasMoreElements()) {
   	        InitializationParameter initializationParameter =
   		    (InitializationParameter)enum.nextElement();
   
  -		initializationParameters.put(
  -		    initializationParameter.getName(),
  -		    initializationParameter.getValue());
  +		if (sw != null) {
  +		    sw.addInitParam(initializationParameter.getName(),
  +				    initializationParameter.getValue());
  +		}
   	    }
   
  -	    ctx.setServletInitParams( webComponentDescriptor.getCanonicalName(),
  -				 initializationParameters);
   
   	    enum = webComponentDescriptor.getUrlPatterns();
   
  @@ -851,9 +866,9 @@
   		    mapping = "/" + mapping;
   		}
   
  -		if (! ctx.containsServlet(mapping) &&
  -		    ! ctx.containsJSP(mapping)) {
  -		    if (ctx.containsMapping(mapping)) {
  +		if (! containsServlet(ctx, mapping) &&
  +		    ! containsJSP(ctx, mapping)) {
  +		    if (ctx.getServletMapping(mapping)!=null) {
   // 		        String msg = sm.getString("context.dd.dropMapping",
   // 			    mapping);
   
  @@ -907,4 +922,33 @@
   	    ctx.addErrorPage(key, errorPageDescriptor.getLocation());
   	}
       }
  +
  +    private boolean containsJSP( Context ctx, String path) {
  +	Enumeration enum = ctx.getServletNames();
  +
  +	while (enum.hasMoreElements()) {
  +	    String key = (String)enum.nextElement();
  +	    ServletWrapper sw = ctx.getServletByName(key);
  +
  +	    if( path.equals( (sw).getPath()))
  +		return true;
  +	}
  +	return false;
  +    }
  +
  +    
  +    /** True if we have a servlet with className.
  +     */
  +    public boolean containsServlet(Context ctx, String className) {
  +	Enumeration enum = ctx.getServletNames();
  +
  +	while (enum.hasMoreElements()) {
  +	    String key = (String)enum.nextElement();
  +	    ServletWrapper sw = ctx.getServletByName(key);
  +            if (className.equals(sw.getServletClass()))
  +	        return true;
  +	}
  +	return false;
  +    }
  +
   }
  
  
  
  1.52      +7 -94     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.51
  retrieving revision 1.52
  diff -u -r1.51 -r1.52
  --- Context.java	2000/02/13 01:16:18	1.51
  +++ Context.java	2000/02/13 01:43:41	1.52
  @@ -707,44 +707,6 @@
   
       // --------------------
   
  -    
  -    /** Add a jsp to the "pre-defined" list ( used by web.xml )
  -     *  @deprecated Create a Wrapper and use add Servlet 
  -     */
  -    public void addJSP(String name, String path, String description) {
  -        // XXX
  -        // check for duplicates!
  -
  -	//        JspWrapper wrapper = new JspWrapper(this);
  -	ServletWrapper wrapper = new ServletWrapper(this);
  -
  -	wrapper.setServletName(name);
  -	wrapper.setServletDescription(description);
  -	wrapper.setPath(path);
  -
  -	servlets.put(name, wrapper);
  -    }
  -
  -    /** True if we have a servlet with className.
  -     */
  -    public boolean containsServlet(String className) {
  -	Enumeration enum = servlets.keys();
  -	while (enum.hasMoreElements()) {
  -	    String key = (String)enum.nextElement();
  -	    ServletWrapper sw = (ServletWrapper)servlets.get(key);
  -            if (className.equals(sw.getServletClass()))
  -	        return true;
  -	}
  -	return false;
  -    }
  -
  -    /** Check if we have a servlet with the specified name
  -     */
  -    public boolean containsServletByName(String name) {
  -	return (servlets.containsKey(name));
  -    }
  -
  -    // XXX use external iterator 
       /** Remove all servlets with a specific class name
        */
       void removeServletByClassName(String className)
  @@ -772,52 +734,7 @@
   	}
       }
   
  -    /** @deprecated use getServletByPath or getJsp
  -     */
  -    public boolean containsJSP(String path) {
  -	Enumeration enum = servlets.keys();
  -
  -	while (enum.hasMoreElements()) {
  -	    String key = (String)enum.nextElement();
  -	    ServletWrapper sw = (ServletWrapper)servlets.get(key);
  -
  -	    //	    if( (sw instanceof JspWrapper ) &&
  -	    if( path.equals( (sw).getPath()))
  -		return true;
  -	}
  -	return false;
  -    }
  -
  -    /** Will remove a JSP from the list of "declared" jsps.
  -     *  Called only by deployment descriptor - to deal with
  -     *  duplicated mappings -
  -     *  XXX Find out if we really need that - it can be avoided!
  -     * @deprecated Use removeServlet and findServletByPath or ByName
  -     */
  -    public void removeJSP(String path)
  -	throws TomcatException
  -    {
  -	Enumeration enum = servlets.keys();
  -	while (enum.hasMoreElements()) {
  -	    String key = (String)enum.nextElement();
  -	    ServletWrapper sw = (ServletWrapper)servlets.get(key);
  -	    //	    if( (sw instanceof JspWrapper ) &&
  -	    if(path.equals( (sw).getPath())) {
  -		servlets.remove( sw.getServletName() );
  -		contextM.removeServlet( this, sw );
  -	    }
  -	}
  -    }
  -
  -    /** @deprecated use the method of servletWrapper
  -     */
  -    public void setServletInitParams(String name, Hashtable initParams) {
  -	ServletWrapper wrapper = (ServletWrapper)servlets.get(name);
  -	if (wrapper != null) {
  -	    wrapper.setInitArgs(initParams);
  -	}
  -    }
  -
  +    // -------------------- Mappings
       
       /**
        * Maps a named servlet to a particular path or extension.
  @@ -866,8 +783,9 @@
   	return mappings.keys();
       }
   
  -    public ServletWrapper getServletMapping( String path ) {
  -	return (ServletWrapper)mappings.get(path);
  +    public ServletWrapper getServletMapping( String mapping ) {
  +        mapping = mapping.trim();
  +	return (ServletWrapper)mappings.get(mapping);
       }
   
       public void removeMapping( String path ) {
  @@ -887,9 +805,7 @@
   	    }
   	}
       }
  -    
  -    // -------------------- deprecated code
  -    
  +
       public ServletWrapper getDefaultServlet() {
   	if( defaultServlet==null)
   	    defaultServlet=getServletByName(Constants.DEFAULT_SERVLET_NAME );
  @@ -898,12 +814,9 @@
   	
   	return defaultServlet;
       }
  -    
  -    public boolean containsMapping(String mapping) {
  -        mapping = mapping.trim();
  -	return mappings.containsKey( mapping );
  -    }
   
  +    // -------------------- Servlets management --------------------
  +    
       public ServletWrapper getServletByName(String servletName) {
   	return (ServletWrapper)servlets.get(servletName);
       }
  
  
  
  1.23      +3 -9      jakarta-tomcat/src/share/org/apache/tomcat/core/ServletWrapper.java
  
  Index: ServletWrapper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ServletWrapper.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- ServletWrapper.java	2000/02/12 03:38:50	1.22
  +++ ServletWrapper.java	2000/02/13 01:43:41	1.23
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ServletWrapper.java,v 1.22 2000/02/12 03:38:50 costin Exp $
  - * $Revision: 1.22 $
  - * $Date: 2000/02/12 03:38:50 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ServletWrapper.java,v 1.23 2000/02/13 01:43:41 costin Exp $
  + * $Revision: 1.23 $
  + * $Date: 2000/02/13 01:43:41 $
    *
    * ====================================================================
    *
  @@ -210,12 +210,6 @@
   	initArgs.put( name, value );
       }
       
  -    /** @deprecated
  -     */
  -    void setInitArgs(Hashtable initArgs) {
  -        config.setInitArgs(initArgs);
  -    }
  -
       void destroy() {
   	if (servlet != null) {
   	    synchronized (this) {