KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > wings > externalizer > ExternalizedResource


1 /*
2  * $Id: ExternalizedResource.java,v 1.5 2005/04/08 15:06:23 blueshift Exp $
3  * Copyright 2000,2005 wingS development team.
4  *
5  * This file is part of wingS (http://www.j-wings.org).
6  *
7  * wingS is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation; either version 2.1
10  * of the License, or (at your option) any later version.
11  *
12  * Please see COPYING for the complete licence.
13  */

14 package org.wings.externalizer;
15
16 import java.util.Collection JavaDoc;
17
18 /**
19  * @author <a HREF="mailto:haaf@mercatis.de">Armin Haaf</a>
20  * @version $Revision: 1.5 $
21  */

22 public class ExternalizedResource {
23     /*
24      * the following two members are the key elements,
25      * used by hashCode() and equals();
26      */

27     private final Object JavaDoc extObject;
28     private final Externalizer externalizer;
29
30     private final String JavaDoc mimeType;
31     private final int flags;
32     private final long lastModified;
33     private final Collection JavaDoc headers;
34     private String JavaDoc id;
35
36     public ExternalizedResource(Object JavaDoc obj, Externalizer ext,
37                                 String JavaDoc mimeType, Collection JavaDoc headers, int flags) {
38         extObject = obj;
39         externalizer = ext;
40         this.mimeType = mimeType;
41         this.flags = flags;
42
43         if (externalizer == null || extObject == null) {
44             throw new IllegalArgumentException JavaDoc("no externalizer or null object");
45         }
46
47         lastModified = System.currentTimeMillis();
48         this.headers = headers;
49     }
50
51
52     public final String JavaDoc getMimeType() {
53         return mimeType == null ? externalizer.getMimeType(extObject) : mimeType;
54     }
55
56
57     public final Object JavaDoc getObject() {
58         return extObject;
59     }
60
61
62     public final Externalizer getExternalizer() {
63         return externalizer;
64     }
65
66
67     public final Collection JavaDoc getHeaders() {
68         return headers == null ? externalizer.getHeaders(extObject) : headers;
69     }
70
71
72     public final boolean deliverOnce() {
73         return (flags & AbstractExternalizeManager.REQUEST) > 0;
74     }
75
76
77     public final boolean isFinal() {
78         return (((flags & AbstractExternalizeManager.FINAL) > 0
79                 || externalizer.isFinal(extObject))
80                 // if flags is request only, then object is not final!!
81
&& (flags & AbstractExternalizeManager.REQUEST) == 0);
82     }
83
84
85     public final String JavaDoc getExtension() {
86         return externalizer.getExtension(extObject);
87     }
88
89
90     public final int getFlags() {
91         return flags;
92     }
93
94
95     public final long getLastModified() {
96         if (isFinal())
97             return lastModified;
98         else
99             return -1;
100     }
101
102
103     void setId(String JavaDoc s) {
104         id = s;
105     }
106
107
108     public String JavaDoc getId() {
109         return id;
110     }
111
112
113     public String JavaDoc toString() {
114         return "Externalized Info";
115     }
116
117     /**
118      * The HashCode of the externalized resource is
119      * the hash code of the to be externalized object
120      * (the externalized resource). Together with the implementation
121      * of the {@link #equals(Object)}-Method, this makes sure, that
122      * the same resource gets the same ID.
123      *
124      * @return the has code of the externalized object.
125      */

126     public final int hashCode() {
127         return extObject.hashCode();
128     }
129
130     /**
131      * If the managed externalized resource and the
132      * externalized manager are the same, then both
133      * ExternalizedResource objects are regarded equal.
134      *
135      * @return true, if the other externalized resource equals
136      * this resource regarding the key members.
137      */

138     public final boolean equals(ExternalizedResource e) {
139         return (extObject.equals(e.extObject)
140                 && externalizer.equals(e.externalizer));
141     }
142
143     /**
144      * @return true, if the other object is an ExternalizedResource
145      * and {@link #equals(ExternalizedResource)} returns true.
146      */

147     public final boolean equals(Object JavaDoc o) {
148         if (o instanceof ExternalizedResource) {
149             return equals((ExternalizedResource) o);
150         }
151         return false;
152     }
153
154 }
155
156
157
158
159
160
161
Popular Tags