wardircontext.java
来自「This temp directory is used by the JVM f」· Java 代码 · 共 998 行 · 第 1/3 页
JAVA
998 行
/*
* $Header: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/naming/resources/WARDirContext.java,v 1.3 2004/01/26 19:48:27 remm Exp $
* $Revision: 1.3 $
* $Date: 2004/01/26 19:48:27 $
*
* ====================================================================
*
* 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 apache@apache.org.
*
* 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.naming.resources;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Date;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipFile;
import javax.naming.CompositeName;
import javax.naming.Name;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.OperationNotSupportedException;
import javax.naming.directory.Attributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.ModificationItem;
import javax.naming.directory.SearchControls;
import org.apache.naming.NamingContextBindingsEnumeration;
import org.apache.naming.NamingContextEnumeration;
import org.apache.naming.NamingEntry;
/**
* WAR Directory Context implementation.
*
* @author Remy Maucherat
* @version $Revision: 1.3 $ $Date: 2004/01/26 19:48:27 $
*/
public class WARDirContext extends BaseDirContext {
// ----------------------------------------------------------- Constructors
/**
* Builds a WAR directory context using the given environment.
*/
public WARDirContext() {
super();
}
/**
* Builds a WAR directory context using the given environment.
*/
public WARDirContext(Hashtable env) {
super(env);
}
/**
* Constructor used for returning fake subcontexts.
*/
protected WARDirContext(ZipFile base, Entry entries) {
this.base = base;
this.entries = entries;
}
// ----------------------------------------------------- Instance Variables
/**
* The WAR file.
*/
protected ZipFile base = null;
/**
* WAR entries.
*/
protected Entry entries = null;
// ------------------------------------------------------------- Properties
/**
* Set the document root.
*
* @param docBase The new document root
*
* @exception IllegalArgumentException if the specified value is not
* supported by this implementation
* @exception IllegalArgumentException if this would create a
* malformed URL
*/
public void setDocBase(String docBase) {
// Validate the format of the proposed document root
if (docBase == null)
throw new IllegalArgumentException
(sm.getString("resources.null"));
if (!(docBase.endsWith(".war")))
throw new IllegalArgumentException
(sm.getString("warResources.notWar"));
// Calculate a File object referencing this document base directory
File base = new File(docBase);
// Validate that the document base is an existing directory
if (!base.exists() || !base.canRead() || base.isDirectory())
throw new IllegalArgumentException
(sm.getString("warResources.notWar"));
try {
this.base = new ZipFile(base);
} catch (Exception e) {
throw new IllegalArgumentException
(sm.getString("warResources.invalidWar", e.getMessage()));
}
super.setDocBase(docBase);
loadEntries();
}
// --------------------------------------------------------- Public Methods
/**
* Release any resources allocated for this directory context.
*/
public void release() {
entries = null;
if (base != null) {
try {
base.close();
} catch (IOException e) {
System.out.println
("Exception closing WAR File " + base.getName());
e.printStackTrace(System.out);
}
}
base = null;
super.release();
}
// -------------------------------------------------------- Context Methods
/**
* Retrieves the named object.
*
* @param name the name of the object to look up
* @return the object bound to name
* @exception NamingException if a naming exception is encountered
*/
public Object lookup(String name)
throws NamingException {
return lookup(new CompositeName(name));
}
/**
* Retrieves the named object. If name is empty, returns a new instance
* of this context (which represents the same naming context as this
* context, but its environment may be modified independently and it may
* be accessed concurrently).
*
* @param name the name of the object to look up
* @return the object bound to name
* @exception NamingException if a naming exception is encountered
*/
public Object lookup(Name name)
throws NamingException {
if (name.isEmpty())
return this;
Entry entry = treeLookup(name);
if (entry == null)
throw new NamingException
(sm.getString("resources.notFound", name));
ZipEntry zipEntry = entry.getEntry();
if (zipEntry.isDirectory())
return new WARDirContext(base, entry);
else
return new WARResource(entry.getEntry());
}
/**
* Unbinds the named object. Removes the terminal atomic name in name
* from the target context--that named by all but the terminal atomic
* part of name.
* <p>
* This method is idempotent. It succeeds even if the terminal atomic
* name is not bound in the target context, but throws
* NameNotFoundException if any of the intermediate contexts do not exist.
*
* @param name the name to bind; may not be empty
* @exception NameNotFoundException if an intermediate context does not
* exist
* @exception NamingException if a naming exception is encountered
*/
public void unbind(String name)
throws NamingException {
throw new OperationNotSupportedException();
}
/**
* Binds a new name to the object bound to an old name, and unbinds the
* old name. Both names are relative to this context. Any attributes
* associated with the old name become associated with the new name.
* Intermediate contexts of the old name are not changed.
*
* @param oldName the name of the existing binding; may not be empty
* @param newName the name of the new binding; may not be empty
* @exception NameAlreadyBoundException if newName is already bound
* @exception NamingException if a naming exception is encountered
*/
public void rename(String oldName, String newName)
throws NamingException {
throw new OperationNotSupportedException();
}
/**
* Enumerates the names bound in the named context, along with the class
* names of objects bound to them. The contents of any subcontexts are
* not included.
* <p>
* If a binding is added to or removed from this context, its effect on
* an enumeration previously returned is undefined.
*
* @param name the name of the context to list
* @return an enumeration of the names and class names of the bindings in
* this context. Each element of the enumeration is of type NameClassPair.
* @exception NamingException if a naming exception is encountered
*/
public NamingEnumeration list(String name)
throws NamingException {
return list(new CompositeName(name));
}
/**
* Enumerates the names bound in the named context, along with the class
* names of objects bound to them. The contents of any subcontexts are
* not included.
* <p>
* If a binding is added to or removed from this context, its effect on
* an enumeration previously returned is undefined.
*
* @param name the name of the context to list
* @return an enumeration of the names and class names of the bindings in
* this context. Each element of the enumeration is of type NameClassPair.
* @exception NamingException if a naming exception is encountered
*/
public NamingEnumeration list(Name name)
throws NamingException {
if (name.isEmpty())
return new NamingContextEnumeration(list(entries));
Entry entry = treeLookup(name);
if (entry == null)
throw new NamingException
(sm.getString("resources.notFound", name));
return new NamingContextEnumeration(list(entry));
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?