KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > repository > commonimpl > ReadLiveOnlyDocument


1 /*
2  * Copyright 2004 Outerthought bvba and Schaubroeck nv
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.outerj.daisy.repository.commonimpl;
17
18 import org.outerj.daisy.repository.*;
19 import org.outerx.daisy.x10.DocumentDocument;
20
21 import java.util.Date JavaDoc;
22 import java.util.Map JavaDoc;
23
24 /**
25  * Wrapper around a document object that denies access to "non-live"
26  * informationn for users which have only "readOnlyLive" permissions.
27  */

28 public class ReadLiveOnlyDocument implements Document, DocumentWrapper {
29     private final DocumentImpl delegate;
30     private final DocumentStrategy documentStrategy;
31     private final long liveVersionId;
32     private static final String JavaDoc UNMODIFIABLE_MESSAGE = "You are not allowed to update this document.";
33     private static final String JavaDoc NONLIVE_ACCESS = "You are not allowed to access non-live information of this document.";
34
35     public ReadLiveOnlyDocument(DocumentImpl delegate, DocumentStrategy documentStrategy) {
36         this.delegate = delegate;
37         this.documentStrategy = documentStrategy;
38         this.liveVersionId = delegate.getLiveVersionId();
39         if (liveVersionId == -1)
40             throw new RuntimeException JavaDoc("Document has no live version.");
41     }
42
43     public DocumentImpl getWrappedDocument(DocumentStrategy strategy) {
44         if (strategy == this.documentStrategy)
45             return delegate;
46         return null;
47     }
48
49     public long getId() {
50         return delegate.getId();
51     }
52
53     public long getBranchId() {
54         return delegate.getBranchId();
55     }
56
57     public long getLanguageId() {
58         return delegate.getLanguageId();
59     }
60
61     public VariantKey getVariantKey() {
62         return delegate.getVariantKey();
63     }
64
65     public boolean isVariantNew() {
66         return delegate.isVariantNew();
67     }
68
69     public AvailableVariants getAvailableVariants() throws RepositoryException {
70         return delegate.getAvailableVariants();
71     }
72
73     public long getDocumentTypeId() {
74         return delegate.getDocumentTypeId();
75     }
76
77     public void changeDocumentType(long documentTypeId) throws RepositoryException {
78         throw new RuntimeException JavaDoc(UNMODIFIABLE_MESSAGE);
79     }
80
81     public void changeDocumentType(String JavaDoc documentTypeName) throws RepositoryException {
82         throw new RuntimeException JavaDoc(UNMODIFIABLE_MESSAGE);
83     }
84
85     public String JavaDoc getName() {
86         throw new RuntimeException JavaDoc(NONLIVE_ACCESS);
87     }
88
89     public void setName(String JavaDoc name) {
90         throw new RuntimeException JavaDoc(UNMODIFIABLE_MESSAGE);
91     }
92
93     public long getOwner() {
94         return delegate.getOwner();
95     }
96
97     public void setOwner(long userId) {
98         throw new RuntimeException JavaDoc(UNMODIFIABLE_MESSAGE);
99     }
100
101     public boolean isPrivate() {
102         return delegate.isPrivate();
103     }
104
105     public void setPrivate(boolean _private) {
106         throw new RuntimeException JavaDoc(UNMODIFIABLE_MESSAGE);
107     }
108
109     public Date JavaDoc getCreated() {
110         return delegate.getCreated();
111     }
112
113     public boolean isRetired() {
114         return delegate.isRetired();
115     }
116
117     public void setRetired(boolean retired) {
118         throw new RuntimeException JavaDoc(UNMODIFIABLE_MESSAGE);
119     }
120
121     public Date JavaDoc getLastModified() {
122         return delegate.getLastModified();
123     }
124
125     public long getLastModifier() {
126         return delegate.getLastModifier();
127     }
128
129     public Date JavaDoc getVariantLastModified() {
130         return delegate.getVariantLastModified();
131     }
132
133     public long getVariantLastModifier() {
134         return delegate.getVariantLastModifier();
135     }
136
137     public Versions getVersions() throws RepositoryException {
138         throw new RuntimeException JavaDoc(NONLIVE_ACCESS);
139     }
140
141     public Version getVersion(long id) throws RepositoryException {
142         if (id != liveVersionId)
143             throw new RuntimeException JavaDoc(NONLIVE_ACCESS);
144         return delegate.getVersion(id);
145     }
146
147     public long getLiveVersionId() {
148         return liveVersionId;
149     }
150
151     public boolean canReadLiveOnly() {
152         return true;
153     }
154
155     public long getLastVersionId() {
156         return delegate.getLastVersionId();
157     }
158
159     public Version getLastVersion() throws RepositoryException {
160         if (delegate.getLastVersionId() != liveVersionId)
161             throw new RuntimeException JavaDoc(NONLIVE_ACCESS);
162         return delegate.getLastVersion();
163     }
164
165     public Version getLiveVersion() throws RepositoryException {
166         return delegate.getLiveVersion();
167     }
168
169     public void setField(String JavaDoc name, Object JavaDoc value) throws DocumentTypeInconsistencyException {
170         throw new RuntimeException JavaDoc(UNMODIFIABLE_MESSAGE);
171     }
172
173     public void setField(long fieldTypeId, Object JavaDoc value) throws DocumentTypeInconsistencyException {
174         throw new RuntimeException JavaDoc(UNMODIFIABLE_MESSAGE);
175     }
176
177     public void deleteField(String JavaDoc name) {
178         throw new RuntimeException JavaDoc(UNMODIFIABLE_MESSAGE);
179     }
180
181     public void deleteField(long fieldTypeId) {
182         throw new RuntimeException JavaDoc(UNMODIFIABLE_MESSAGE);
183     }
184
185     public Field getField(String JavaDoc fieldTypeName) throws FieldNotFoundException {
186         throw new RuntimeException JavaDoc(NONLIVE_ACCESS);
187     }
188
189     public Field getField(long fieldTypeId) throws FieldNotFoundException {
190         throw new RuntimeException JavaDoc(NONLIVE_ACCESS);
191     }
192
193     public boolean hasField(long fieldTypeId) {
194         throw new RuntimeException JavaDoc(NONLIVE_ACCESS);
195     }
196
197     public boolean hasField(String JavaDoc fieldTypeName) {
198         throw new RuntimeException JavaDoc(NONLIVE_ACCESS);
199     }
200
201     public Fields getFields() {
202         throw new RuntimeException JavaDoc(NONLIVE_ACCESS);
203     }
204
205     public Fields getFieldsInOrder() {
206         throw new RuntimeException JavaDoc(NONLIVE_ACCESS);
207     }
208
209     public void save() throws RepositoryException {
210         throw new RuntimeException JavaDoc(UNMODIFIABLE_MESSAGE);
211     }
212
213     public void save(boolean validate) throws RepositoryException {
214         throw new RuntimeException JavaDoc(UNMODIFIABLE_MESSAGE);
215     }
216
217     public void validate() throws DocumentTypeInconsistencyException {
218         throw new RuntimeException JavaDoc(UNMODIFIABLE_MESSAGE);
219     }
220
221     public void setNewVersionState(VersionState versionState) {
222         throw new RuntimeException JavaDoc(UNMODIFIABLE_MESSAGE);
223     }
224
225     public VersionState getNewVersionState() {
226         return delegate.getNewVersionState();
227     }
228
229     public boolean lock(long duration, LockType lockType) throws RepositoryException {
230         throw new RuntimeException JavaDoc(UNMODIFIABLE_MESSAGE);
231     }
232
233     public boolean releaseLock() throws RepositoryException {
234         throw new RuntimeException JavaDoc(UNMODIFIABLE_MESSAGE);
235     }
236
237     public LockInfo getLockInfo(boolean fresh) throws RepositoryException {
238         return delegate.getLockInfo(fresh);
239     }
240
241     public void setCustomField(String JavaDoc name, String JavaDoc value) {
242         throw new RuntimeException JavaDoc(UNMODIFIABLE_MESSAGE);
243     }
244
245     public void deleteCustomField(String JavaDoc name) {
246         throw new RuntimeException JavaDoc(UNMODIFIABLE_MESSAGE);
247     }
248
249     public String JavaDoc getCustomField(String JavaDoc name) {
250         return delegate.getCustomField(name);
251     }
252
253     public boolean hasCustomField(String JavaDoc name) {
254         return delegate.hasCustomField(name);
255     }
256
257     public void clearCustomFields() {
258         throw new RuntimeException JavaDoc(UNMODIFIABLE_MESSAGE);
259     }
260
261     public Map JavaDoc getCustomFields() {
262         return delegate.getCustomFields();
263     }
264
265     public void setPart(String JavaDoc partTypeName, String JavaDoc mimeType, byte[] data) throws DocumentTypeInconsistencyException {
266         throw new RuntimeException JavaDoc(UNMODIFIABLE_MESSAGE);
267     }
268
269     public void setPart(long partTypeId, String JavaDoc mimeType, byte[] data) throws DocumentTypeInconsistencyException {
270         throw new RuntimeException JavaDoc(UNMODIFIABLE_MESSAGE);
271     }
272
273     public void setPart(String JavaDoc partTypeName, String JavaDoc mimeType, PartDataSource partDataSource) throws DocumentTypeInconsistencyException {
274         throw new RuntimeException JavaDoc(UNMODIFIABLE_MESSAGE);
275     }
276
277     public void setPart(long partTypeId, String JavaDoc mimeType, PartDataSource partDataSource) throws DocumentTypeInconsistencyException {
278         throw new RuntimeException JavaDoc(UNMODIFIABLE_MESSAGE);
279     }
280
281     public void setPartFileName(String JavaDoc partTypeName, String JavaDoc fileName) {
282         throw new RuntimeException JavaDoc(UNMODIFIABLE_MESSAGE);
283     }
284
285     public void setPartFileName(long partTypeId, String JavaDoc fileName) {
286         throw new RuntimeException JavaDoc(UNMODIFIABLE_MESSAGE);
287     }
288
289     public void setPartMimeType(String JavaDoc partTypeName, String JavaDoc mimeType) {
290         throw new RuntimeException JavaDoc(UNMODIFIABLE_MESSAGE);
291     }
292
293     public void setPartMimeType(long partTypeId, String JavaDoc mimeType) {
294         throw new RuntimeException JavaDoc(UNMODIFIABLE_MESSAGE);
295     }
296
297     public void deletePart(long partTypeId) {
298         throw new RuntimeException JavaDoc(UNMODIFIABLE_MESSAGE);
299     }
300
301     public void deletePart(String JavaDoc name) {
302         throw new RuntimeException JavaDoc(UNMODIFIABLE_MESSAGE);
303     }
304
305     public Part getPart(long partTypeId) throws PartNotFoundException {
306         throw new RuntimeException JavaDoc(NONLIVE_ACCESS);
307     }
308
309     public Part getPart(String JavaDoc name) throws PartNotFoundException {
310         throw new RuntimeException JavaDoc(NONLIVE_ACCESS);
311     }
312
313     public boolean hasPart(long partTypeId) {
314         throw new RuntimeException JavaDoc(NONLIVE_ACCESS);
315     }
316
317     public boolean hasPart(String JavaDoc name) {
318         throw new RuntimeException JavaDoc(NONLIVE_ACCESS);
319     }
320
321     public Parts getParts() {
322         throw new RuntimeException JavaDoc(NONLIVE_ACCESS);
323     }
324
325     public Parts getPartsInOrder() {
326         throw new RuntimeException JavaDoc(NONLIVE_ACCESS);
327     }
328
329     public void addLink(String JavaDoc title, String JavaDoc target) {
330         throw new RuntimeException JavaDoc(UNMODIFIABLE_MESSAGE);
331     }
332
333     public void deleteLink(int index) {
334         throw new RuntimeException JavaDoc(UNMODIFIABLE_MESSAGE);
335     }
336
337     public void clearLinks() {
338         throw new RuntimeException JavaDoc(UNMODIFIABLE_MESSAGE);
339     }
340
341     public Links getLinks() {
342         throw new RuntimeException JavaDoc(NONLIVE_ACCESS);
343     }
344
345     public void addToCollection(DocumentCollection collection) {
346         throw new RuntimeException JavaDoc(UNMODIFIABLE_MESSAGE);
347     }
348
349     public void removeFromCollection(DocumentCollection collection) {
350         throw new RuntimeException JavaDoc(UNMODIFIABLE_MESSAGE);
351     }
352
353     public DocumentCollections getCollections() {
354         return delegate.getCollections();
355     }
356
357     public boolean inCollection(DocumentCollection collection) {
358         return delegate.inCollection(collection);
359     }
360
361     public boolean inCollection(long collectionId) {
362         return delegate.inCollection(collectionId);
363     }
364
365     public DocumentDocument getXml() throws RepositoryException {
366         throw new RuntimeException JavaDoc(NONLIVE_ACCESS);
367     }
368
369     public DocumentDocument getXmlWithoutVariant() throws RepositoryException {
370         return delegate.getXmlWithoutVariant();
371     }
372
373     public DocumentDocument getXmlWithoutVersionedData() throws RepositoryException {
374         return delegate.getXmlWithoutVersionedData();
375     }
376
377     public DocumentDocument getXml(long versionId) throws RepositoryException {
378         if (versionId != liveVersionId)
379             throw new RuntimeException JavaDoc(NONLIVE_ACCESS);
380         return delegate.getXml(versionId);
381     }
382
383     public void clearCollections() {
384         throw new RuntimeException JavaDoc(UNMODIFIABLE_MESSAGE);
385     }
386
387     public String JavaDoc getSummary() {
388         return delegate.getSummary();
389     }
390
391     public long getVariantCreatedFromBranchId() {
392         return delegate.getVariantCreatedFromBranchId();
393     }
394
395     public long getVariantCreatedFromLanguageId() {
396         return delegate.getVariantCreatedFromLanguageId();
397     }
398
399     public long getVariantCreatedFromVersionId() {
400         return delegate.getVariantCreatedFromVersionId();
401     }
402
403     public long getUpdateCount() {
404         return delegate.getUpdateCount();
405     }
406
407     public long getVariantUpdateCount() {
408         return delegate.getVariantUpdateCount();
409     }
410 }
411
Popular Tags