Apache Tomcat 7.0.37

org.apache.naming.resources
Class VirtualDirContext

java.lang.Object
  extended by org.apache.naming.resources.BaseDirContext
      extended by org.apache.naming.resources.FileDirContext
          extended by org.apache.naming.resources.VirtualDirContext
All Implemented Interfaces:
Context, DirContext

public class VirtualDirContext
extends FileDirContext

Extended FileDirContext implementation that allows to expose multiple directories of the filesystem under a single webapp, a feature mainly used for development with IDEs. This should be used in conjunction with VirtualWebappLoader. Sample context xml configuration: <Context path="/mywebapp" docBase="/Users/theuser/mywebapp/src/main/webapp" > <Resources className="org.apache.naming.resources.VirtualDirContext" extraResourcePaths="/pictures=/Users/theuser/mypictures,/movies=/Users/theuser/mymovies" /> <Loader className="org.apache.catalina.loader.VirtualWebappLoader" virtualClasspath="/Users/theuser/mywebapp/target/classes" /> <JarScanner scanAllDirectories="true" /> </Context> This is not meant to be used for production. Its meant to ease development with IDE's without the need for fully republishing jars in WEB-INF/lib

Version:
$Id: VirtualDirContext.java 1371816 2012-08-10 19:54:55Z markt $
Author:
Fabrizio Giustina

Nested Class Summary
 
Nested classes/interfaces inherited from class org.apache.naming.resources.FileDirContext
FileDirContext.FileResource, FileDirContext.FileResourceAttributes
 
Field Summary
 
Fields inherited from class org.apache.naming.resources.FileDirContext
absoluteBase, allowLinking, base, BUFFER_SIZE
 
Fields inherited from class org.apache.naming.resources.BaseDirContext
aliases, altDirContexts, cached, cacheMaxSize, cacheObjectMaxSize, cacheTTL, docBase, env, nameParser, sm
 
Fields inherited from interface javax.naming.directory.DirContext
ADD_ATTRIBUTE, REMOVE_ATTRIBUTE, REPLACE_ATTRIBUTE
 
Fields inherited from interface javax.naming.Context
APPLET, AUTHORITATIVE, BATCHSIZE, DNS_URL, INITIAL_CONTEXT_FACTORY, LANGUAGE, OBJECT_FACTORIES, PROVIDER_URL, REFERRAL, SECURITY_AUTHENTICATION, SECURITY_CREDENTIALS, SECURITY_PRINCIPAL, SECURITY_PROTOCOL, STATE_FACTORIES, URL_PKG_PREFIXES
 
Constructor Summary
VirtualDirContext()
           
 
Method Summary
 void allocate()
          Allocate resources for this directory context.
protected  String doGetRealPath(String path)
          Return the real path for a given virtual path, if possible; otherwise return null.
protected  Object doLookup(String name)
          Retrieves the named object.
protected  File file(String name)
          Return a File object representing the specified normalized context-relative path if it exists and is readable.
 Attributes getAttributes(String name)
          Retrieves all of the attributes associated with a named object.
protected  List<NamingEntry> list(File file)
          List the resources which are members of a collection.
 void release()
          Release any resources allocated for this directory context.
 void setExtraResourcePaths(String path)
           Allows to map a path of the filesystem to a path in the webapp.
 
Methods inherited from class org.apache.naming.resources.FileDirContext
bind, createSubcontext, destroySubcontext, doGetAttributes, doListBindings, getAllowLinking, getNameInNamespace, getSchema, getSchemaClassDefinition, lookupLink, modifyAttributes, modifyAttributes, normalize, rebind, rename, search, search, search, search, setAllowLinking, setDocBase, unbind
 
Methods inherited from class org.apache.naming.resources.BaseDirContext
addAlias, addAltDirContext, addResourcesJar, addToEnvironment, bind, bind, bind, close, composeName, composeName, createSubcontext, createSubcontext, createSubcontext, destroySubcontext, getAliases, getAttributes, getAttributes, getAttributes, getCacheMaxSize, getCacheObjectMaxSize, getCacheTTL, getDocBase, getEnvironment, getNameParser, getNameParser, getRealPath, getSchema, getSchemaClassDefinition, isCached, list, list, listBindings, listBindings, lookup, lookup, lookupLink, modifyAttributes, modifyAttributes, rebind, rebind, rebind, removeAlias, removeFromEnvironment, rename, search, search, search, search, setAliases, setCached, setCacheMaxSize, setCacheObjectMaxSize, setCacheTTL, unbind
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VirtualDirContext

public VirtualDirContext()
Method Detail

setExtraResourcePaths

public void setExtraResourcePaths(String path)

Allows to map a path of the filesystem to a path in the webapp. Multiple filesystem paths can be mapped to the same path in the webapp. Filesystem path and virtual path must be separated by an equal sign. Pairs of paths must be separated by a comma.

Example: /=/Users/slaurent/mywebapp/src/main/webapp;/pictures=/Users/slaurent/sharedpictures

The path to the docBase must not be added here, otherwise resources would be listed twice.

Parameters:
path -

allocate

public void allocate()
Allocate resources for this directory context.

Overrides:
allocate in class BaseDirContext

release

public void release()
Release any resources allocated for this directory context.

Overrides:
release in class FileDirContext

getAttributes

public Attributes getAttributes(String name)
                         throws NamingException
Description copied from class: BaseDirContext
Retrieves all of the attributes associated with a named object.

Specified by:
getAttributes in interface DirContext
Overrides:
getAttributes in class BaseDirContext
Parameters:
name - the name of the object from which to retrieve attributes
Returns:
the set of attributes associated with name
Throws:
NamingException - if a naming exception is encountered

file

protected File file(String name)
Description copied from class: FileDirContext
Return a File object representing the specified normalized context-relative path if it exists and is readable. Otherwise, return null.

Overrides:
file in class FileDirContext
Parameters:
name - Normalized context-relative path (with leading '/')

list

protected List<NamingEntry> list(File file)
Description copied from class: FileDirContext
List the resources which are members of a collection.

Overrides:
list in class FileDirContext
Parameters:
file - Collection
Returns:
Vector containing NamingEntry objects

doLookup

protected Object doLookup(String name)
Description copied from class: FileDirContext
Retrieves the named object.

Overrides:
doLookup in class FileDirContext
Parameters:
name - the name of the object to look up
Returns:
the object bound to name

doGetRealPath

protected String doGetRealPath(String path)
Description copied from class: FileDirContext
Return the real path for a given virtual path, if possible; otherwise return null.

Overrides:
doGetRealPath in class FileDirContext
Parameters:
path - The path to the desired resource

Apache Tomcat 7.0.37

Copyright © 2000-2013 Apache Software Foundation. All Rights Reserved.