KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > wings > Resource


1 /*
2  * $Id: Resource.java,v 1.4 2004/12/01 07:54:06 hengels 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;
15
16 import org.wings.session.Session;
17 import org.wings.session.SessionManager;
18
19 import java.io.Serializable JavaDoc;
20 import java.util.Collection JavaDoc;
21 import java.util.Map JavaDoc;
22
23 /*
24  * Diese Klasse ist nur ein Wrapper, um Eingabestroeme von Grafiken mit dem
25  * ExternalizeManager mit der richtigen Endung und ohne Umweg einer neuen
26  * Codierung (die z.B. keine Transparenz unterstuetzt) uebers WWW zugreifbar zu
27  * machen. Zugleich muss diese Klasse aber auch zu der API der Componenten
28  * passen, also ein Image bzw. ImageIcon sein. ImageIcon ist einfacher zu
29  * benutzen und implementiert schon alles was benoetigt wird...
30  */

31
32 /**
33  * @author <a HREF="mailto:haaf@mercatis.de">Armin Haaf</a>
34  * @author <a HREF="mailto:H.Zeller@acm.org">Henner Zeller</a>
35  * @version $Revision: 1.4 $
36  */

37 public abstract class Resource implements Serializable JavaDoc, URLResource, Renderable {
38     private final transient static org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog("org.wings");
39
40
41     protected String JavaDoc id;
42
43     protected String JavaDoc extension;
44
45     protected String JavaDoc mimeType;
46
47     protected Collection JavaDoc headers;
48
49     protected Resource(String JavaDoc extension, String JavaDoc mimeType) {
50         this.extension = extension;
51         this.mimeType = mimeType;
52     }
53
54     protected Resource() {
55     }
56
57
58     public int getLength() {
59         return -1;
60     }
61
62
63     public String JavaDoc getExtension() {
64         return extension;
65     }
66
67     /**
68      * Returns the mime type of this resource.
69      */

70     public String JavaDoc getMimeType() {
71         return mimeType;
72     }
73
74     public void setHeaders(Collection JavaDoc/*<Map.Entry>*/ headers) {
75         this.headers = headers;
76     }
77
78     public Collection JavaDoc getHeaders() {
79         return headers;
80     }
81
82
83     public String JavaDoc getId() {
84         return id;
85     }
86
87     public abstract SimpleURL getURL();
88
89
90     public String JavaDoc toString() {
91         return getId();
92     }
93
94     public Session getSession() {
95         return SessionManager.getSession();
96     }
97
98     public static final class HeaderEntry implements Map.Entry JavaDoc {
99         final Object JavaDoc key;
100         Object JavaDoc value;
101
102         /**
103          * Create new entry.
104          */

105         public HeaderEntry(Object JavaDoc k, Object JavaDoc v) {
106             key = k;
107             value = v;
108         }
109
110         public Object JavaDoc getKey() {
111             return key;
112         }
113
114         public Object JavaDoc getValue() {
115             return value;
116         }
117
118         public Object JavaDoc setValue(Object JavaDoc newValue) {
119             Object JavaDoc oldValue = value;
120             value = newValue;
121             return oldValue;
122         }
123
124         public boolean equals(Object JavaDoc o) {
125             if (!(o instanceof Map.Entry JavaDoc))
126                 return false;
127             Map.Entry JavaDoc e = (Map.Entry JavaDoc) o;
128             Object JavaDoc k1 = getKey();
129             Object JavaDoc k2 = e.getKey();
130             if (k1 == k2 || (k1 != null && k1.equals(k2))) {
131                 Object JavaDoc v1 = getValue();
132                 Object JavaDoc v2 = e.getValue();
133                 if (v1 == v2 || (v1 != null && v1.equals(v2)))
134                     return true;
135             }
136             return false;
137         }
138
139         public int hashCode() {
140             return (key == null ? 0 : key.hashCode()) ^
141                     (value == null ? 0 : value.hashCode());
142         }
143
144         public String JavaDoc toString() {
145             return getKey() + "=" + getValue();
146         }
147
148     }
149
150 }
151
152
153
Popular Tags