This project has retired. For details please refer to its
Attic page.
AbstractSingleFilingImpl xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.chemistry.opencmis.inmemory.storedobj.impl;
20
21 import java.util.Collections;
22 import java.util.List;
23
24 import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
25 import org.apache.chemistry.opencmis.commons.exceptions.CmisNameConstraintViolationException;
26 import org.apache.chemistry.opencmis.inmemory.NameValidator;
27 import org.apache.chemistry.opencmis.inmemory.storedobj.api.Document;
28 import org.apache.chemistry.opencmis.inmemory.storedobj.api.Folder;
29 import org.apache.chemistry.opencmis.inmemory.storedobj.api.SingleFiling;
30 import org.apache.chemistry.opencmis.inmemory.storedobj.api.VersionedDocument;
31
32
33
34
35
36
37
38 public abstract class AbstractSingleFilingImpl extends StoredObjectImpl implements SingleFiling {
39
40 protected FolderImpl fParent;
41
42 protected AbstractSingleFilingImpl(ObjectStoreImpl objStore) {
43 super(objStore);
44 }
45
46 public String getPath() {
47 StringBuffer path = new StringBuffer(getName());
48 if (null == getParent()) {
49 path.replace(0, path.length(), PATH_SEPARATOR);
50 } else {
51
52 Folder f = getParent();
53 while (f.getParent() != null) {
54 path.insert(0, PATH_SEPARATOR);
55 path.insert(0, f.getName());
56 f = f.getParent();
57 }
58 path.insert(0, PATH_SEPARATOR);
59 }
60
61
62 return path.toString();
63 }
64
65 public Folder getParent() {
66 return fParent;
67 }
68
69 public boolean hasParent() {
70 return null != fParent;
71 }
72
73 public List<Folder> getParents() {
74 if (null == fParent) {
75 return Collections.emptyList();
76 } else {
77 return Collections.singletonList((Folder) fParent);
78 }
79 }
80
81 public List<Folder> getParents(String user) {
82 return getParents();
83 }
84
85 public void setParent(Folder parent) {
86 try {
87 fObjStore.lock();
88 fParent = (FolderImpl) parent;
89 } finally {
90 fObjStore.unlock();
91 }
92 }
93
94 @Override
95 public void rename(String newName) {
96 if (!NameValidator.isValidId(newName)) {
97 throw new CmisInvalidArgumentException(NameValidator.ERROR_ILLEGAL_NAME);
98 }
99 try {
100 fObjStore.lock();
101 if (getParent() == null) {
102 throw new CmisInvalidArgumentException("Root folder cannot be renamed.");
103 }
104 if (getParent().hasChild(newName)) {
105 throw new CmisNameConstraintViolationException("Cannot rename object to " + newName
106 + ". This path already exists.");
107 }
108
109 setName(newName);
110 } finally {
111 fObjStore.unlock();
112 }
113 }
114
115 public void move(Folder oldParent, Folder newParent) {
116 try {
117 fObjStore.lock();
118 if (this instanceof Document || this instanceof VersionedDocument) {
119 fParent.moveChildDocument(this, oldParent, newParent);
120 } else {
121 if (getParent() == null) {
122 throw new IllegalArgumentException("Root folder cannot be moved.");
123 }
124 if (newParent == null) {
125 throw new IllegalArgumentException("null is not a valid move target.");
126 }
127 if (newParent.hasChild(getName())) {
128 throw new IllegalArgumentException("Cannot move folder, this name already exists in target.");
129 }
130
131 setParent(newParent);
132 }
133 } finally {
134 fObjStore.unlock();
135 }
136 }
137
138 }