⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 proxydircontext.java

📁 Tomcat 4.1与WebServer集成组件的源代码包.
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
     * @return a non-null enumeration of SearchResult objects. Each      * SearchResult contains the attributes identified by attributesToReturn      * and the name of the corresponding object, named relative to the      * context named by name.     * @exception NamingException if a naming exception is encountered     */    public NamingEnumeration search(Name name, Attributes matchingAttributes)        throws NamingException {        return dirContext.search(parseName(name), matchingAttributes);    }    /**     * Searches in a single context for objects that contain a specified set      * of attributes.     *      * @param name the name of the context to search     * @param matchingAttributes the attributes to search for. If empty or      * null, all objects in the target context are returned.     * @return a non-null enumeration of SearchResult objects. Each      * SearchResult contains the attributes identified by attributesToReturn      * and the name of the corresponding object, named relative to the      * context named by name.     * @exception NamingException if a naming exception is encountered     */    public NamingEnumeration search(String name, Attributes matchingAttributes)        throws NamingException {        return dirContext.search(parseName(name), matchingAttributes);    }    /**     * Searches in the named context or object for entries that satisfy the      * given search filter. Performs the search as specified by the search      * controls.     *      * @param name the name of the context or object to search     * @param filter the filter expression to use for the search; may not be      * null     * @param cons the search controls that control the search. If null,      * the default search controls are used (equivalent to      * (new SearchControls())).     * @return an enumeration of SearchResults of the objects that satisfy      * the filter; never null     * @exception InvalidSearchFilterException if the search filter specified      * is not supported or understood by the underlying directory     * @exception InvalidSearchControlsException if the search controls      * contain invalid settings     * @exception NamingException if a naming exception is encountered     */    public NamingEnumeration search(Name name, String filter,                                     SearchControls cons)        throws NamingException {        return dirContext.search(parseName(name), filter, cons);    }    /**     * Searches in the named context or object for entries that satisfy the      * given search filter. Performs the search as specified by the search      * controls.     *      * @param name the name of the context or object to search     * @param filter the filter expression to use for the search; may not be      * null     * @param cons the search controls that control the search. If null,      * the default search controls are used (equivalent to      * (new SearchControls())).     * @return an enumeration of SearchResults of the objects that satisfy      * the filter; never null     * @exception InvalidSearchFilterException if the search filter      * specified is not supported or understood by the underlying directory     * @exception InvalidSearchControlsException if the search controls      * contain invalid settings     * @exception NamingException if a naming exception is encountered     */    public NamingEnumeration search(String name, String filter,                                     SearchControls cons)        throws NamingException {        return dirContext.search(parseName(name), filter, cons);    }    /**     * Searches in the named context or object for entries that satisfy the      * given search filter. Performs the search as specified by the search      * controls.     *      * @param name the name of the context or object to search     * @param filterExpr the filter expression to use for the search.      * The expression may contain variables of the form "{i}" where i is a      * nonnegative integer. May not be null.     * @param filterArgs the array of arguments to substitute for the      * variables in filterExpr. The value of filterArgs[i] will replace each      * occurrence of "{i}". If null, equivalent to an empty array.     * @param cons the search controls that control the search. If null, the      * default search controls are used (equivalent to (new SearchControls())).     * @return an enumeration of SearchResults of the objects that satisy the      * filter; never null     * @exception ArrayIndexOutOfBoundsException if filterExpr contains {i}      * expressions where i is outside the bounds of the array filterArgs     * @exception InvalidSearchControlsException if cons contains invalid      * settings     * @exception InvalidSearchFilterException if filterExpr with filterArgs      * represents an invalid search filter     * @exception NamingException if a naming exception is encountered     */    public NamingEnumeration search(Name name, String filterExpr,                                    Object[] filterArgs, SearchControls cons)        throws NamingException {        return dirContext.search(parseName(name), filterExpr, filterArgs,                                  cons);    }    /**     * Searches in the named context or object for entries that satisfy the      * given search filter. Performs the search as specified by the search      * controls.     *      * @param name the name of the context or object to search     * @param filterExpr the filter expression to use for the search.      * The expression may contain variables of the form "{i}" where i is a      * nonnegative integer. May not be null.     * @param filterArgs the array of arguments to substitute for the      * variables in filterExpr. The value of filterArgs[i] will replace each      * occurrence of "{i}". If null, equivalent to an empty array.     * @param cons the search controls that control the search. If null, the      * default search controls are used (equivalent to (new SearchControls())).     * @return an enumeration of SearchResults of the objects that satisy the      * filter; never null     * @exception ArrayIndexOutOfBoundsException if filterExpr contains {i}      * expressions where i is outside the bounds of the array filterArgs     * @exception InvalidSearchControlsException if cons contains invalid      * settings     * @exception InvalidSearchFilterException if filterExpr with filterArgs      * represents an invalid search filter     * @exception NamingException if a naming exception is encountered     */    public NamingEnumeration search(String name, String filterExpr,                                    Object[] filterArgs, SearchControls cons)        throws NamingException {        return dirContext.search(parseName(name), filterExpr, filterArgs,                                  cons);    }    // ------------------------------------------------------ Protected Methods    /**     * Parses a name.     *      * @return the parsed name     */    protected String parseName(String name)         throws NamingException {        return name;    }    /**     * Parses a name.     *      * @return the parsed name     */    protected Name parseName(Name name)         throws NamingException {        return name;    }    /**     * Lookup in cache.     */    protected CacheEntry cacheLookupAndLoad(String name) {        if (cache == null)            return (null);        CacheEntry cacheEntry = (CacheEntry) cache.get(name);        if (cacheEntry == null) {            cacheEntry = new CacheEntry();            cacheEntry.name = name;            // Load entry            if (!cacheLoad(cacheEntry))                return null;            return (cacheEntry);        } else {            if (!validate(cacheEntry)) {                if (!revalidate(cacheEntry)) {                    cacheUnload(cacheEntry.name);                    return (null);                } else {                    cacheEntry.timestamp =                         System.currentTimeMillis() + cacheTTL;                }            }            return (cacheEntry);        }    }    /**     * Validate entry.     */    protected boolean validate(CacheEntry entry) {        if ((entry.resource != null)             //            && (entry.resource.getContent() != null)             && (System.currentTimeMillis() < entry.timestamp)) {            return true;        }        return false;    }    /**     * Revalidate entry.     */    protected boolean revalidate(CacheEntry entry) {        // Get the attributes at the given path, and check the last         // modification date        if (entry.attributes == null)            return false;        long lastModified = AttributeHelper.getLastModified(entry.attributes);        //        long contentLength = entry.attributes.getContentLength();        if (lastModified <= 0)            return false;        try {//             Attributes tempAttributes = dirContext.getAttributes(entry.name);             Attributes attributes = dirContext.getAttributes(entry.name);//             ResourceAttributes attributes = null;//             if (!(tempAttributes instanceof ResourceAttributes)) {//                 attributes = new ResourceAttributes(tempAttributes);//             } else {//                 attributes = (ResourceAttributes) tempAttributes;//             }            long lastModified2 = AttributeHelper.getLastModified(attributes);            //            long contentLength2 = attributes.getContentLength();            return (lastModified == lastModified2) ;                //  && (contentLength == contentLength2);        } catch (NamingException e) {            return false;        }    }    /**     * Load entry into cache.     */    protected boolean cacheLoad(CacheEntry entry) {        if (cache == null)            return false;        String name = entry.name;        // Retrieve missing info        // Retrieving attributes        if (entry.attributes == null) {            try {                Attributes attributes = dirContext.getAttributes(entry.name);//                 if (!(attributes instanceof ResourceAttributes)) {//                     entry.attributes = //                         new ResourceAttributes(attributes);//                 } else {//                     entry.attributes = (ResourceAttributes) attributes;//                 }            } catch (NamingException e) {                return false;            }        }        // Retriving object        if ((entry.resource == null) && (entry.context == null)) {            try {                Object object = dirContext.lookup(name);//                 if (object instanceof InputStream) {//                     entry.resource = new Resource((InputStream) object);//                 } else if (object instanceof DirContext) {//                     entry.context = (DirContext) object;//                 } else if (object instanceof Resource) {//                     entry.resource = (Resource) object;//                 } else {//                     entry.resource = new Resource(new ByteArrayInputStream//                         (object.toString().getBytes()));//                 }                entry.resource=object;            } catch (NamingException e) {                return false;            }        }        // TODO: lazy loading. We may list a dir, there's no reason to load        // all entries ( we may just look at attributes )                // Load object content. We cache entries without content ( users, etc )         /*          if ((entry.resource != null) && (entry.resource.getContent() == null)             //            && (entry.attributes.getContentLength() >= 0)            && (entry.attributes.getContentLength() < cacheObjectMaxSize)) {            int length = (int) entry.attributes.getContentLength();            InputStream is = null;            try {                is = entry.resource.streamContent();                int pos = 0;                byte[] b = new byte[length];                while (pos < length) {                    int n = is.read(b, pos, length - pos);                    if (n < 0)                        break;                    pos = pos + n;                }                entry.resource.setContent(b);            } catch (IOException e) {                ; // Ignore            } finally {                try {                    if (is != null)                        is.close();                } catch (IOException e) {                    ; // Ignore                }            }        }        */        // Set timestamp        entry.timestamp = System.currentTimeMillis() + cacheTTL;        // Add new entry to cache        cache.put(name, entry);        return true;    }    /**     * Remove entry from cache.     */    protected boolean cacheUnload(String name) {        if (cache == null)            return false;        return (cache.remove(name) != null);    }    // ------------------------------------------------- CacheEntry Inner Class    protected class CacheEntry {        // ------------------------------------------------- Instance Variables        long timestamp = -1;        String name = null;        Attributes attributes = null;        //ResourceAttributes attributes = null;        Object resource = null;        DirContext context = null;        // ----------------------------------------------------- Public Methods        public void recycle() {            timestamp = -1;            name = null;            attributes = null;            resource = null;            context = null;        }        public String toString() {            return ("Cache entry: " + name + "\n"                    + "Attributes: " + attributes + "\n"                    + "Resource: " + resource + "\n"                    + "Context: " + context);        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -