FileDocCategorySizeDatePackage
ResourceAttributes.javaAPI DocGlassfish v2 API26196Fri May 04 22:33:00 BST 2007org.apache.naming.resources

ResourceAttributes

public class ResourceAttributes extends Object implements Attributes
Attributes implementation.
author
Remy Maucherat
version
$Revision: 1.4 $

Fields Summary
public static final String
CREATION_DATE
Creation date.
public static final String
ALTERNATE_CREATION_DATE
Creation date.
public static final String
LAST_MODIFIED
Last modification date.
public static final String
ALTERNATE_LAST_MODIFIED
Last modification date.
public static final String
NAME
Name.
public static final String
TYPE
Type.
public static final String
ALTERNATE_TYPE
Type.
public static final String
SOURCE
Source.
public static final String
CONTENT_TYPE
MIME type of the content.
public static final String
CONTENT_LANGUAGE
Content language.
public static final String
CONTENT_LENGTH
Content length.
public static final String
ALTERNATE_CONTENT_LENGTH
Content length.
public static final String
ETAG
ETag.
public static final String
COLLECTION_TYPE
Collection type.
protected static final SimpleDateFormat
format
HTTP date format.
protected static final SimpleDateFormat[]
formats
Date formats using for Date parsing.
protected static final TimeZone
gmtZone
protected boolean
collection
Collection flag.
protected long
contentLength
Content length.
protected long
creation
Creation time.
protected Date
creationDate
Creation date.
protected long
lastModified
Last modified time.
protected Date
lastModifiedDate
Last modified date.
protected String
lastModifiedHttp
Last modified date in HTTP format.
protected String
mimeType
MIME type.
protected String
name
Name.
protected String
weakETag
Weak ETag.
protected String
strongETag
Strong ETag.
protected Attributes
attributes
External attributes.
Constructors Summary
public ResourceAttributes()
Default constructor.



                  
     

        format.setTimeZone(gmtZone);

        formats[0].setTimeZone(gmtZone);
        formats[1].setTimeZone(gmtZone);
        formats[2].setTimeZone(gmtZone);

    
    
public ResourceAttributes(Attributes attributes)
Merges with another attribute set.

        this.attributes = attributes;
    
Methods Summary
public java.lang.Objectclone()
Clone the attributes object (WARNING: fake cloning).

        return this;
    
public javax.naming.directory.Attributeget(java.lang.String attrID)
Get attribute.

        if (attributes == null) {
            if (attrID.equals(CREATION_DATE)) {
                return new BasicAttribute(CREATION_DATE, getCreationDate());
            } else if (attrID.equals(ALTERNATE_CREATION_DATE)) {
                return new BasicAttribute(ALTERNATE_CREATION_DATE, 
                                          getCreationDate());
            } else if (attrID.equals(LAST_MODIFIED)) {
                return new BasicAttribute(LAST_MODIFIED, 
                                          getLastModifiedDate());
            } else if (attrID.equals(ALTERNATE_LAST_MODIFIED)) {
                return new BasicAttribute(ALTERNATE_LAST_MODIFIED,
                                          getLastModifiedDate());
            } else if (attrID.equals(NAME)) {
                return new BasicAttribute(NAME, getName());
            } else if (attrID.equals(TYPE)) {
                return new BasicAttribute(TYPE, getResourceType());
            } else if (attrID.equals(ALTERNATE_TYPE)) {
                return new BasicAttribute(ALTERNATE_TYPE, getResourceType());
            } else if (attrID.equals(CONTENT_LENGTH)) {
                return new BasicAttribute(CONTENT_LENGTH, 
                                          Long.valueOf(getContentLength()));
            } else if (attrID.equals(ALTERNATE_CONTENT_LENGTH)) {
                return new BasicAttribute(ALTERNATE_CONTENT_LENGTH, 
                                          Long.valueOf(getContentLength()));
            }
        } else {
            return attributes.get(attrID);
        }
        return null;
    
public javax.naming.NamingEnumerationgetAll()
Get all attributes.

        if (attributes == null) {
            Vector attributes = new Vector();
            attributes.addElement(new BasicAttribute
                                  (CREATION_DATE, getCreationDate()));
            attributes.addElement(new BasicAttribute
                                  (LAST_MODIFIED, getLastModifiedDate()));
            attributes.addElement(new BasicAttribute(NAME, getName()));
            attributes.addElement(new BasicAttribute(TYPE, getResourceType()));
            attributes.addElement
                (new BasicAttribute(CONTENT_LENGTH, 
                                    Long.valueOf(getContentLength())));
            return new RecyclableNamingEnumeration(attributes);
        } else {
            return attributes.getAll();
        }
    
public longgetContentLength()
Get content length.

return
content length value

        if (contentLength != -1L)
            return contentLength;
        if (attributes != null) {
            Attribute attribute = attributes.get(CONTENT_LENGTH);
            if (attribute != null) {
                try {
                    Object value = attribute.get();
                    if (value instanceof Long) {
                        contentLength = ((Long) value).longValue();
                    } else {
                        try {
                            contentLength = Long.parseLong(value.toString());
                        } catch (NumberFormatException e) {
                            ; // Ignore
                        }
                    }
                } catch (NamingException e) {
                    ; // No value for the attribute
                }
            }
        }
        return contentLength;
    
public longgetCreation()
Get creation time.

return
creation time value

        if (creation != -1L)
            return creation;
        if (creationDate != null)
            return creationDate.getTime();
        if (attributes != null) {
            Attribute attribute = attributes.get(CREATION_DATE);
            if (attribute != null) {
                try {
                    Object value = attribute.get();
                    if (value instanceof Long) {
                        creation = ((Long) value).longValue();
                    } else if (value instanceof Date) {
                        creation = ((Date) value).getTime();
                        creationDate = (Date) value;
                    } else {
                        String creationDateValue = value.toString();
                        Date result = null;
                        // Parsing the HTTP Date
                        for (int i = 0; (result == null) && 
                                 (i < formats.length); i++) {
                            try {
                                result = formats[i].parse(creationDateValue);
                            } catch (ParseException e) {
                                ;
                            }
                        }
                        if (result != null) {
                            creation = result.getTime();
                            creationDate = result;
                        }
                    }
                } catch (NamingException e) {
                    ; // No value for the attribute
                }
            }
        }
        return creation;
    
public java.util.DategetCreationDate()
Get creation date.

return
Creation date value

        if (creationDate != null)
            return creationDate;
        if (creation != -1L) {
            creationDate = new Date(creation);
            return creationDate;
        }
        if (attributes != null) {
            Attribute attribute = attributes.get(CREATION_DATE);
            if (attribute != null) {
                try {
                    Object value = attribute.get();
                    if (value instanceof Long) {
                        creation = ((Long) value).longValue();
                        creationDate = new Date(creation);
                    } else if (value instanceof Date) {
                        creation = ((Date) value).getTime();
                        creationDate = (Date) value;
                    } else {
                        String creationDateValue = value.toString();
                        Date result = null;
                        // Parsing the HTTP Date
                        for (int i = 0; (result == null) && 
                                 (i < formats.length); i++) {
                            try {
                                result = formats[i].parse(creationDateValue);
                            } catch (ParseException e) {
                                ;
                            }
                        }
                        if (result != null) {
                            creation = result.getTime();
                            creationDate = result;
                        }
                    }
                } catch (NamingException e) {
                    ; // No value for the attribute
                }
            }
        }
        return creationDate;
    
public java.lang.StringgetETag()
Get ETag.

return
Weak ETag

        return getETag(false);
    
public java.lang.StringgetETag(boolean strong)
Get ETag.

param
strong If true, the strong ETag will be returned
return
ETag

        String result = null;
        if (attributes != null) {
            Attribute attribute = attributes.get(ETAG);
            if (attribute != null) {
                try {
                    result = attribute.get().toString();
                } catch (NamingException e) {
                    ; // No value for the attribute
                }
            }
        }
        if (strong) {
            // The strong ETag must always be calculated by the resources
            result = strongETag;
        } else {
            // The weakETag is contentLenght + lastModified
            if (weakETag == null) {
                weakETag = "W/\"" + getContentLength() + "-" 
                    + getLastModified() + "\"";
            }
            result = weakETag;
        }
        return result;
    
public javax.naming.NamingEnumerationgetIDs()
Get all attribute IDs.

        if (attributes == null) {
            Vector attributeIDs = new Vector();
            attributeIDs.addElement(CREATION_DATE);
            attributeIDs.addElement(LAST_MODIFIED);
            attributeIDs.addElement(NAME);
            attributeIDs.addElement(TYPE);
            attributeIDs.addElement(CONTENT_LENGTH);
            return new RecyclableNamingEnumeration(attributeIDs);
        } else {
            return attributes.getIDs();
        }
    
public longgetLastModified()
Get last modified time.

return
lastModified time value

        if (lastModified != -1L)
            return lastModified;
        if (lastModifiedDate != null)
            return lastModifiedDate.getTime();
        if (attributes != null) {
            Attribute attribute = attributes.get(LAST_MODIFIED);
            if (attribute != null) {
                try {
                    Object value = attribute.get();
                    if (value instanceof Long) {
                        lastModified = ((Long) value).longValue();
                    } else if (value instanceof Date) {
                        lastModified = ((Date) value).getTime();
                        lastModifiedDate = (Date) value;
                    } else {
                        String lastModifiedDateValue = value.toString();
                        Date result = null;
                        // Parsing the HTTP Date
                        for (int i = 0; (result == null) && 
                                 (i < formats.length); i++) {
                            try {
                                result = 
                                    formats[i].parse(lastModifiedDateValue);
                            } catch (ParseException e) {
                                ;
                            }
                        }
                        if (result != null) {
                            lastModified = result.getTime();
                            lastModifiedDate = result;
                        }
                    }
                } catch (NamingException e) {
                    ; // No value for the attribute
                }
            }
        }
        return lastModified;
    
public java.util.DategetLastModifiedDate()
Get lastModified date.

return
LastModified date value

        if (lastModifiedDate != null)
            return lastModifiedDate;
        if (lastModified != -1L) {
            lastModifiedDate = new Date(lastModified);
            return lastModifiedDate;
        }
        if (attributes != null) {
            Attribute attribute = attributes.get(LAST_MODIFIED);
            if (attribute != null) {
                try {
                    Object value = attribute.get();
                    if (value instanceof Long) {
                        lastModified = ((Long) value).longValue();
                        lastModifiedDate = new Date(lastModified);
                    } else if (value instanceof Date) {
                        lastModified = ((Date) value).getTime();
                        lastModifiedDate = (Date) value;
                    } else {
                        String lastModifiedDateValue = value.toString();
                        Date result = null;
                        // Parsing the HTTP Date
                        for (int i = 0; (result == null) && 
                                 (i < formats.length); i++) {
                            try {
                                result = 
                                    formats[i].parse(lastModifiedDateValue);
                            } catch (ParseException e) {
                                ;
                            }
                        }
                        if (result != null) {
                            lastModified = result.getTime();
                            lastModifiedDate = result;
                        }
                    }
                } catch (NamingException e) {
                    ; // No value for the attribute
                }
            }
        }
        return lastModifiedDate;
    
public java.lang.StringgetLastModifiedHttp()

return
Returns the lastModifiedHttp.

        if (lastModifiedHttp != null)
            return lastModifiedHttp;
        Date modifiedDate = getLastModifiedDate();
        if (modifiedDate == null) {
            modifiedDate = getCreationDate();
        }
        if (modifiedDate == null) {
            modifiedDate = new Date();
        }
        synchronized (format) {
            lastModifiedHttp = format.format(modifiedDate);
        }
        return lastModifiedHttp;
    
public java.lang.StringgetMimeType()

return
Returns the mimeType.

        return mimeType;
    
public java.lang.StringgetName()
Get name.

return
Name value

        if (name != null)
            return name;
        if (attributes != null) {
            Attribute attribute = attributes.get(NAME);
            if (attribute != null) {
                try {
                    name = attribute.get().toString();
                } catch (NamingException e) {
                    ; // No value for the attribute
                }
            }
        }
        return name;
    
public java.lang.StringgetResourceType()
Get resource type.

return
String resource type

        String result = null;
        if (attributes != null) {
            Attribute attribute = attributes.get(TYPE);
            if (attribute != null) {
                try {
                    result = attribute.get().toString();
                } catch (NamingException e) {
                    ; // No value for the attribute
                }
            }
        }
        if (result == null) {
            if (collection)
                result = COLLECTION_TYPE;
            else
                result = "";
        }
        return result;
    
public booleanisCaseIgnored()
Case sensitivity.

        return false;
    
public booleanisCollection()
Is collection.



    // ------------------------------------------------------------- Properties


           
       
        if (attributes != null) {
            return (getResourceType().equals(COLLECTION_TYPE));
        } else {
            return (collection);
        }
    
public javax.naming.directory.Attributeput(javax.naming.directory.Attribute attribute)
Put attribute.

        if (attributes == null) {
            try {
                return put(attribute.getID(), attribute.get());
            } catch (NamingException e) {
                return null;
            }
        } else {
            return attributes.put(attribute);
        }
    
public javax.naming.directory.Attributeput(java.lang.String attrID, java.lang.Object val)
Put attribute.

        if (attributes == null) {
            return null; // No reason to implement this
        } else {
            return attributes.put(attrID, val);
        }
    
public javax.naming.directory.Attributeremove(java.lang.String attrID)
Remove attribute.

        if (attributes == null) {
            return null; // No reason to implement this
        } else {
            return attributes.remove(attrID);
        }
    
public voidsetCollection(boolean collection)
Set collection flag.

return
value of the collection flag

        this.collection = collection;
        if (attributes != null) {
            String value = "";
            if (collection)
                value = COLLECTION_TYPE;
            attributes.put(TYPE, value);
        }
    
public voidsetContentLength(long contentLength)
Set content length.

param
contentLength New content length value

        this.contentLength = contentLength;
        if (attributes != null)
            attributes.put(CONTENT_LENGTH, Long.valueOf(contentLength));
    
public voidsetCreation(long creation)
Set creation.

param
creation New creation value

        this.creation = creation;
        this.creationDate = null;
        if (attributes != null)
            attributes.put(CREATION_DATE, new Date(creation));
    
public voidsetCreationDate(java.util.Date creationDate)
Creation date mutator.

param
creationDate New creation date

        this.creation = creationDate.getTime();
        this.creationDate = creationDate;
        if (attributes != null)
            attributes.put(CREATION_DATE, creationDate);
    
public voidsetETag(java.lang.String eTag)
Set strong ETag.

        this.strongETag = eTag;
        if (attributes != null)
            attributes.put(ETAG, eTag);
    
public voidsetLastModified(long lastModified)
Set last modified.

param
lastModified New last modified value

        this.lastModified = lastModified;
        this.lastModifiedDate = null;
        if (attributes != null)
            attributes.put(LAST_MODIFIED, new Date(lastModified));
    
public voidsetLastModified(java.util.Date lastModified)
Set last modified date.

param
lastModified New last modified date value
deprecated

        setLastModifiedDate(lastModified);
    
public voidsetLastModifiedDate(java.util.Date lastModifiedDate)
Last modified date mutator.

param
lastModifiedDate New last modified date

        this.lastModified = lastModifiedDate.getTime();
        this.lastModifiedDate = lastModifiedDate;
        if (attributes != null)
            attributes.put(LAST_MODIFIED, lastModifiedDate);
    
public voidsetLastModifiedHttp(java.lang.String lastModifiedHttp)

param
lastModifiedHttp The lastModifiedHttp to set.

        this.lastModifiedHttp = lastModifiedHttp;
    
public voidsetMimeType(java.lang.String mimeType)

param
mimeType The mimeType to set.

        this.mimeType = mimeType;
    
public voidsetName(java.lang.String name)
Set name.

param
name New name value

        this.name = name;
        if (attributes != null)
            attributes.put(NAME, name);
    
public voidsetResourceType(java.lang.String resourceType)
Type mutator.

param
resourceType New resource type

        collection = resourceType.equals(COLLECTION_TYPE);
        if (attributes != null)
            attributes.put(TYPE, resourceType);
    
public intsize()
Retrieves the number of attributes in the attribute set.

        if (attributes == null) {
            return 5;
        } else {
            return attributes.size();
        }