"Craig R. McClanahan" <[EMAIL PROTECTED]> writes:

> I'd certainly be interested in a patch to allow pattern matching in the
> host mapper, as long as the code was smart about using direct string
> compares when no patterns are specified (to avoid slowing down all
> requests by regexp processing).

Since "." is a regex character, there is no way to automatically infer
whether an alias string is a pattern or a literal, meaning that a way
to communicate to the Mapper implementations which aliases are
patterns is required.  Because of this, I don't believe that it is
possible to avoid minor API/server.xml additions/changes.

The cleanest implementation route I see for addition of pattern
matching is to solidfy an existing data type (Alias) as an interface
accompanied by standard implementation.  The suggested syntax would be
as follows:

<Host ...>
  <Alias isPattern="true">.*domain.com</Alias>
  <!-- An Alias element is not a pattern by default -->
  <Alias>www.otherdomain.com</Alias>
</Host>

I haven't previously used Digester, Modeler, or BeanUtils, so am
unsure of what changes to make to mbeans-descriptors.xml and
HostRuleSet.java (I definitely screwed up the declaration for Alias).

> Note that Tomcat already loads jakarta-regexp for use in the
> RemoteAddrValve and RemoteHostValve filters.  If you need regexp patterns,
> that would be a convenient choice because no additional dependencies would
> be created.

Gotcha -- I used RE.match() in the style of RequestFilterValve.

Here's an incomplete version of the modifications to solicit feedback,
and make sure I'm following the desired path:


Index: src/share/org/apache/catalina/Alias.java
===================================================================
RCS file: Alias.java
diff -N Alias.java
--- /dev/null   Fri Nov 30 17:57:31 2001
+++ Alias.java  Fri Nov 30 17:59:22 2001
@@ -0,0 +1,128 @@
+/*
+ * $Header: 
+/home/cvspublic/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/Host.java,v 
+1.7 2001/10/22 04:48:56 remm Exp $
+ * $Revision: 1.7 $
+ * $Date: 2001/10/22 04:48:56 $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
+ *    Foundation" must not be used to endorse or promote products derived
+ *    from this software without prior written permission. For written
+ *    permission, please contact [EMAIL PROTECTED]
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ *    nor may "Apache" appear in their names without prior written
+ *    permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+
+package org.apache.catalina;
+
+
+import javax.servlet.ServletContext;
+
+/**
+ * An <code>Alias</code> defines a mapping from a host name used in a
+ * request to a <b>Host</b> object from server.xml.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]";>Daniel Rall</a>
+ * @version $Revision: $ $Date: $
+ */
+
+public interface Alias {
+
+
+    // ------------------------------------------------------------- Properties
+
+
+    /**
+     * Returns the host alias name or pattern.
+     *
+     * @return Alias for the containing Host.
+     */
+    public String getMapping();
+
+
+    /**
+     * Sets the host alias name or pattern.
+     *
+     * @param alias Alias for the containing Host.
+     */
+    public void setMapping(String alias);
+
+
+    /**
+     * Returns whether this mapping uses pattern matching.
+     * <code>false</code> by default.
+     *
+     * @return Whether name should be pattern matched.
+     */
+    public boolean isPattern();
+
+
+    /**
+     * Sets whether this mapping uses pattern matching.
+     *
+     * @param isPattern Whether name should be pattern matched.
+     */
+    public void setPattern(boolean isPattern);
+
+
+    // ---------------------------------------------------------------- Methods
+
+
+    /**
+     * Matches the provided Host name against this Alias.
+     *
+     * @param serverName The name used in a request to access the web
+     * server which will be mapped to a particular Host.
+     * @return Whether this Alias matches the supplied name.
+     */
+    public boolean match(String serverName);
+
+
+}
Index: src/share/org/apache/catalina/Host.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/Host.java,v
retrieving revision 1.7
diff -u -r1.7 Host.java
--- src/share/org/apache/catalina/Host.java     2001/10/22 04:48:56     1.7
+++ src/share/org/apache/catalina/Host.java     2001/12/01 01:59:23
@@ -186,18 +186,18 @@
 
 
     /**
-     * Add an alias name that should be mapped to this same Host.
+     * Add an Alias that should be mapped to this same Host.
      *
-     * @param alias The alias to be added
+     * @param alias The Alias to be added.
      */
-    public void addAlias(String alias);
+    public void addAlias(Alias alias);
 
 
     /**
      * Return the set of alias names for this Host.  If none are defined,
      * a zero length array is returned.
      */
-    public String[] findAliases();
+    public Alias[] findAliases();
 
 
     /**
@@ -214,7 +214,7 @@
      *
      * @param alias Alias name to be removed
      */
-    public void removeAlias(String alias);
+    public void removeAlias(Alias alias);
 
 
 }
Index: src/share/org/apache/catalina/core/FastEngineMapper.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/FastEngineMapper.java,v
retrieving revision 1.3
diff -u -r1.3 FastEngineMapper.java
--- src/share/org/apache/catalina/core/FastEngineMapper.java    2001/11/09 19:39:11    
 1.3
+++ src/share/org/apache/catalina/core/FastEngineMapper.java    2001/12/01 01:59:28
@@ -68,7 +68,10 @@
 import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.Iterator;
+import org.apache.commons.collections.FastHashMap;
+import org.apache.catalina.Alias;
 import org.apache.catalina.Container;
 import org.apache.catalina.ContainerEvent;
 import org.apache.catalina.ContainerListener;
@@ -104,12 +107,18 @@
 
 
     /**
-     * Cache of hostname -> Host mappings.  FIXME - use FastHashMap.
+     * Cache of lowercased hostname -> Host mappings.
      */
-    private java.util.HashMap cache = new java.util.HashMap();
+    private HashMap cache = new FastHashMap();
 
 
     /**
+     * Cache of Alias -> Host mappings.
+     */
+    private HashMap patterns = new HashMap();
+
+
+    /**
      * The default host used for unknown host names.
      */
     private Host defaultHost = null;
@@ -235,14 +244,14 @@
         // Find the specified host in our cache
         if (debug >= 2)
             engine.log(" Trying a cache match");
-        Host host = (Host) cache.get(server);
+        Host host = findHost(server);
 
         // Map to the default host if any
         if ((host == null) && (defaultHost != null)) {
             if (debug >= 2)
                 engine.log(" Mapping to default host");
             host = defaultHost;
-            addAlias(server, host);
+            addAlias(new StandardAlias(server), host);
         }
 
         // Update the Request if requested, and return the selected Host
@@ -271,7 +280,8 @@
                 removeHost((Host) event.getData());
         } else if (source instanceof Host) {
             if (Host.ADD_ALIAS_EVENT.equals(type))
-                addAlias((String) event.getData(), (Host) source);
+                addAlias(new StandardAlias((String) event.getData()),
+                         (Host) source);
             else if (Host.REMOVE_ALIAS_EVENT.equals(type))
                 removeAlias((String) event.getData());
         }
@@ -404,15 +414,18 @@
     /**
      * Add an alias for the specified host.
      *
-     * @param alias New alias name
+     * @param alias New alias to map
      * @param host Host to resolve to
      */
-    private void addAlias(String alias, Host host) {
+    private void addAlias(Alias alias, Host host) {
 
         if (debug >= 3)
             engine.log("Adding alias '" + alias + "' for host '" +
                        host.getName() + "'");
-        cache.put(alias.toLowerCase(), host);
+        if (alias.isPattern())
+            patterns.put(alias, host);
+        else
+            cache.put(alias.getMapping().toLowerCase(), host);
 
     }
 
@@ -430,10 +443,10 @@
         host.addContainerListener(this);
 
         // Register the host name
-        addAlias(host.getName(), host);
+        addAlias(new StandardAlias(host.getName()), host);
 
         // Register all associated aliases
-        String aliases[] = host.findAliases();
+        Alias aliases[] = host.findAliases();
         for (int i = 0; i < aliases.length; i++)
             addAlias(aliases[i], host);
 
@@ -448,21 +461,42 @@
      */
     private Host findHost(String name) {
 
-        return ((Host) cache.get(name.toLowerCase()));
+        name = name.toLowerCase();
+        Host host = (Host) cache.get(name);
+        if (host == null && !patterns.isEmpty()) {
+            Alias alias;
+            for (Iterator i = patterns.keySet().iterator(); i.hasNext(); ) {
+                alias = (Alias) i.next();
+                if (alias.match(name)) {
+                    // Host found -- cache pattern match result
+                    host = (Host) patterns.get(alias);
+                    addAlias(new StandardAlias(name), host);
+                }
+            }
+        }
+        return (host);
 
     }
 
 
     /**
-     * Remove the specified alias from our cache.
+     * Remove the specified alias from our name and pattern caches.
      *
-     * @param alias Alias to remove
+     * @param alias Alias to remove (either a String or Alias).
      */
-    private void removeAlias(String alias) {
+    private void removeAlias(Object alias) {
 
         if (debug >= 3)
             engine.log("Removing alias '" + alias + "'");
-        cache.remove(alias.toLowerCase());
+        if (alias instanceof String) {
+            cache.remove(((String) alias).toLowerCase());
+        } else if (alias instanceof Alias) {
+            patterns.remove(alias);
+        } else {
+            throw new IllegalArgumentException
+                // FIXME: Localize error text
+                ("Uknown alias type: " + alias.getClass().getName());
+        }
 
     }
 
@@ -479,19 +513,27 @@
 
         host.removeContainerListener(this);
 
-        // Identify all names mapped to this host
+        // Identify all name and pattern aliases mapped to this host
         ArrayList removes = new ArrayList();
         Iterator keys = cache.keySet().iterator();
+        Object key;
         while (keys.hasNext()) {
-            String key = (String) keys.next();
+            key = keys.next();
             if (host.equals((Host) cache.get(key)))
                 removes.add(key);
         }
+        keys = patterns.keySet().iterator();
+        while (keys.hasNext()) {
+            key = keys.next();
+            if (host.equals((Host) patterns.get(key)))
+                removes.add(key);
+        }
 
-        // Remove the associated names
+        // Remove the associated name and pattern aliases
         keys = removes.iterator();
         while (keys.hasNext()) {
-            removeAlias((String) keys.next());
+            key = keys.next();
+            removeAlias(key);
         }
 
     }
Index: src/share/org/apache/catalina/core/StandardAlias.java
===================================================================
RCS file: StandardAlias.java
diff -N StandardAlias.java
--- /dev/null   Fri Nov 30 17:57:31 2001
+++ StandardAlias.java  Fri Nov 30 17:59:28 2001
@@ -0,0 +1,244 @@
+/*
+ * $Header: 
+/home/cvspublic/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardHost.java,v
+ 1.22 2001/10/25 00:23:02 craigmcc Exp $
+ * $Revision: 1.22 $
+ * $Date: 2001/10/25 00:23:02 $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
+ *    Foundation" must not be used to endorse or promote products derived
+ *    from this software without prior written permission. For written
+ *    permission, please contact [EMAIL PROTECTED]
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ *    nor may "Apache" appear in their names without prior written
+ *    permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ * [Additional notices, if required by prior licensing conditions]
+ *
+ */
+
+
+package org.apache.catalina.core;
+
+
+import org.apache.regexp.RE;
+import org.apache.regexp.RESyntaxException;
+import org.apache.catalina.Alias;
+
+
+/**
+ * Standard implementation of the <code>Alias</code> interface, which
+ * defines a mapping from a host name used in a request to a
+ * <b>Host</b> object from server.xml.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]";>Daniel Rall</a>
+ * @version $Revision: $ $Date: $
+ */
+
+public class StandardAlias
+    implements Alias {
+
+
+    // ----------------------------------------------------------- Constructors
+
+
+    /**
+     * Create a new StandardAlias with an empty name mapping.
+     */
+    public StandardAlias() {
+
+        this("");
+
+    }
+
+
+    /**
+     * Create a new StandardAlias with the supplied name mapping.
+     */
+    protected StandardAlias(String mapping) {
+
+        setMapping(mapping);
+
+    }
+
+
+    // ----------------------------------------------------- Instance Variables
+
+
+    /**
+     * The alias name or pattern.
+     */
+    private String mapping;
+
+
+    /**
+     * A compiled regular expression to use for pattern matching.
+     */
+    private RE re;
+
+
+    /**
+     * The pattern matching flag for this Alias.
+     */
+    private boolean isPattern = false;
+
+
+    // ------------------------------------------------------------- Properties
+
+
+    /**
+     * @see org.apache.catalina.Alias#getMapping()
+     */
+    public String getMapping() {
+
+        return (this.mapping);
+
+    }
+
+
+    /**
+     * @see org.apache.catalina.Alias#setMapping(String)
+     */
+    public void setMapping(String mapping) {
+
+        this.mapping = mapping;
+        this.re = null;
+
+    }
+
+
+    /**
+     * @see org.apache.catalina.Alias#isPattern()
+     */
+    public boolean isPattern() {
+
+        return (this.isPattern);
+
+    }
+
+
+    /**
+     * @see org.apache.catalina.Alias#setPattern(boolean)
+     */
+    public void setPattern(boolean isPattern) {
+
+        this.isPattern = isPattern;
+        this.re = null;
+
+    }
+
+
+    // ---------------------------------------------------------------- Methods
+
+
+    /**
+     * Matches the provided Host name against this Alias.
+     *
+     * @param serverName The name used in a request to access the web
+     * server which will be mapped to a particular Host.
+     * @return Whether this Alias matches the supplied name.
+     * @exception IllegalArgumentException If one of the pattern has
+     * invalid syntax.
+     */
+    public boolean match(String serverName) {
+
+        if (mapping == null)
+            return false;
+
+        if (isPattern) {
+            if (re == null)
+                try {
+                    re = new RE(mapping, RE.MATCH_CASEINDEPENDENT);
+                } catch (RESyntaxException e) {
+                    // FIXME: Localize error text
+                    throw new IllegalArgumentException
+                        ("Invalid regexp pattern: " + mapping);
+                }
+            return re.match(serverName);
+        } else {
+            return mapping.equalsIgnoreCase(serverName);
+        }
+
+    }
+
+
+    public boolean equals(Object alias) {
+
+        if (this == alias) {
+            return true;
+        }
+
+        if (alias != null && alias instanceof Alias) {
+            boolean mappingEqual = false;
+            Alias a = (Alias) alias;
+            if (mapping != null) {
+                mappingEqual = mapping.equals(a.getMapping());
+            } else {
+                mappingEqual = (a.getMapping() == null);
+            }
+            return (mappingEqual && isPattern == a.isPattern());
+        }
+        return false;
+
+    }
+
+
+    public int hashCode() {
+
+        return (mapping != null ? mapping.hashCode() : "".hashCode());
+
+    }
+
+
+    public final String toString() {
+
+        return getMapping();
+
+    }
+
+
+}
Index: src/share/org/apache/catalina/core/StandardEngineMapper.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardEngineMapper.java,v
retrieving revision 1.5
diff -u -r1.5 StandardEngineMapper.java
--- src/share/org/apache/catalina/core/StandardEngineMapper.java        2001/07/22 
20:25:08     1.5
+++ src/share/org/apache/catalina/core/StandardEngineMapper.java        2001/12/01 
+01:59:29
@@ -65,6 +65,7 @@
 package org.apache.catalina.core;
 
 
+import org.apache.catalina.Alias;
 import org.apache.catalina.Container;
 import org.apache.catalina.Engine;
 import org.apache.catalina.Host;
@@ -203,9 +204,9 @@
                 engine.log(" Trying an alias match");
             Container children[] = engine.findChildren();
             for (int i = 0; i < children.length; i++) {
-                String aliases[] = ((Host) children[i]).findAliases();
+                Alias aliases[] = ((Host) children[i]).findAliases();
                 for (int j = 0; j < aliases.length; j++) {
-                    if (server.equals(aliases[j])) {
+                    if (aliases[j].match(server)) {
                         host = (Host) children[i];
                         break;
                     }
Index: src/share/org/apache/catalina/core/StandardHost.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardHost.java,v
retrieving revision 1.22
diff -u -r1.22 StandardHost.java
--- src/share/org/apache/catalina/core/StandardHost.java        2001/10/25 00:23:02    
 1.22
+++ src/share/org/apache/catalina/core/StandardHost.java        2001/12/01 01:59:30
@@ -72,6 +72,7 @@
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import org.apache.catalina.Alias;
 import org.apache.catalina.Container;
 import org.apache.catalina.Context;
 import org.apache.catalina.DefaultContext;
@@ -123,7 +124,7 @@
     /**
      * The set of aliases for this Host.
      */
-    private String[] aliases = new String[0];
+    private Alias[] aliases = new Alias[0];
 
 
     /**
@@ -443,14 +444,13 @@
 
     }
 
+
     /**
-     * Add an alias name that should be mapped to this same Host.
+     * Add an Alias that should be mapped to this same Host.
      *
-     * @param alias The alias to be added
+     * @param alias The Alias to be added.
      */
-    public void addAlias(String alias) {
-
-        alias = alias.toLowerCase();
+    public void addAlias(Alias alias) {
 
         // Skip duplicate aliases
         for (int i = 0; i < aliases.length; i++) {
@@ -459,7 +459,7 @@
         }
 
         // Add this alias to the list
-        String newAliases[] = new String[aliases.length + 1];
+        Alias newAliases[] = new Alias[aliases.length + 1];
         for (int i = 0; i < aliases.length; i++)
             newAliases[i] = aliases[i];
         newAliases[aliases.length] = alias;
@@ -492,7 +492,7 @@
      * Return the set of alias names for this Host.  If none are defined,
      * a zero length array is returned.
      */
-    public String[] findAliases() {
+    public Alias[] findAliases() {
 
         return (this.aliases);
 
@@ -564,9 +564,7 @@
      *
      * @param alias Alias name to be removed
      */
-    public void removeAlias(String alias) {
-
-        alias = alias.toLowerCase();
+    public void removeAlias(Alias alias) {
 
         synchronized (aliases) {
 
@@ -583,7 +581,7 @@
 
             // Remove the specified alias
             int j = 0;
-            String results[] = new String[aliases.length - 1];
+            Alias results[] = new Alias[aliases.length - 1];
             for (int i = 0; i < aliases.length; i++) {
                 if (i != n)
                     results[j++] = aliases[i];
Index: src/share/org/apache/catalina/mbeans/AliasMBean.java
===================================================================
RCS file: AliasMBean.java
diff -N AliasMBean.java
--- /dev/null   Fri Nov 30 17:57:31 2001
+++ AliasMBean.java     Fri Nov 30 17:59:31 2001
@@ -0,0 +1,122 @@
+/*
+ * $Header: 
+/home/cvspublic/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/ManagerMBean.java,v
+ 1.1 2001/11/07 01:36:36 amyroh Exp $
+ * $Revision: 1.1 $
+ * $Date: 2001/11/07 01:36:36 $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999 The Apache Software Foundation.  All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
+ *    Foundation" must not be used to endorse or promote products derived
+ *    from this software without prior written permission. For written
+ *    permission, please contact [EMAIL PROTECTED]
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ *    nor may "Apache" appear in their names without prior written
+ *    permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ * [Additional notices, if required by prior licensing conditions]
+ *
+ */
+
+package org.apache.catalina.mbeans;
+
+
+import javax.management.MBeanException;
+import javax.management.RuntimeOperationsException;
+import org.apache.catalina.Host;
+import org.apache.catalina.Alias;
+import org.apache.commons.modeler.BaseModelMBean;
+
+
+/**
+ * <p>A <strong>ModelMBean</strong> implementation for the
+ * <code>org.apache.catalina.Alias</code> component.</p>
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]";>Daniel Rall</a>
+ * @version $Revision: $ $Date: $
+ */
+
+public class AliasMBean extends BaseModelMBean {
+
+
+    // ----------------------------------------------------------- Constructors
+
+
+    /**
+     * Construct a <code>ModelMBean</code> with default
+     * <code>ModelMBeanInfo</code> information.
+     *
+     * @exception MBeanException if the initializer of an object
+     *  throws an exception
+     * @exception RuntimeOperationsException if an IllegalArgumentException
+     *  occurs
+     */
+    public AliasMBean()
+        throws MBeanException, RuntimeOperationsException {
+
+        super();
+
+    }
+
+
+    // ------------------------------------------------------------- Attributes
+
+
+    /**
+     * Return the parent (Host) that owns this Alias.
+     * HELP: Not sure if this is necessary for Alias.
+     */
+    public Host getParent() {
+
+        if (this.resource == null)
+            return (null);
+        Host host = (Host) this.resource;
+        return (host.getParent());
+
+    }
+
+
+}
Index: src/share/org/apache/catalina/mbeans/mbeans-descriptors.xml
===================================================================
RCS file: 
/home/cvspublic/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/mbeans-descriptors.xml,v
retrieving revision 1.12
diff -u -r1.12 mbeans-descriptors.xml
--- src/share/org/apache/catalina/mbeans/mbeans-descriptors.xml 2001/11/15 02:03:08    
 1.12
+++ src/share/org/apache/catalina/mbeans/mbeans-descriptors.xml 2001/12/01 01:59:34
@@ -821,21 +821,21 @@
            returnType="void">
       <parameter name="alias"
           description="The alias to be added"
-                 type="java.lang.String"/>
+                 type="org.apache.catalina.Alias"/>
     </operation>
 
     <operation   name="findAliases"
           description="Return the set of alias names for this Host"
                impact="INFO"
-           returnType="java.lang.String[]"/>
+           returnType="org.apache.catalina.Alias[]"/>
 
     <operation   name="removeAlias"
           description="Remove the specified alias name from the aliases for this Host"
                impact="ACTION"
            returnType="void">
       <parameter name="alias"
-          description="Alias name to be removed"
-                 type="java.lang.String"/>
+          description="Alias to be removed"
+                 type="org.apache.catalina.Alias"/>
     </operation>
 
     <operation   name="addChild"
@@ -883,6 +883,26 @@
           description="Valve to be removed"
                  type="org.apache.catalina.Valve"/>
     </operation>
+
+  </mbean>
+
+
+  <mbean         name="StandardAlias"
+            className="org.apache.catalina.mbeans.AliasMBean"
+          description="Standard implementation of the Alias interface"
+               domain="Catalina"
+                group="Manager"
+                 type="org.apache.catalina.session.StandardManager">
+
+    <attribute   name="mapping"
+          description="The alias name or pattern"
+                 type="java.lang.String"/>
+
+    <attribute   name="pattern"
+          description="Whether the alias is a pattern"
+                 type="boolean"/>
+
+    <constructor name="StandardAlias"/>
 
   </mbean>
 
Index: src/share/org/apache/catalina/startup/HostRuleSet.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/HostRuleSet.java,v
retrieving revision 1.2
diff -u -r1.2 HostRuleSet.java
--- src/share/org/apache/catalina/startup/HostRuleSet.java      2001/11/11 19:58:35    
 1.2
+++ src/share/org/apache/catalina/startup/HostRuleSet.java      2001/12/01 01:59:35
@@ -149,8 +149,16 @@
                             "addChild",
                             "org.apache.catalina.Container");
 
-        digester.addCallMethod(prefix + "Host/Alias",
-                               "addAlias", 0);
+        // FIXME: Rather than having <Alias>...</Alias>, we now have
+        // <Alias pattern="true">...</Alias> -- 2 params
+//         digester.addCallMethod(prefix + "Host/Alias",
+//                                "addAlias", 0);
+        digester.addObjectCreate(prefix + "Host/Alias",
+                                 "org.apache.catalina.core.StandardContext");
+        digester.addSetProperties(prefix + "Host/Alias");
+        digester.addSetNext(prefix + "Host/Alias",
+                            "addAlias",
+                            "org.apache.catalina.Alias");
 
         digester.addObjectCreate(prefix + "Host/Cluster",
                                  null, // MUST be specified in the element

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to