This project has retired. For details please refer to its
Attic page.
AbstractMultiFilingImpl 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.ArrayList;
22 import java.util.Collections;
23 import java.util.List;
24
25 import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
26 import org.apache.chemistry.opencmis.commons.exceptions.CmisNameConstraintViolationException;
27 import org.apache.chemistry.opencmis.inmemory.NameValidator;
28 import org.apache.chemistry.opencmis.inmemory.storedobj.api.Folder;
29 import org.apache.chemistry.opencmis.inmemory.storedobj.api.MultiFiling;
30
31
32
33
34
35
36
37 public abstract class AbstractMultiFilingImpl extends StoredObjectImpl implements MultiFiling {
38
39 protected List<Folder> fParents = new ArrayList<Folder>(1);
40
41 AbstractMultiFilingImpl(ObjectStoreImpl objStore) {
42 super(objStore);
43 }
44
45 public void addParent(Folder parent) {
46 try {
47 fObjStore.lock();
48 addParentIntern(parent);
49 } finally {
50 fObjStore.unlock();
51 }
52 }
53
54 private void addParentIntern(Folder parent) {
55 if (parent.hasChild(getName())) {
56 throw new IllegalArgumentException(
57 "Cannot assign new parent folder, this name already exists in target folder.");
58 }
59
60 if (null == fParents) {
61 fParents = new ArrayList<Folder>();
62 }
63
64 fParents.add(parent);
65 }
66
67 public void removeParent(Folder parent) {
68 try {
69 fObjStore.lock();
70 removeParentIntern(parent);
71 } finally {
72 fObjStore.unlock();
73 }
74 }
75
76 private void removeParentIntern(Folder parent) {
77 fParents.remove(parent);
78 if (fParents.isEmpty()) {
79 fParents = null;
80 }
81 }
82
83 public List<Folder> getParents() {
84 if (null == fParents)
85 return Collections.emptyList();
86 else
87 return fParents;
88 }
89
90
91
92
93
94
95
96 public List<Folder> getParents(String user) {
97 if (null == fParents)
98 return Collections.emptyList();
99 else if (null == user)
100 return Collections.unmodifiableList(fParents);
101 else {
102 List<Folder> visibleParents = new ArrayList<Folder>(fParents.size());
103 for (Folder folder : fParents)
104 if (fObjStore.hasReadAccess(user, folder))
105 visibleParents.add(folder);
106 return visibleParents;
107 }
108 }
109
110 public boolean hasParent() {
111 return null != fParents && !fParents.isEmpty();
112 }
113
114 public String getPathSegment() {
115 return getName();
116 }
117
118 public void move(Folder oldParent, Folder newParent) {
119 try {
120 fObjStore.lock();
121 addParentIntern(newParent);
122 removeParentIntern(oldParent);
123 } finally {
124 fObjStore.unlock();
125 }
126 }
127
128 @Override
129 public void rename(String newName) {
130 try {
131 if (!NameValidator.isValidId(newName)) {
132 throw new CmisInvalidArgumentException(NameValidator.ERROR_ILLEGAL_NAME);
133 }
134 fObjStore.lock();
135 for (Folder folder : fParents) {
136 if (folder == null) {
137 throw new CmisInvalidArgumentException("Root folder cannot be renamed.");
138 }
139 if (folder.hasChild(newName)) {
140 throw new CmisNameConstraintViolationException("Cannot rename object to " + newName
141 + ". This path already exists in parent " + folder.getPath() + ".");
142 }
143 }
144 setName(newName);
145 } finally {
146 fObjStore.unlock();
147 }
148 }
149
150 }