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

📄 resource.java

📁 很棒的web服务器源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	}    }    /**     * Unregister a resource frame from the given resource.     * @param frame The frame to unregister from the resource.     */    public synchronized void unregisterFrame(ResourceFrame frame) {	ResourceFrame frames[] = null;	frames = (ResourceFrame[]) getValue(ATTR_RESOURCE_FRAMES, null);	if ( frames != null ) {	    ResourceFrame f[] = new ResourceFrame[frames.length-1];	    int j=0;	    for (int i = 0; i < frames.length ; i++) {		if ( frames[i] == frame ) {		    // got it, copy the end of the array		    System.arraycopy(frames, i+1, f, j, frames.length-i-1);		    setValue(ATTR_RESOURCE_FRAMES, f);		    return;		} else {		    try {			f[j++] = frames[i];		    } catch (ArrayIndexOutOfBoundsException ex) {			return; // no modifications, return		    }		}	    }	}    }    /**     * Collect all frames.     * @return An array of ResourceFrame, containing a set of frames instances     * or <strong>null</strong> if no resource frame is available.     */    public synchronized ResourceFrame[] getFrames() {	return (ResourceFrame[]) getValue(ATTR_RESOURCE_FRAMES, null);    }    /**     * Collect any frame that's an instance of the given class.     * @param cls The class of frames we are looking for.     * @return An array of ResourceFrame, containing a set of frames instances     * of the given class, or <strong>null</strong> if no resource frame is     * available.     */    public synchronized ResourceFrame[] collectFrames(Class c) {	ResourceFrame frames[] = null;	frames = (ResourceFrame[]) getValue(ATTR_RESOURCE_FRAMES, null);	if ( frames != null ) {	    Vector v = new Vector(frames.length);	    for (int i = 0 ; i < frames.length ; i++) {		if ( c.isInstance(frames[i]) )		    v.addElement(frames[i]);	    }	    int sz = v.size();	    if ( sz > 0 ) {		ResourceFrame ret[] = new ResourceFrame[sz];		v.copyInto(ret);		return ret;	    }	}	return null;    }    /**     * Collect any frame that's an instance of the given class.     * @param cls The class of frames we are looking for.     * @return An array of ResourceFrame, containing a set of frames instances     * of the given class, or <strong>null</strong> if no resource frame is     * available.     */    ResourceFrame[] unsafeCollectFrames(Class c) {	ResourceFrame frames[] = null;	frames = (ResourceFrame[]) unsafeGetValue(ATTR_RESOURCE_FRAMES, null);	if ( frames != null ) {	    Vector v = new Vector(frames.length);	    for (int i = 0 ; i < frames.length ; i++) {		if ( c.isInstance(frames[i]) )		    v.addElement(frames[i]);	    }	    int sz = v.size();	    if ( sz > 0 ) {		ResourceFrame ret[] = new ResourceFrame[sz];		v.copyInto(ret);		return ret;	    }	}	return null;    }    /**     * Get the first occurence of a frame of the given class.     * @param cls The class of te frame to look for.     * @return A ResourceFrame instance, or <strong>null</strong>.     */    public synchronized ResourceFrame getFrame(Class c) {	ResourceFrame frames[] = null;	frames = (ResourceFrame[]) getValue(ATTR_RESOURCE_FRAMES, null);	if ( frames != null ) {	    for (int i = 0 ; i < frames.length ; i++) {		if ( c.isInstance(frames[i]) )		    return frames[i];	    }	}	return null;    }	    /**     * Get an attached frame attribute value.     * This method really is a short-hand that combines a <code>getFrame</code>     * and <code>getValue</code> method call.     * @param cls The class of the frame we want the value of.     * @param idx The attribute index.     * @param def The default value (if the attribute value isn't defined).     * @return The attribute value as an Object instance, or the provided     * default value if the attribute value isn't defined.     */    public synchronized Object getValue(Class c, int idx, Object def) {	ResourceFrame frame = getFrame(c);	if ( frame != null )	    return frame.getValue(idx, def);	throw new IllegalAttributeAccess(this, idx);    }    /**     * Set an attached frame attribute value.     * This method really is a short-hand that combines a <code>getFrame</code>     * and a <code>setValue</code> method call.     * @param cls The class of the frame we want to modify.     * @param idx The attribute to modify.     * @param val The new attribute value.     */    public synchronized void setValue(Class c, int idx, Object val) {	ResourceFrame frame = getFrame(c);	if ( frame != null ) {	    frame.setValue(idx, val);	    markModified();	    return;	}	throw new IllegalAttributeAccess(this, idx);    }    /**     * Get this resource last modification time.     * @return A long giving the date of the last modification time, or     *    <strong>-1</strong> if undefined.     */    public long getLastModified() {	return getLong(ATTR_LAST_MODIFIED, (long) -1) ;    }    /**     * Mark this resource as having been modified.     */    public void markModified() {	ResourceSpace space = getSpace();	if ((space != null) && (getSpaceEntry() != null)) {	    synchronized (this) {		space.markModified(getSpaceEntry(), this);	    }	}	super.setValue(ATTR_LAST_MODIFIED, 		       new Long(System.currentTimeMillis()));    }    /**     * We overide setValue, to mark the resource as modified.     * @param idx The index of the attribute to modify.     * @param value The new attribute value.     */    public void setValue(int idx, Object value) {	// Changing the identifier of a resource needs some special tricks:	if ( idx == ATTR_IDENTIFIER ) {	    String oldid = getIdentifier();	    try {		super.setValue(idx, value);	    } catch (IllegalAttributeAccess ex) {		// We were not able to change the identifier, rethrow		throw ex;	    }	    // Change was successfull, update the resource space:	    if (getSpaceEntry() != null) {		ResourceSpace space = getSpace();		space.renameResource(getSpaceEntry(), oldid, (String) value);	    }	    //modify the URL path	    ResourceReference rr = getParent();	    if (rr != null) {		try {		    Resource r = rr.lock();		    setValue(ATTR_URL,			     r.getURLPath()+			     java.net.URLEncoder.encode((String) value));		} catch(Exception ex) {		    ex.printStackTrace();		} finally {		    rr.unlock();		}	    }	    markModified();	    return;	}	// Normal setValue, but markModified before leaving:	super.setValue(idx, value) ;	if (( ! attributes[idx].checkFlag(Attribute.DONTSAVE) ) &&	    ( idx != ATTR_LAST_MODIFIED))	    markModified() ;    }    /**     * Is that resource willing to be unloaded.     * This method is a bit tricky to implement. The guideline is that you     * should not dynamically change the returned value (since you can't      * control what happens between a call to that method and a call to     * the <code>notifyUnload</code> method).     * <p>Returning <strong>false</strong> should never be needed, except     * for very strange resources.     * @return A boolean <strong>true</strong> if the resource can be unloaded     * <strong>false</strong> otherwise.     */    public boolean acceptUnload() {	if ( debugunload ) {	    try {		System.out.println(getValue("url","<??>")+": acceptUnload");	    } catch (IllegalAttributeAccess ex) {	    }	}	return true;    }    /**     * This resource is being unloaded.     * The resource is being unloaded from memory, perform any additional     * cleanup required.     */    public void notifyUnload() {	if ( debugunload ) {	    try {		System.out.println(getValue("url","<??>")+": unloaded.");	    } catch (IllegalAttributeAccess ex) {	    }	}	values = null ;    }    /**     * unloaded?     * @return true if the resource has been unloaded.     */    public boolean isUnloaded() {	return (values == null);    }    /**     * The web admin wants us to update any out of date attribute.     */    public void updateAttributes() {	return ;    }    /**     * Check if this resource is loked more than one time.     * @exception MultipleLockException is thrown if true.     */    protected void checkMultipleLock(ResourceReference rr) 	throws MultipleLockException    {	if (rr.nbLock() > 1)	    throw new MultipleLockException(rr.nbLock(), this, "can't delete");    }    /**     * Delete this Resource instance, and remove it from its store.     * This method will erase definitely this resource, for ever, by removing     * it from its resource store (when doable).     * @exception MultipleLockException if someone else has locked this      * resource     */    public synchronized void delete() 	throws MultipleLockException    {	ResourceSpace space = getSpace();	if ((space != null) && (getSpaceEntry() != null)) {	    ResourceReference self = getResourceReference();	    if (self != null) {		synchronized (self) {		    checkMultipleLock(self);		    space.deleteResource(getSpaceEntry(), this);		}	    } else {		space.deleteResource(getSpaceEntry(), this);	    }	}    }    public boolean isInitialized() {	return (values != null);    }    /**     * Set the values. (MUST be called before initialize).     * @param defs The Hashtable containing the values.     */    public void pickleValues(Hashtable defs) {	Object nvalues[] = new Object[attributes.length];	for (int i = 0 ; i < nvalues.length ; i++) {	    String attrname = attributes[i].getName() ;	    Object def      = defs.get(attrname) ;	    if ((i == ATTR_HELP_URL) && (def != null) 		&& (def instanceof String)) {		nvalues[i] = ((String) def).intern();	    } else {	    		nvalues[i] = def ;	    }	    	}	this.values = nvalues ;    }   /**     * Initialization method for attribute holders.     * This method allows to initialize an attribute holder by providing     * its attributes values through a Hashtable mapping attribute names     * to attribute values.     * @param defs The Hashtable containing the default values.     */    public void initialize(Hashtable defs) {	Object values[] = ((this.values == null)			   ? new Object[attributes.length] 			   : this.values);	for (int i = 0 ; i < values.length ; i++) {	    String attrname = attributes[i].getName() ;	    Object def      = defs.get(attrname) ;	    if ( values[i] == null ) {		// for help_url, we can save lots of space by using 		// String.intern()		if ((i == ATTR_HELP_URL) && (def != null) 		        && (def instanceof String)) {		    values[i] = ((String) def).intern();		} else {	    		    values[i] = def ;		}	    }	}	initialize(values) ;    }    public void initialize(Object values[]) {	super.initialize(values);    }    /**     * Create an empty resource instance.     * Initialize the instance attributes description, and its values.     */    public Resource() {	super() ;    }}

⌨️ 快捷键说明

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