001: /*
002: * Copyright 2000,2005 wingS development team.
003: *
004: * This file is part of wingS (http://wingsframework.org).
005: *
006: * wingS is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU Lesser General Public License
008: * as published by the Free Software Foundation; either version 2.1
009: * of the License, or (at your option) any later version.
010: *
011: * Please see COPYING for the complete licence.
012: */
013: package org.wings.externalizer;
014:
015: import java.util.Collection;
016:
017: /**
018: * @author <a href="mailto:haaf@mercatis.de">Armin Haaf</a>
019: */
020: public class ExternalizedResource {
021: /*
022: * the following two members are the key elements,
023: * used by hashCode() and equals();
024: */
025: private final Object extObject;
026: private final Externalizer externalizer;
027:
028: private final String mimeType;
029: private final int flags;
030: private final long lastModified;
031: private final Collection headers;
032: private String id;
033:
034: public ExternalizedResource(Object obj, Externalizer ext,
035: String mimeType, Collection headers, int flags) {
036: extObject = obj;
037: externalizer = ext;
038: this .mimeType = mimeType;
039: this .flags = flags;
040:
041: if (externalizer == null || extObject == null) {
042: throw new IllegalArgumentException(
043: "no externalizer or null object");
044: }
045:
046: lastModified = System.currentTimeMillis();
047: this .headers = headers;
048: }
049:
050: public final String getMimeType() {
051: return mimeType == null ? externalizer.getMimeType(extObject)
052: : mimeType;
053: }
054:
055: public final Object getObject() {
056: return extObject;
057: }
058:
059: public final Externalizer getExternalizer() {
060: return externalizer;
061: }
062:
063: public final Collection getHeaders() {
064: return headers == null ? externalizer.getHeaders(extObject)
065: : headers;
066: }
067:
068: public final boolean deliverOnce() {
069: return (flags & AbstractExternalizeManager.REQUEST) > 0;
070: }
071:
072: public final boolean isFinal() {
073: return (((flags & AbstractExternalizeManager.FINAL) > 0 || externalizer
074: .isFinal(extObject))
075: // if flags is request only, then object is not final!!
076: && (flags & AbstractExternalizeManager.REQUEST) == 0);
077: }
078:
079: public final String getExtension() {
080: return externalizer.getExtension(extObject);
081: }
082:
083: public final int getFlags() {
084: return flags;
085: }
086:
087: public final long getLastModified() {
088: if (isFinal())
089: return lastModified;
090: else
091: return System.currentTimeMillis();
092: }
093:
094: void setId(String s) {
095: id = s;
096: }
097:
098: public String getId() {
099: return id;
100: }
101:
102: public String toString() {
103: return "Externalized Info";
104: }
105:
106: /**
107: * The HashCode of the externalized resource is
108: * the hash code of the to be externalized object
109: * (the externalized resource). Together with the implementation
110: * of the {@link #equals(Object)}-Method, this makes sure, that
111: * the same resource gets the same ID.
112: *
113: * @return the has code of the externalized object.
114: */
115: @Override
116: public final int hashCode() {
117: return extObject.hashCode();
118: }
119:
120: /**
121: * If the managed externalized resource and the
122: * externalized manager are the same, then both
123: * ExternalizedResource objects are regarded equal.
124: *
125: * @return true, if the other externalized resource equals
126: * this resource regarding the key members.
127: */
128: public final boolean equals(ExternalizedResource e) {
129: return (extObject.equals(e.extObject) && externalizer
130: .equals(e.externalizer));
131: }
132:
133: /**
134: * @return true, if the other object is an ExternalizedResource
135: * and {@link #equals(ExternalizedResource)} returns true.
136: */
137: @Override
138: public final boolean equals(Object o) {
139: if (o instanceof ExternalizedResource) {
140: return equals((ExternalizedResource) o);
141: }
142: return false;
143: }
144:
145: }
|