Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed to the Apache Software Foundation (ASF) under one or more
   * contributor license agreements.  See the NOTICE file distributed with
   * this work for additional information regarding copyright ownership.
   * The ASF licenses this file to You under the Apache License, Version 2.0
   * (the "License"); you may not use this file except in compliance with
   * the License.  You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
  * 
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 
 package org.apache.catalina.core;
 
 
 import static org.jboss.web.CatalinaMessages.MESSAGES;
 
 
 
Standard implementation of the Host interface. Each child container must be a Context implementation to process the requests directed to a particular web application.

Author(s):
Craig R. McClanahan
Remy Maucherat
Version:
$Revision: 1686 $ $Date: 2011-03-23 17:54:28 +0100 (Wed, 23 Mar 2011) $
 
 
 public class StandardHost
     extends ContainerBase
     implements Host  
  {
     
     // ----------------------------------------------------------- Constructors
 

    
Create a new StandardHost component with the default basic Valve.
 
     public StandardHost() {
 
         super();
         .setBasic(new StandardHostValve());
          = 
             Boolean.valueOf(System.getProperty("org.apache.catalina.core.StandardHost.startChildren""false")).booleanValue();
 
     }
 
 
     // ----------------------------------------------------- Instance Variables
 

    
The set of aliases for this Host.
 
     private String[] aliases = new String[0];


    
The application root for this Host.
 
     private String appBase = ".";


    
The default webapp name.
 
     private String defaultWebapp = "ROOT";


    
The Java class name of the default context configuration class for deployed web applications.
 
     private String configClass =
         System.getProperty("org.apache.catalina.core.StandardHost.configClass"null);


    
The Java class name of the default Context implementation class for deployed web applications.
    private String contextClass =
        "org.apache.catalina.core.StandardContext";


    
The Java class name of the default error reporter implementation class for deployed web applications.
    private String errorReportValveClass =
        "org.apache.catalina.valves.ErrorReportValve";

    
The object name for the errorReportValve.
    private ObjectName errorReportValveObjectName = null;

    
The descriptive information string for this implementation.
    private static final String info =
        "org.apache.catalina.core.StandardHost/1.0";


    
Work Directory base for applications.
    private String workDir = null;
    // ------------------------------------------------------------- Properties


    
Return the application root for this Host. This can be an absolute pathname, a relative pathname, or a URL.
    public String getAppBase() {
        return (this.);
    }


    
Set the application root for this Host. This can be an absolute pathname, a relative pathname, or a URL.

Parameters:
appBase The new application root
    public void setAppBase(String appBase) {
        String oldAppBase = this.;
        this. = appBase;
        .firePropertyChange("appBase"oldAppBasethis.);
    }
    public String getDefaultWebapp() {
        return (this.);
    }
    public void setDefaultWebapp(String defaultWebapp) {
        String oldDefaultWebapp = this.;
        this. = defaultWebapp;
        .firePropertyChange("defaultWebapp"oldDefaultWebappthis.);
    }


    
Return the Java class name of the context configuration class for new web applications.
    public String getConfigClass() {
        return (this.);
    }


    
Set the Java class name of the context configuration class for new web applications.

Parameters:
configClass The new context configuration class
    public void setConfigClass(String configClass) {
        String oldConfigClass = this.;
        this. = configClass;
        .firePropertyChange("configClass",
                                   oldConfigClassthis.);
    }


    
Return the Java class name of the Context implementation class for new web applications.
    public String getContextClass() {
        return (this.);
    }


    
Set the Java class name of the Context implementation class for new web applications.

Parameters:
contextClass The new context implementation class
    public void setContextClass(String contextClass) {
        String oldContextClass = this.;
        this. = contextClass;
        .firePropertyChange("contextClass",
                                   oldContextClassthis.);
    }


    
Return the Java class name of the error report valve class for new web applications.
    public String getErrorReportValveClass() {
        return (this.);
    }


    
Set the Java class name of the error report valve class for new web applications.

Parameters:
errorReportValveClass The new error report valve class
    public void setErrorReportValveClass(String errorReportValveClass) {
        String oldErrorReportValveClassClass = this.;
        this. = errorReportValveClass;
        .firePropertyChange("errorReportValveClass",
                                   oldErrorReportValveClassClass
                                   this.);
    }


    
Return the canonical, fully qualified, name of the virtual host this Container represents.
    public String getName() {
        return ();
    }


    
Set the canonical, fully qualified, name of the virtual host this Container represents.

Parameters:
name Virtual host name
Throws:
java.lang.IllegalArgumentException if name is null
    public void setName(String name) {
        if (name == null)
            throw .hostNameIsNull();
        name = name.toLowerCase(.);      // Internally all names are lower case
        String oldName = this.;
        this. = name;
        .firePropertyChange("name"oldNamethis.);
    }


    
Host work directory base.
    public String getWorkDir() {
        return ();
    }


    
Host work directory base.
    public void setWorkDir(String workDir) {
        this. = workDir;
    }
    // --------------------------------------------------------- Public Methods


    
Add an alias name that should be mapped to this same Host.

Parameters:
alias The alias to be added
    public void addAlias(String alias) {
        alias = alias.toLowerCase(.);
        // Skip duplicate aliases
        for (int i = 0; i < .i++) {
            if ([i].equals(alias))
                return;
        }
        // Add this alias to the list
        String newAliases[] = new String[. + 1];
        for (int i = 0; i < .i++)
            newAliases[i] = [i];
        newAliases[.] = alias;
         = newAliases;
        // Inform interested listeners
        fireContainerEvent(alias);
    }


    
Add a child Container, only if the proposed child is an implementation of Context.

Parameters:
child Child container to be added
    public void addChild(Container child) {
        if (!(child instanceof Context))
            throw .hostChildMustBeContext();
        super.addChild(child);
    }


    
Return the set of alias names for this Host. If none are defined, a zero length array is returned.
    public String[] findAliases() {
        return (this.);
    }


    
Return descriptive information about this Container implementation and the corresponding version number, in the format <description>/<version>.
    public String getInfo() {
        return ();
    }


    
Remove the specified alias name from the aliases for this Host.

Parameters:
alias Alias name to be removed
    public void removeAlias(String alias) {
        alias = alias.toLowerCase(.);
        // Make sure this alias is currently present
        int n = -1;
        for (int i = 0; i < .i++) {
            if ([i].equals(alias)) {
                n = i;
                break;
            }
        }
        if (n < 0)
            return;
        // Remove the specified alias
        int j = 0;
        String results[] = new String[. - 1];
        for (int i = 0; i < .i++) {
            if (i != n)
                results[j++] = [i];
        }
         = results;
        // Inform interested listeners
        fireContainerEvent(alias);
    }


    
Return a String representation of this component.
    public String toString() {
        StringBuilder sb = new StringBuilder();
        if (getParent() != null) {
            sb.append(getParent().toString());
            sb.append(".");
        }
        sb.append("StandardHost[");
        sb.append(getName());
        sb.append("]");
        return (sb.toString());
    }


    
Start this host.

Throws:
org.apache.catalina.LifecycleException if this component detects a fatal error that prevents it from being started
    public synchronized void start() throws LifecycleException {
        if ) {
            return;
        }
        if( !  )
            init();
        // Set error report valve
        if (( != null)
            && (!.equals(""))) {
            try {
                boolean found = false;
                if( != null) {
                    ObjectName[] names = 
                        ((StandardPipeline)).getValveObjectNames();
                    for (int i=0; !found && i<names.lengthi++)
                        if(.equals(names[i]))
                            found = true ;
                    }
                    if(!found) {          	
                        Valve valve = (Valve) Class.forName()
                        .newInstance();
                        addValve(valve);
                         = ((ValveBase)valve).getObjectName() ;
                    }
            } catch (Throwable t) {
            }
        }
        super.start();
    }
    // -------------------- JMX  --------------------
    
Return the MBean Names of the Valves assoicated with this Host

Throws:
java.lang.Exception if an MBean cannot be created or registered
     public String [] getValveNames()
         throws Exception
    {
         Valve [] valves = this.getValves();
         String [] mbeanNames = new String[valves.length];
         for (int i = 0; i < valves.lengthi++) {
             ifvalves[i] == null ) continue;
             if( ((ValveBase)valves[i]).getObjectName() == null ) continue;
             mbeanNames[i] = ((ValveBase)valves[i]).getObjectName().toString();
         }
         return mbeanNames;
     }
    public String[] getAliases() {
        return ;
    }
    private boolean initialized=false;
    
    public synchronized void init() {
        if ) return;
        =true;
        
        if (.....) {
            if==null ) {
                // not registered in JMX yet - standalone mode
                try {
                    StandardEngine engine=(StandardEngine);
                    =engine.getName();
                    =new ObjectName( + ":type=Host,host=" +
                            this.getName());
                     = ;
                    ifgetParent() == null ) {
                        // Register with the Engine
                        ObjectName serviceName=new ObjectName( + 
                                ":type=Engine");
                        HostConfig deployer = new HostConfig();
                        addLifecycleListener(deployer);                
                        if.isRegisteredserviceName )) {
                            .invokeserviceName"addChild",
                                    new Object[] { this },
                                    new String[] { "org.apache.catalina.Container" } );
                        }
                    }
                    Registry.getRegistry(nullnull).registerComponent(thisnull);
                } catchThrowable t ) {
                    ..failedHostJmxRegistration(t);
                }
            }
        }
    }
    public synchronized void destroy() throws Exception {
        // destroy our child containers, if any
        Container children[] = findChildren();
        super.destroy();
        for (int i = 0; i < children.lengthi++) {
            if(children[iinstanceof StandardContext)
                ((StandardContext)children[i]).destroy();
        }
      
    }
    
    public ObjectName preRegister(MBeanServer serverObjectName oname ) 
        throws Exception
    {
        ObjectName res=super.preRegister(serveroname);
        String name=oname.getKeyProperty("host");
        ifname != null )
            setNamename );
        return res;        
    }
    
    public ObjectName createObjectName(String domainObjectName parent)
        throws Exception
    {
        return new ObjectNamedomain + ":type=Host,host=" + getName());
    }
New to GrepCode? Check out our FAQ X