Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
CachedAsset |
|
| 2.1818181818181817;2.182 |
1 | // Copyright 2004, 2005 The Apache Software Foundation |
|
2 | // |
|
3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
|
4 | // you may not use this file except in compliance with the License. |
|
5 | // You may obtain a copy of the License at |
|
6 | // |
|
7 | // http://www.apache.org/licenses/LICENSE-2.0 |
|
8 | // |
|
9 | // Unless required by applicable law or agreed to in writing, software |
|
10 | // distributed under the License is distributed on an "AS IS" BASIS, |
|
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
12 | // See the License for the specific language governing permissions and |
|
13 | // limitations under the License. |
|
14 | package org.apache.tapestry.asset; |
|
15 | ||
16 | ||
17 | /** |
|
18 | * Wrapper around cached asset resource. |
|
19 | * |
|
20 | * @author jkuhnert |
|
21 | */ |
|
22 | public class CachedAsset |
|
23 | { |
|
24 | ||
25 | /** |
|
26 | * The raw data for this resource. |
|
27 | */ |
|
28 | private byte[] _data; |
|
29 | ||
30 | /** |
|
31 | * The gzipped version of the raw data. |
|
32 | */ |
|
33 | private byte[] _gzipData; |
|
34 | ||
35 | /** |
|
36 | * Path to the resource. |
|
37 | */ |
|
38 | private String _path; |
|
39 | ||
40 | /** |
|
41 | * The last known modification time of the data this cached object |
|
42 | * represents. Is used to invalidate cache entries. |
|
43 | */ |
|
44 | private long _lastModified; |
|
45 | ||
46 | /** |
|
47 | * Creates a new cachable asset entry. |
|
48 | * |
|
49 | * @param path |
|
50 | * The path string of the resource. |
|
51 | * @param lastModified |
|
52 | * The last known modification time of the data this cached object |
|
53 | * represents. Is used to invalidate cache entries. |
|
54 | * @param data |
|
55 | * The data representation to cache. |
|
56 | * @param gzipData |
|
57 | * The optional gzip'ed data. |
|
58 | */ |
|
59 | public CachedAsset(String path, long lastModified, byte[] data, byte[] gzipData) |
|
60 | 1 | { |
61 | 1 | _path = path; |
62 | 1 | _lastModified = lastModified; |
63 | 1 | _data = data; |
64 | 1 | _gzipData = gzipData; |
65 | 1 | } |
66 | ||
67 | /** |
|
68 | * @return Returns the data. |
|
69 | */ |
|
70 | public byte[] getData() |
|
71 | { |
|
72 | 0 | return _data; |
73 | } |
|
74 | ||
75 | /** |
|
76 | * @param data The data to set. |
|
77 | */ |
|
78 | public void setData(byte[] data) |
|
79 | { |
|
80 | 1 | _data = data; |
81 | 1 | } |
82 | ||
83 | ||
84 | /** |
|
85 | * @return Returns the gzipData. |
|
86 | */ |
|
87 | public byte[] getGzipData() |
|
88 | { |
|
89 | 0 | return _gzipData; |
90 | } |
|
91 | ||
92 | ||
93 | /** |
|
94 | * @param gzipData The gzipData to set. |
|
95 | */ |
|
96 | public void setGzipData(byte[] gzipData) |
|
97 | { |
|
98 | 0 | _gzipData = gzipData; |
99 | 0 | } |
100 | ||
101 | ||
102 | /** |
|
103 | * @return Returns the path. |
|
104 | */ |
|
105 | public String getPath() |
|
106 | { |
|
107 | 0 | return _path; |
108 | } |
|
109 | ||
110 | /** |
|
111 | * @return Returns the lastModified. |
|
112 | */ |
|
113 | public long getLastModified() |
|
114 | { |
|
115 | 0 | return _lastModified; |
116 | } |
|
117 | ||
118 | /** |
|
119 | * Clears the currently cached data and resets the last modified time. |
|
120 | * |
|
121 | * @param lastModified The lastModified to set. |
|
122 | */ |
|
123 | public void clear(long lastModified) |
|
124 | { |
|
125 | 0 | _lastModified = lastModified; |
126 | 0 | _data = null; |
127 | 0 | _gzipData = null; |
128 | 0 | } |
129 | ||
130 | /** |
|
131 | * {@inheritDoc} |
|
132 | */ |
|
133 | public int hashCode() |
|
134 | { |
|
135 | 0 | final int prime = 31; |
136 | 0 | int result = 1; |
137 | 0 | result = prime * result + ((_path == null) ? 0 : _path.hashCode()); |
138 | 0 | return result; |
139 | } |
|
140 | ||
141 | /** |
|
142 | * {@inheritDoc} |
|
143 | */ |
|
144 | public boolean equals(Object obj) |
|
145 | { |
|
146 | 0 | if (this == obj) return true; |
147 | 0 | if (obj == null) return false; |
148 | 0 | if (getClass() != obj.getClass()) return false; |
149 | 0 | final CachedAsset other = (CachedAsset) obj; |
150 | 0 | if (_path == null) { |
151 | 0 | if (other._path != null) return false; |
152 | 0 | } else if (!_path.equals(other._path)) return false; |
153 | 0 | return true; |
154 | } |
|
155 | ||
156 | /** |
|
157 | * {@inheritDoc} |
|
158 | */ |
|
159 | public String toString() |
|
160 | { |
|
161 | 0 | String ret = "CachedAsset [path: " + _path; |
162 | ||
163 | 0 | if (_data != null) |
164 | 0 | ret += ", data size(bytes): " + _data.length; |
165 | 0 | if (_gzipData != null) |
166 | 0 | ret += ", gzip data size(bytes): " + _gzipData.length; |
167 | ||
168 | 0 | ret += ", lastModified(ms): " + _lastModified + "]"; |
169 | ||
170 | 0 | return ret; |
171 | } |
|
172 | } |