1 package fr.in2p3.jsaga.impl.file;
2
3 import fr.in2p3.jsaga.adaptor.data.DataAdaptor;
4 import fr.in2p3.jsaga.impl.namespace.*;
5 import fr.in2p3.jsaga.impl.url.AbstractURLImpl;
6 import fr.in2p3.jsaga.impl.url.URLHelper;
7 import fr.in2p3.jsaga.sync.file.SyncDirectory;
8 import org.ogf.saga.SagaObject;
9 import org.ogf.saga.error.*;
10 import org.ogf.saga.file.*;
11 import org.ogf.saga.namespace.*;
12 import org.ogf.saga.session.Session;
13 import org.ogf.saga.url.URL;
14
15 import java.util.List;
16
17
18
19
20
21
22
23
24
25
26
27
28
29 public class AbstractSyncDirectoryImpl extends AbstractNSDirectoryImpl implements SyncDirectory {
30
31 public AbstractSyncDirectoryImpl(Session session, URL url, DataAdaptor adaptor, int flags) throws NotImplementedException, IncorrectURLException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, AlreadyExistsException, DoesNotExistException, TimeoutException, NoSuccessException {
32 super(session, url, adaptor, new FlagsHelper(flags).keep(JSAGAFlags.BYPASSEXIST, Flags.ALLNAMESPACEFLAGS));
33 }
34
35
36 public AbstractSyncDirectoryImpl(AbstractNSDirectoryImpl dir, URL relativeUrl, int flags) throws NotImplementedException, IncorrectURLException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, AlreadyExistsException, DoesNotExistException, TimeoutException, NoSuccessException {
37 super(dir, relativeUrl, new FlagsHelper(flags).keep(JSAGAFlags.BYPASSEXIST, Flags.ALLNAMESPACEFLAGS));
38 }
39
40
41 public AbstractSyncDirectoryImpl(AbstractNSEntryImpl entry, String absolutePath, int flags) throws NotImplementedException, IncorrectURLException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, AlreadyExistsException, DoesNotExistException, TimeoutException, NoSuccessException {
42 super(entry, absolutePath, new FlagsHelper(flags).keep(JSAGAFlags.BYPASSEXIST, Flags.ALLNAMESPACEFLAGS));
43 }
44
45
46 public SagaObject clone() throws CloneNotSupportedException {
47 return super.clone();
48 }
49
50
51
52
53 public NSDirectory openAbsoluteDir(String absolutePath, int flags) throws NotImplementedException, IncorrectURLException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, IncorrectStateException, AlreadyExistsException, DoesNotExistException, TimeoutException, NoSuccessException {
54 return new DirectoryImpl(this, absolutePath, flags);
55 }
56
57
58 public NSEntry openAbsolute(String absolutePath, int flags) throws NotImplementedException, IncorrectURLException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, IncorrectStateException, AlreadyExistsException, DoesNotExistException, TimeoutException, NoSuccessException {
59 if (URLHelper.isDirectory(absolutePath)) {
60 return new DirectoryImpl(this, absolutePath, flags);
61 } else {
62 return new FileImpl(this, absolutePath, flags);
63 }
64 }
65
66
67
68
69 public NSDirectory openDir(URL name, int flags) throws NotImplementedException, IncorrectURLException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, IncorrectStateException, AlreadyExistsException, DoesNotExistException, TimeoutException, NoSuccessException {
70 return this.openDirectory(name, flags);
71 }
72
73 public NSDirectory openDir(URL name) throws NotImplementedException, IncorrectURLException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, IncorrectStateException, AlreadyExistsException, DoesNotExistException, TimeoutException, NoSuccessException {
74 return this.openDirectory(name);
75 }
76
77
78 public NSEntry open(URL name, int flags) throws NotImplementedException, IncorrectURLException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, IncorrectStateException, AlreadyExistsException, DoesNotExistException, TimeoutException, NoSuccessException {
79 if (URLHelper.isDirectory(name)) {
80 return this.openDirectory(name, flags);
81 } else {
82 return this.openFile(name, flags);
83 }
84 }
85
86 public NSEntry open(URL name) throws NotImplementedException, IncorrectURLException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, IncorrectStateException, AlreadyExistsException, DoesNotExistException, TimeoutException, NoSuccessException {
87 if (URLHelper.isDirectory(name)) {
88 return this.openDirectory(name);
89 } else {
90 return this.openFile(name);
91 }
92 }
93
94
95
96
97 public long getSizeSync(int flags) throws NotImplementedException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, IncorrectStateException, TimeoutException, NoSuccessException {
98 int total_size = 0;
99 try {
100 List list = this.list(flags);
101 for (int i=0; i<list.size(); i++) {
102 AbstractURLImpl url = (AbstractURLImpl)list.get(i);
103 if (url.getPath().endsWith("/")) {
104 total_size += ((DirectoryImpl)this.openDir(url, flags)).getSize();
105 } else {
106 if (url.hasCache()) {
107 total_size += url.getCache().getSize();
108 } else {
109 total_size += ((FileImpl)this.openFile(url, flags)).getSize();
110 }
111 }
112 }
113 return total_size;
114 } catch (IncorrectURLException e) {
115 throw new NoSuccessException(e);
116 } catch (DoesNotExistException e) {
117 throw new NoSuccessException(e);
118 } catch (AlreadyExistsException e) {
119 throw new NoSuccessException(e);
120 }
121 }
122
123 public long getSizeSync() throws NotImplementedException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, IncorrectStateException, BadParameterException, TimeoutException, NoSuccessException {
124 return this.getSizeSync(Flags.NONE.getValue());
125 }
126
127
128 public long getSizeSync(URL name, int flags) throws NotImplementedException, IncorrectURLException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, IncorrectStateException, DoesNotExistException, TimeoutException, NoSuccessException {
129 new FlagsHelper(flags).allowed(Flags.NONE, Flags.DEREFERENCE);
130 try {
131 File entry = this.openFile(name, flags);
132 try {
133 return entry.getSize();
134 } finally {
135 entry.close();
136 }
137 } catch (BadParameterException bpe) {
138
139 if (bpe.getStackTrace()[0].getClassName().equals(fr.in2p3.jsaga.impl.url.URLHelper.class.getName())) {
140 if (name.normalize().getPath().equals(m_url.getPath())) {
141 return this.getSizeSync(flags);
142 } else {
143 try {
144 return ((DirectoryImpl)this.openDir(name, flags)).getSize();
145 } catch (AlreadyExistsException aee) {
146
147 throw new NoSuccessException("Wrong exception thrown: "+ name, aee);
148 }
149 }
150 } else {
151 throw bpe;
152 }
153 } catch (AlreadyExistsException aee) {
154
155 throw new NoSuccessException("Wrong exception thrown: "+ name, aee);
156 }
157 }
158
159 public long getSizeSync(URL name) throws NotImplementedException, IncorrectURLException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, IncorrectStateException, DoesNotExistException, TimeoutException, NoSuccessException {
160 return this.getSizeSync(name, Flags.NONE.getValue());
161 }
162
163 public boolean isFileSync(URL name) throws NotImplementedException, IncorrectURLException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, IncorrectStateException, DoesNotExistException, TimeoutException, NoSuccessException {
164 return super.isEntrySync(name);
165 }
166
167
168 public Directory openDirectory(URL relativeUrl, int flags) throws NotImplementedException, IncorrectURLException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, IncorrectStateException, AlreadyExistsException, DoesNotExistException, TimeoutException, NoSuccessException {
169 return new DirectoryImpl(this, relativeUrl, flags);
170 }
171
172 public Directory openDirectory(URL relativeUrl) throws NotImplementedException, IncorrectURLException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, IncorrectStateException, AlreadyExistsException, DoesNotExistException, TimeoutException, NoSuccessException {
173 return new DirectoryImpl(this, relativeUrl, Flags.READ.getValue());
174 }
175
176
177 public File openFile(URL relativeUrl, int flags) throws NotImplementedException, IncorrectURLException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, IncorrectStateException, AlreadyExistsException, DoesNotExistException, TimeoutException, NoSuccessException {
178 return new FileImpl(this, relativeUrl, flags);
179 }
180
181 public File openFile(URL relativeUrl) throws NotImplementedException, IncorrectURLException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, IncorrectStateException, AlreadyExistsException, DoesNotExistException, TimeoutException, NoSuccessException {
182 return new FileImpl(this, relativeUrl, Flags.READ.getValue());
183 }
184
185 public FileInputStream openFileInputStreamSync(URL relativeUrl) throws NotImplementedException, IncorrectURLException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, IncorrectStateException, AlreadyExistsException, DoesNotExistException, TimeoutException, NoSuccessException {
186 URL url = _resolveRelativeUrl(m_url, relativeUrl);
187 return FileFactoryImpl.openFileInputStream(m_session, url, m_adaptor);
188 }
189
190 public FileOutputStream openFileOutputStreamSync(URL relativeUrl) throws NotImplementedException, IncorrectURLException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, IncorrectStateException, AlreadyExistsException, DoesNotExistException, TimeoutException, NoSuccessException {
191 URL url = _resolveRelativeUrl(m_url, relativeUrl);
192 boolean exclusive = false;
193 boolean append = false;
194 return FileFactoryImpl.openFileOutputStream(m_session, url, m_adaptor, append, exclusive);
195 }
196 public FileOutputStream openFileOutputStreamSync(URL relativeUrl, boolean append) throws NotImplementedException, IncorrectURLException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, IncorrectStateException, AlreadyExistsException, DoesNotExistException, TimeoutException, NoSuccessException {
197 URL url = _resolveRelativeUrl(m_url, relativeUrl);
198 boolean exclusive = false;
199 return FileFactoryImpl.openFileOutputStream(m_session, url, m_adaptor, append, exclusive);
200 }
201 }