1 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 ; 22 import java.util.Map ; 23 24 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 UNMODIFIABLE_MESSAGE = "You are not allowed to update this document."; 33 private static final String 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 ("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 (UNMODIFIABLE_MESSAGE); 79 } 80 81 public void changeDocumentType(String documentTypeName) throws RepositoryException { 82 throw new RuntimeException (UNMODIFIABLE_MESSAGE); 83 } 84 85 public String getName() { 86 throw new RuntimeException (NONLIVE_ACCESS); 87 } 88 89 public void setName(String name) { 90 throw new RuntimeException (UNMODIFIABLE_MESSAGE); 91 } 92 93 public long getOwner() { 94 return delegate.getOwner(); 95 } 96 97 public void setOwner(long userId) { 98 throw new RuntimeException (UNMODIFIABLE_MESSAGE); 99 } 100 101 public boolean isPrivate() { 102 return delegate.isPrivate(); 103 } 104 105 public void setPrivate(boolean _private) { 106 throw new RuntimeException (UNMODIFIABLE_MESSAGE); 107 } 108 109 public Date 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 (UNMODIFIABLE_MESSAGE); 119 } 120 121 public Date getLastModified() { 122 return delegate.getLastModified(); 123 } 124 125 public long getLastModifier() { 126 return delegate.getLastModifier(); 127 } 128 129 public Date 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 (NONLIVE_ACCESS); 139 } 140 141 public Version getVersion(long id) throws RepositoryException { 142 if (id != liveVersionId) 143 throw new RuntimeException (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 (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 name, Object value) throws DocumentTypeInconsistencyException { 170 throw new RuntimeException (UNMODIFIABLE_MESSAGE); 171 } 172 173 public void setField(long fieldTypeId, Object value) throws DocumentTypeInconsistencyException { 174 throw new RuntimeException (UNMODIFIABLE_MESSAGE); 175 } 176 177 public void deleteField(String name) { 178 throw new RuntimeException (UNMODIFIABLE_MESSAGE); 179 } 180 181 public void deleteField(long fieldTypeId) { 182 throw new RuntimeException (UNMODIFIABLE_MESSAGE); 183 } 184 185 public Field getField(String fieldTypeName) throws FieldNotFoundException { 186 throw new RuntimeException (NONLIVE_ACCESS); 187 } 188 189 public Field getField(long fieldTypeId) throws FieldNotFoundException { 190 throw new RuntimeException (NONLIVE_ACCESS); 191 } 192 193 public boolean hasField(long fieldTypeId) { 194 throw new RuntimeException (NONLIVE_ACCESS); 195 } 196 197 public boolean hasField(String fieldTypeName) { 198 throw new RuntimeException (NONLIVE_ACCESS); 199 } 200 201 public Fields getFields() { 202 throw new RuntimeException (NONLIVE_ACCESS); 203 } 204 205 public Fields getFieldsInOrder() { 206 throw new RuntimeException (NONLIVE_ACCESS); 207 } 208 209 public void save() throws RepositoryException { 210 throw new RuntimeException (UNMODIFIABLE_MESSAGE); 211 } 212 213 public void save(boolean validate) throws RepositoryException { 214 throw new RuntimeException (UNMODIFIABLE_MESSAGE); 215 } 216 217 public void validate() throws DocumentTypeInconsistencyException { 218 throw new RuntimeException (UNMODIFIABLE_MESSAGE); 219 } 220 221 public void setNewVersionState(VersionState versionState) { 222 throw new RuntimeException (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 (UNMODIFIABLE_MESSAGE); 231 } 232 233 public boolean releaseLock() throws RepositoryException { 234 throw new RuntimeException (UNMODIFIABLE_MESSAGE); 235 } 236 237 public LockInfo getLockInfo(boolean fresh) throws RepositoryException { 238 return delegate.getLockInfo(fresh); 239 } 240 241 public void setCustomField(String name, String value) { 242 throw new RuntimeException (UNMODIFIABLE_MESSAGE); 243 } 244 245 public void deleteCustomField(String name) { 246 throw new RuntimeException (UNMODIFIABLE_MESSAGE); 247 } 248 249 public String getCustomField(String name) { 250 return delegate.getCustomField(name); 251 } 252 253 public boolean hasCustomField(String name) { 254 return delegate.hasCustomField(name); 255 } 256 257 public void clearCustomFields() { 258 throw new RuntimeException (UNMODIFIABLE_MESSAGE); 259 } 260 261 public Map getCustomFields() { 262 return delegate.getCustomFields(); 263 } 264 265 public void setPart(String partTypeName, String mimeType, byte[] data) throws DocumentTypeInconsistencyException { 266 throw new RuntimeException (UNMODIFIABLE_MESSAGE); 267 } 268 269 public void setPart(long partTypeId, String mimeType, byte[] data) throws DocumentTypeInconsistencyException { 270 throw new RuntimeException (UNMODIFIABLE_MESSAGE); 271 } 272 273 public void setPart(String partTypeName, String mimeType, PartDataSource partDataSource) throws DocumentTypeInconsistencyException { 274 throw new RuntimeException (UNMODIFIABLE_MESSAGE); 275 } 276 277 public void setPart(long partTypeId, String mimeType, PartDataSource partDataSource) throws DocumentTypeInconsistencyException { 278 throw new RuntimeException (UNMODIFIABLE_MESSAGE); 279 } 280 281 public void setPartFileName(String partTypeName, String fileName) { 282 throw new RuntimeException (UNMODIFIABLE_MESSAGE); 283 } 284 285 public void setPartFileName(long partTypeId, String fileName) { 286 throw new RuntimeException (UNMODIFIABLE_MESSAGE); 287 } 288 289 public void setPartMimeType(String partTypeName, String mimeType) { 290 throw new RuntimeException (UNMODIFIABLE_MESSAGE); 291 } 292 293 public void setPartMimeType(long partTypeId, String mimeType) { 294 throw new RuntimeException (UNMODIFIABLE_MESSAGE); 295 } 296 297 public void deletePart(long partTypeId) { 298 throw new RuntimeException (UNMODIFIABLE_MESSAGE); 299 } 300 301 public void deletePart(String name) { 302 throw new RuntimeException (UNMODIFIABLE_MESSAGE); 303 } 304 305 public Part getPart(long partTypeId) throws PartNotFoundException { 306 throw new RuntimeException (NONLIVE_ACCESS); 307 } 308 309 public Part getPart(String name) throws PartNotFoundException { 310 throw new RuntimeException (NONLIVE_ACCESS); 311 } 312 313 public boolean hasPart(long partTypeId) { 314 throw new RuntimeException (NONLIVE_ACCESS); 315 } 316 317 public boolean hasPart(String name) { 318 throw new RuntimeException (NONLIVE_ACCESS); 319 } 320 321 public Parts getParts() { 322 throw new RuntimeException (NONLIVE_ACCESS); 323 } 324 325 public Parts getPartsInOrder() { 326 throw new RuntimeException (NONLIVE_ACCESS); 327 } 328 329 public void addLink(String title, String target) { 330 throw new RuntimeException (UNMODIFIABLE_MESSAGE); 331 } 332 333 public void deleteLink(int index) { 334 throw new RuntimeException (UNMODIFIABLE_MESSAGE); 335 } 336 337 public void clearLinks() { 338 throw new RuntimeException (UNMODIFIABLE_MESSAGE); 339 } 340 341 public Links getLinks() { 342 throw new RuntimeException (NONLIVE_ACCESS); 343 } 344 345 public void addToCollection(DocumentCollection collection) { 346 throw new RuntimeException (UNMODIFIABLE_MESSAGE); 347 } 348 349 public void removeFromCollection(DocumentCollection collection) { 350 throw new RuntimeException (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 (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 (NONLIVE_ACCESS); 380 return delegate.getXml(versionId); 381 } 382 383 public void clearCollections() { 384 throw new RuntimeException (UNMODIFIABLE_MESSAGE); 385 } 386 387 public String 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 |