## org.eclipse.jetty.servlet
Class ServletHolder

    java.lang.Object
      org.eclipse.jetty.util.component.AbstractLifeCycle
          org.eclipse.jetty.servlet.Holder<Servlet>
              org.eclipse.jetty.servlet.ServletHolder

All Implemented Interfaces:
  Comparable, UserIdentity.Scope, LifeCycle

    public class ServletHolder

extends Holder<Servlet>
implements UserIdentity.Scope, Comparable

Servlet Instance and Context Holder. Holds the name, params and some state of a javax.servlet.Servlet instance. It implements the ServletConfig interface. This class will organise the loading of the servlet when needed or requested.

Nested Class Summary
`protected class` `ServletHolder.Config`
`class` `ServletHolder.Registration`

Nested classes/interfaces inherited from class org.eclipse.jetty.servlet.Holder
`Holder.HolderConfig, Holder.HolderRegistration`

Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
`AbstractLifeCycle.AbstractLifeCycleListener`

Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle
`LifeCycle.Listener`

Field Summary
`static Map<String,String>` `NO_MAPPED_ROLES`

Fields inherited from class org.eclipse.jetty.servlet.Holder
`_asyncSupported, _class, _className, _displayName, _extInstance, _initParams, _name, _servletHandler`

Fields inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
`_listeners, FAILED, RUNNING, STARTED, STARTING, STOPPED, STOPPING`

Constructor Summary
`ServletHolder()` Constructor .
`ServletHolder(Class<? extends Servlet> servlet)` Constructor for existing servlet.
`ServletHolder(Servlet servlet)` Constructor for existing servlet.

Method Summary
`void` `checkServletType()` Check to ensure class of servlet is acceptable.
`int` `compareTo(Object o)` Comparitor by init order.
`void` `destroyInstance(Object o)`
`void` `doStart()`
`void` `doStop()`
`boolean` `equals(Object o)`
`String` `getContextPath()`
`String` `getForcedPath()`
`int` `getInitOrder()`
`ServletRegistration.Dynamic` `getRegistration()`
`Map<String,String>` `getRoleMap()`
`Map<String,String>` `getRoleRefMap()`
`String` `getRunAsRole()`
`Servlet` `getServlet()` Get the servlet.
`Servlet` `getServletInstance()` Get the servlet instance (no initialization done).
`UnavailableException` `getUnavailableException()`
`String` `getUserRoleLink(String name)` get a user role link.
`void` `handle(Request baseRequest, ServletRequest request, ServletResponse response)` Service a request with this servlet.
`int` `hashCode()`
`boolean` `isAvailable()`
`boolean` `isSetInitOrder()`
`protected Servlet` `newInstance()`
`void` `setForcedPath(String forcedPath)`
`void` `setInitOrder(int order)` Set the initialize order.
`void` `setRunAsRole(String role)`
`void` `setServlet(Servlet servlet)`
`void` `setUserRoleLink(String name, String link)` Link a user role.

Methods inherited from class org.eclipse.jetty.servlet.Holder
`getClassName, getDisplayName, getHeldClass, getInitParameter, getInitParameterNames, getInitParameters, getName, getServletHandler, illegalStateIfContextStarted, isAsyncSupported, isInstance, setAsyncSupported, setClassName, setDisplayName, setHeldClass, setInitParameter, setInitParameters, setName, setServletHandler, toString`

Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
`addLifeCycleListener, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop`

Methods inherited from class java.lang.Object
`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

Methods inherited from interface org.eclipse.jetty.server.UserIdentity.Scope
`getName`

Field Detail

### NO_MAPPED_ROLES

    public static final Map<String,String> NO_MAPPED_ROLES

Constructor Detail

### ServletHolder

    public ServletHolder()

  Constructor .

### ServletHolder

    public ServletHolder(Servlet servlet)

  Constructor for existing servlet.

### ServletHolder

    public ServletHolder(Class<? extends Servlet> servlet)

  Constructor for existing servlet.

Method Detail

### getUnavailableException

    public UnavailableException getUnavailableException()

  Returns:
    The unavailable exception or null if not unavailable

### setServlet

    public void setServlet(Servlet servlet)

### getInitOrder

    public int getInitOrder()

### setInitOrder

    public void setInitOrder(int order)

  Set the initialize order. Holders with order<0, are initialized on use. Those with order>=0 are initialized in increasing order when the handler is started.

### isSetInitOrder

    public boolean isSetInitOrder()

### compareTo

    public int compareTo(Object o)

  Comparitor by init order.

  Specified by:
    `compareTo` in interface `Comparable`

### equals

    public boolean equals(Object o)

  Overrides:
    `equals` in class `Object`

### hashCode

    public int hashCode()

  Overrides:
    `hashCode` in class `Object`

### setUserRoleLink

    public void setUserRoleLink(String name,
                                String link)

  Link a user role. Translate the role name used by a servlet, to the link name used by the container.

  Parameters:
    `name` - The role name as used by the servlet
    `link` - The role name as used by the container.

### getUserRoleLink

    public String getUserRoleLink(String name)

  get a user role link.

  Parameters:
    `name` - The name of the role
  Returns:
    The name as translated by the link. If no link exists, the name is returned.

### getRoleMap

    public Map<String,String> getRoleMap()

### getForcedPath

    public String getForcedPath()

  Returns:
    Returns the forcedPath.

### setForcedPath

    public void setForcedPath(String forcedPath)

  Parameters:
    `forcedPath` - The forcedPath to set.

### doStart

    public void doStart()
                 throws Exception

  Overrides:
    `doStart` in class `Holder<Servlet>`
  Throws:
    `Exception`

### doStop

    public void doStop()
                throws Exception

  Overrides:
    `doStop` in class `Holder<Servlet>`
  Throws:
    `Exception`

### destroyInstance

    public void destroyInstance(Object o)
                         throws Exception

  Overrides:
    `destroyInstance` in class `Holder<Servlet>`
  Throws:
    `Exception`

### getServlet

    public Servlet getServlet()
                       throws ServletException

  Get the servlet.

  Returns:
    The servlet
  Throws:
    `ServletException`

### getServletInstance

    public Servlet getServletInstance()

  Get the servlet instance (no initialization done).

  Returns:
    The servlet or null

### checkServletType

    public void checkServletType()
                          throws UnavailableException

  Check to ensure class of servlet is acceptable.

  Throws:
    `UnavailableException`

### isAvailable

    public boolean isAvailable()

  Returns:
    true if the holder is started and is not unavailable

### getContextPath

    public String getContextPath()

  Specified by:
    `getContextPath` in interface `UserIdentity.Scope`
  Returns:
    The context path that the identity is being considered within
  See Also:
    `UserIdentity.Scope.getContextPath()`

### getRoleRefMap

    public Map<String,String> getRoleRefMap()

  Specified by:
    `getRoleRefMap` in interface `UserIdentity.Scope`
  Returns:
    A map of role reference names that converts from names used by application code to names used by the context deployment.
  See Also:
    `UserIdentity.Scope.getRoleRefMap()`

### getRunAsRole

    public String getRunAsRole()

### setRunAsRole

    public void setRunAsRole(String role)

### handle

    public void handle(Request baseRequest,
                       ServletRequest request,
                       ServletResponse response)
                throws ServletException,
                       UnavailableException,
                       IOException

  Service a request with this servlet.

  Throws:
    `ServletException`
    `UnavailableException`
    `IOException`

### getRegistration

    public ServletRegistration.Dynamic getRegistration()

### newInstance

    protected Servlet newInstance()
                           throws ServletException,
                                  IllegalAccessException,
                                  InstantiationException

  Returns:
  Throws:
    `ServletException`
    `IllegalAccessException`
    `InstantiationException`

Copyright © 1995-2010 Mort Bay Consulting. All Rights Reserved.