001/* 002 * (C) Copyright 2006-2013 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Nuxeo - initial API and implementation 018 * 019 * $Id$ 020 */ 021 022package org.nuxeo.ecm.core.event.impl; 023 024import java.io.Serializable; 025import java.util.Collection; 026import java.util.Map; 027import java.util.Set; 028 029import org.nuxeo.common.collections.ScopeType; 030import org.nuxeo.common.collections.ScopedMap; 031import org.nuxeo.common.utils.Path; 032import org.nuxeo.ecm.core.api.CoreSession; 033import org.nuxeo.ecm.core.api.DataModel; 034import org.nuxeo.ecm.core.api.DataModelMap; 035import org.nuxeo.ecm.core.api.DocumentModel; 036import org.nuxeo.ecm.core.api.DocumentRef; 037import org.nuxeo.ecm.core.api.IdRef; 038import org.nuxeo.ecm.core.api.Lock; 039import org.nuxeo.ecm.core.api.PathRef; 040import org.nuxeo.ecm.core.api.PropertyException; 041import org.nuxeo.ecm.core.api.VersioningOption; 042import org.nuxeo.ecm.core.api.model.DocumentPart; 043import org.nuxeo.ecm.core.api.model.Property; 044import org.nuxeo.ecm.core.api.model.PropertyVisitor; 045import org.nuxeo.ecm.core.api.model.resolver.DocumentPropertyObjectResolverImpl; 046import org.nuxeo.ecm.core.api.model.resolver.PropertyObjectResolver; 047import org.nuxeo.ecm.core.api.security.ACP; 048import org.nuxeo.ecm.core.event.Event; 049import org.nuxeo.ecm.core.event.EventBundle; 050import org.nuxeo.ecm.core.schema.DocumentType; 051 052/** 053 * Light weight {@link DocumentModel} implementation Only holds {@link DocumentRef}, RepositoryName, name, path and 054 * context data. Used to reduce memory footprint of {@link Event} stacked in {@link EventBundle}. 055 * 056 * @author Thierry Delprat 057 */ 058public class ShallowDocumentModel implements DocumentModel { 059 060 private static final long serialVersionUID = 1L; 061 062 private final String id; 063 064 private final String repoName; 065 066 private final String name; 067 068 private final Path path; 069 070 private final String type; 071 072 private final boolean isFolder; 073 074 private final boolean isVersion; 075 076 private final boolean isProxy; 077 078 private final boolean isImmutable; 079 080 private final ScopedMap contextData; 081 082 private final Set<String> facets; 083 084 private final String lifecycleState; 085 086 public ShallowDocumentModel(DocumentModel doc) { 087 id = doc.getId(); 088 repoName = doc.getRepositoryName(); 089 name = doc.getName(); 090 path = doc.getPath(); 091 type = doc.getType(); 092 isFolder = doc.isFolder(); 093 isVersion = doc.isVersion(); 094 isProxy = doc.isProxy(); 095 isImmutable = doc.isImmutable(); 096 contextData = doc.getContextData(); 097 facets = doc.getFacets(); 098 if (doc.isLifeCycleLoaded()) { 099 lifecycleState = doc.getCurrentLifeCycleState(); 100 } else { 101 lifecycleState = null; 102 } 103 } 104 105 @Override 106 public String getId() { 107 return id; 108 } 109 110 @Override 111 public DocumentRef getRef() { 112 return id == null ? null : new IdRef(id); 113 } 114 115 @Override 116 public String getRepositoryName() { 117 return repoName; 118 } 119 120 @Override 121 public String getName() { 122 return name; 123 } 124 125 @Override 126 public Long getPos() { 127 return null; 128 } 129 130 @Override 131 public Path getPath() { 132 return path; 133 } 134 135 @Override 136 public String getPathAsString() { 137 if (path != null) { 138 return path.toString(); 139 } 140 return null; 141 } 142 143 @Override 144 public DocumentRef getParentRef() { 145 if (path != null) { 146 return new PathRef(path.removeLastSegments(1).toString()); 147 } 148 return null; 149 } 150 151 @Override 152 public String getType() { 153 return type; 154 } 155 156 @Override 157 public boolean isFolder() { 158 return isFolder; 159 } 160 161 @Override 162 public boolean isVersion() { 163 return isVersion; 164 } 165 166 @Override 167 public void copyContent(DocumentModel sourceDoc) { 168 throw new UnsupportedOperationException(); 169 } 170 171 @Override 172 public void copyContextData(DocumentModel otherDocument) { 173 throw new UnsupportedOperationException(); 174 } 175 176 @Override 177 public boolean followTransition(String transition) { 178 throw new UnsupportedOperationException(); 179 } 180 181 @Override 182 public ACP getACP() { 183 throw new UnsupportedOperationException(); 184 } 185 186 @Override 187 public void accept(PropertyVisitor visitor, Object arg) { 188 throw new UnsupportedOperationException(); 189 } 190 191 @Override 192 public <T> T getAdapter(Class<T> itf) { 193 throw new UnsupportedOperationException(); 194 } 195 196 @Override 197 public <T> T getAdapter(Class<T> itf, boolean refreshCache) { 198 throw new UnsupportedOperationException(); 199 } 200 201 @Override 202 public Collection<String> getAllowedStateTransitions() { 203 throw new UnsupportedOperationException(); 204 } 205 206 @Override 207 public String getCacheKey() { 208 throw new UnsupportedOperationException(); 209 } 210 211 @Override 212 public ScopedMap getContextData() { 213 return contextData; 214 } 215 216 @Override 217 public Serializable getContextData(ScopeType scope, String key) { 218 if (contextData == null) { 219 return null; 220 } 221 return contextData.getScopedValue(scope, key); 222 } 223 224 @Override 225 public CoreSession getCoreSession() { 226 throw new UnsupportedOperationException(); 227 } 228 229 @Override 230 public void detach(boolean loadAll) { 231 } 232 233 @Override 234 public void attach(String sid) { 235 } 236 237 @Override 238 public String getCurrentLifeCycleState() { 239 return lifecycleState; 240 } 241 242 @Override 243 public DataModel getDataModel(String schema) { 244 throw new UnsupportedOperationException(); 245 } 246 247 @Override 248 public DataModelMap getDataModels() { 249 throw new UnsupportedOperationException(); 250 } 251 252 @Override 253 public Collection<DataModel> getDataModelsCollection() { 254 throw new UnsupportedOperationException(); 255 } 256 257 @Override 258 public Set<String> getFacets() { 259 return facets; 260 } 261 262 @Override 263 public Set<String> getDeclaredFacets() { 264 throw new UnsupportedOperationException(); 265 } 266 267 @Override 268 public String[] getSchemas() { 269 throw new UnsupportedOperationException(); 270 } 271 272 @Override 273 public String[] getDeclaredSchemas() { 274 throw new UnsupportedOperationException(); 275 } 276 277 @Override 278 public DocumentType getDocumentType() { 279 throw new UnsupportedOperationException(); 280 } 281 282 @Override 283 public String getLifeCyclePolicy() { 284 throw new UnsupportedOperationException(); 285 } 286 287 @Override 288 public String getLock() { 289 throw new UnsupportedOperationException(); 290 } 291 292 @Override 293 public DocumentPart getPart(String schema) { 294 throw new UnsupportedOperationException(); 295 } 296 297 @Override 298 public DocumentPart[] getParts() { 299 throw new UnsupportedOperationException(); 300 } 301 302 @Override 303 public Map<String, Object> getProperties(String schemaName) { 304 throw new UnsupportedOperationException(); 305 } 306 307 @Override 308 public Property getProperty(String xpath) throws PropertyException { 309 throw new UnsupportedOperationException(); 310 } 311 312 @Override 313 public Object getProperty(String schemaName, String name) { 314 throw new UnsupportedOperationException(); 315 } 316 317 @Override 318 public Serializable getPropertyValue(String xpath) throws PropertyException { 319 throw new UnsupportedOperationException(); 320 } 321 322 @Override 323 public String getSessionId() { 324 throw new UnsupportedOperationException(); 325 } 326 327 @Override 328 public String getSourceId() { 329 throw new UnsupportedOperationException(); 330 } 331 332 @Override 333 public <T extends Serializable> T getSystemProp(String systemProperty, Class<T> type) { 334 throw new UnsupportedOperationException(); 335 } 336 337 @Override 338 public String getTitle() { 339 throw new UnsupportedOperationException(); 340 } 341 342 @Override 343 public String getVersionLabel() { 344 throw new UnsupportedOperationException(); 345 } 346 347 @Override 348 public String getCheckinComment() { 349 throw new UnsupportedOperationException(); 350 } 351 352 @Override 353 public boolean hasFacet(String facet) { 354 return facets.contains(facet); 355 } 356 357 @Override 358 public boolean hasSchema(String schema) { 359 throw new UnsupportedOperationException(); 360 } 361 362 @Override 363 public boolean addFacet(String facet) { 364 throw new UnsupportedOperationException(); 365 } 366 367 @Override 368 public boolean removeFacet(String facet) { 369 throw new UnsupportedOperationException(); 370 } 371 372 @Override 373 public boolean isDownloadable() { 374 throw new UnsupportedOperationException(); 375 } 376 377 @Override 378 public boolean isLifeCycleLoaded() { 379 return lifecycleState != null; 380 } 381 382 @Override 383 public boolean isLocked() { 384 throw new UnsupportedOperationException(); 385 } 386 387 @Override 388 public boolean isProxy() { 389 return isProxy; 390 } 391 392 @Override 393 public boolean isImmutable() { 394 return isImmutable; 395 } 396 397 @Override 398 public boolean isDirty() { 399 throw new UnsupportedOperationException(); 400 } 401 402 @Override 403 public boolean isVersionable() { 404 throw new UnsupportedOperationException(); 405 } 406 407 @Override 408 public boolean isPrefetched(String xpath) { 409 return false; 410 } 411 412 @Override 413 public boolean isPrefetched(String schemaName, String name) { 414 return false; 415 } 416 417 @Override 418 public void prefetchCurrentLifecycleState(String lifecycle) { 419 throw new UnsupportedOperationException(); 420 } 421 422 @Override 423 public void prefetchLifeCyclePolicy(String lifeCyclePolicy) { 424 throw new UnsupportedOperationException(); 425 } 426 427 @Override 428 public void putContextData(String key, Serializable value) { 429 throw new UnsupportedOperationException(); 430 } 431 432 @Override 433 public void putContextData(ScopeType scope, String key, Serializable value) { 434 throw new UnsupportedOperationException(); 435 } 436 437 @Override 438 public void refresh() { 439 throw new UnsupportedOperationException(); 440 } 441 442 @Override 443 public void refresh(int refreshFlags, String[] schemas) { 444 throw new UnsupportedOperationException(); 445 } 446 447 @Override 448 public void reset() { 449 throw new UnsupportedOperationException(); 450 } 451 452 @Override 453 public void setACP(ACP acp, boolean overwrite) { 454 throw new UnsupportedOperationException(); 455 } 456 457 @Override 458 public void setLock(String key) { 459 throw new UnsupportedOperationException(); 460 } 461 462 @Override 463 public Lock setLock() { 464 throw new UnsupportedOperationException(); 465 } 466 467 @Override 468 public Lock getLockInfo() { 469 throw new UnsupportedOperationException(); 470 } 471 472 @Override 473 public Lock removeLock() { 474 throw new UnsupportedOperationException(); 475 } 476 477 @Override 478 public void setPathInfo(String parentPath, String name) { 479 throw new UnsupportedOperationException(); 480 } 481 482 @Override 483 public void setProperties(String schemaName, Map<String, Object> data) { 484 throw new UnsupportedOperationException(); 485 } 486 487 @Override 488 public void setProperty(String schemaName, String name, Object value) { 489 throw new UnsupportedOperationException(); 490 } 491 492 @Override 493 public void setPropertyValue(String xpath, Serializable value) { 494 throw new UnsupportedOperationException(); 495 } 496 497 @Override 498 public void unlock() { 499 throw new UnsupportedOperationException(); 500 } 501 502 @Override 503 public DocumentModel clone() throws CloneNotSupportedException { 504 throw new CloneNotSupportedException(); 505 } 506 507 @Override 508 public Serializable getContextData(String key) { 509 if (contextData == null) { 510 return null; 511 } 512 return contextData.getScopedValue(key); 513 } 514 515 @Override 516 public boolean isCheckedOut() { 517 throw new UnsupportedOperationException(); 518 } 519 520 @Override 521 public void checkOut() { 522 throw new UnsupportedOperationException(); 523 } 524 525 @Override 526 public DocumentRef checkIn(VersioningOption option, String checkinComment) { 527 throw new UnsupportedOperationException(); 528 } 529 530 @Override 531 public String getVersionSeriesId() { 532 throw new UnsupportedOperationException(); 533 } 534 535 @Override 536 public boolean isLatestVersion() { 537 return false; 538 } 539 540 @Override 541 public boolean isMajorVersion() { 542 return false; 543 } 544 545 @Override 546 public boolean isLatestMajorVersion() { 547 return false; 548 } 549 550 @Override 551 public boolean isVersionSeriesCheckedOut() { 552 return true; 553 } 554 555 @Override 556 public String getChangeToken() { 557 return null; 558 } 559 560 @Override 561 public Map<String, String> getBinaryFulltext() { 562 return null; 563 } 564 565 @Override 566 public PropertyObjectResolver getObjectResolver(String xpath) { 567 return DocumentPropertyObjectResolverImpl.create(this, xpath); 568 } 569 570}