FileDocCategorySizeDatePackage
ArchiveResource.javaAPI DocApache Ant 1.708097Wed Dec 13 06:16:22 GMT 2006org.apache.tools.ant.types.resources

ArchiveResource

public abstract class ArchiveResource extends org.apache.tools.ant.types.Resource
A Resource representation of an entry inside an archive.
since
Ant 1.7

Fields Summary
private static final int
NULL_ARCHIVE
private org.apache.tools.ant.types.Resource
archive
private boolean
haveEntry
private boolean
modeSet
private int
mode
Constructors Summary
public ArchiveResource()
Default constructor.


           
      
    
public ArchiveResource(File a)
Construct a ArchiveResource representing the specified entry in the specified archive.

param
a the archive as File.

        this(a, false);
    
public ArchiveResource(File a, boolean withEntry)
Construct a ArchiveResource representing the specified entry in the specified archive.

param
a the archive as File.
param
withEntry if the entry has been specified.

        setArchive(a);
        haveEntry = withEntry;
    
public ArchiveResource(org.apache.tools.ant.types.Resource a, boolean withEntry)
Construct a ArchiveResource representing the specified entry in the specified archive.

param
a the archive as Resource.
param
withEntry if the entry has been specified.

        addConfigured(a);
        haveEntry = withEntry;
    
Methods Summary
public voidaddConfigured(org.apache.tools.ant.types.ResourceCollection a)
Sets the archive that holds this as a single element Resource collection.

param
a the archive as a single element Resource collection.

        checkChildrenAllowed();
        if (archive != null) {
            throw new BuildException("you must not specify more than one"
                                     + " archive");
        }
        if (a.size() != 1) {
            throw new BuildException("only single argument resource collections"
                                     + " are supported as archives");
        }
        archive = (Resource) a.iterator().next();
    
private synchronized voidcheckEntry()

        if (haveEntry) {
            return;
        }
        String name = getName();
        if (name == null) {
            throw new BuildException("entry name not set");
        }
        Resource r = getArchive();
        if (r == null) {
            throw new BuildException("archive attribute not set");
        }
        if (!r.isExists()) {
            throw new BuildException(r.toString() + " does not exist.");
        }
        if (r.isDirectory()) {
            throw new BuildException(r + " denotes a directory.");
        }
        fetchEntry();
        haveEntry = true;
    
public intcompareTo(java.lang.Object another)
Compare this ArchiveResource to another Resource.

param
another the other Resource against which to compare.
return
a negative integer, zero, or a positive integer as this Resource is less than, equal to, or greater than the specified Resource.

        return this.equals(another) ? 0 : super.compareTo(another);
    
public booleanequals(java.lang.Object another)
Compare another Object to this ArchiveResource for equality.

param
another the other Object to compare.
return
true if another is a Resource representing the same entry in the same archive.

        if (this == another) {
            return true;
        }
        if (isReference()) {
            return getCheckedRef().equals(another);
        }
        if (!(another.getClass().equals(getClass()))) {
            return false;
        }
        ArchiveResource r = (ArchiveResource) another;
        return getArchive().equals(r.getArchive())
            && getName().equals(r.getName());
    
protected abstract voidfetchEntry()
fetches information from the named entry inside the archive.

public org.apache.tools.ant.types.ResourcegetArchive()
Get the archive that holds this Resource.

return
the archive as a Resource.

        return isReference()
            ? ((ArchiveResource) getCheckedRef()).getArchive() : archive;
    
public longgetLastModified()
Get the last modified date of this Resource.

return
the last modification date.

        if (isReference()) {
            return ((Resource) getCheckedRef()).getLastModified();
        }
        checkEntry();
        return super.getLastModified();
    
public intgetMode()
Get the file or dir mode for this Resource.

return
integer representation of Unix permission mask.

        if (isReference()) {
            return ((ArchiveResource) getCheckedRef()).getMode();
        }
        checkEntry();
        return mode;
    
public longgetSize()
Get the size of this Resource.

return
the long size of this Resource.

        if (isReference()) {
            return ((Resource) getCheckedRef()).getSize();
        }
        checkEntry();
        return super.getSize();
    
public inthashCode()
Get the hash code for this Resource.

return
hash code as int.

        return super.hashCode()
            * (getArchive() == null ? NULL_ARCHIVE : getArchive().hashCode());
    
public booleanisDirectory()
Learn whether this Resource represents a directory.

return
boolean flag indicating whether the entry is a directory.

        if (isReference()) {
            return ((Resource) getCheckedRef()).isDirectory();
        }
        checkEntry();
        return super.isDirectory();
    
public booleanisExists()
Find out whether this Resource represents an existing Resource.

return
boolean existence flag.

        if (isReference()) {
            return ((Resource) getCheckedRef()).isExists();
        }
        checkEntry();
        return super.isExists();
    
public voidsetArchive(java.io.File a)
Set the archive that holds this Resource.

param
a the archive as a File.

        checkAttributesAllowed();
        archive = new FileResource(a);
    
public voidsetMode(int mode)
Sets the file or dir mode for this resource.

param
mode integer representation of Unix permission mask.

        checkAttributesAllowed();
        this.mode = mode;
        modeSet = true;
    
public voidsetRefid(org.apache.tools.ant.types.Reference r)
Overrides the super version.

param
r the Reference to set.

        if (archive != null || modeSet) {
            throw tooManyAttributes();
        }
        super.setRefid(r);
    
public java.lang.StringtoString()
Format this Resource as a String.

return
String representatation of this Resource.

        return isReference() ? getCheckedRef().toString()
            : getArchive().toString() + ':" + getName();