View Javadoc

1   package fr.in2p3.jsaga.impl.file;
2   
3   import fr.in2p3.jsaga.adaptor.data.DataAdaptor;
4   import fr.in2p3.jsaga.impl.namespace.AbstractNSDirectoryImpl;
5   import fr.in2p3.jsaga.impl.namespace.AbstractNSEntryImpl;
6   import org.ogf.saga.error.*;
7   import org.ogf.saga.file.*;
8   import org.ogf.saga.namespace.Flags;
9   import org.ogf.saga.session.Session;
10  import org.ogf.saga.task.TaskMode;
11  import org.ogf.saga.url.URL;
12  
13  /* ***************************************************
14  * *** Centre de Calcul de l'IN2P3 - Lyon (France) ***
15  * ***             http://cc.in2p3.fr/             ***
16  * ***************************************************
17  * File:   DirectoryImpl
18  * Author: Sylvain Reynaud (sreynaud@in2p3.fr)
19  * Date:   18 sept. 2007
20  * ***************************************************
21  * Description:                                      */
22  /**
23   *
24   */
25  public class DirectoryImpl extends AbstractAsyncDirectoryImpl implements Directory {
26      /** constructor for factory */
27      public DirectoryImpl(Session session, URL url, DataAdaptor adaptor, int flags) throws NotImplementedException, IncorrectURLException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, AlreadyExistsException, DoesNotExistException, TimeoutException, NoSuccessException {
28          super(session, url, adaptor, flags);
29      }
30  
31      /** constructor for NSDirectory.open() */
32      public DirectoryImpl(AbstractNSDirectoryImpl dir, URL relativeUrl, int flags) throws NotImplementedException, IncorrectURLException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, AlreadyExistsException, DoesNotExistException, TimeoutException, NoSuccessException {
33          super(dir, relativeUrl, flags);
34      }
35  
36      /** constructor for NSEntry.openAbsolute() */
37      public DirectoryImpl(AbstractNSEntryImpl entry, String absolutePath, int flags) throws NotImplementedException, IncorrectURLException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, AlreadyExistsException, DoesNotExistException, TimeoutException, NoSuccessException {
38          super(entry, absolutePath, flags);
39      }
40  
41      ////////////////////////////////////////// interface Directory //////////////////////////////////////////
42  
43      // <extra specs>
44      public long getSize() throws NotImplementedException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, IncorrectStateException, TimeoutException, NoSuccessException {
45          float timeout = this.getTimeout("getSize");
46          if (timeout == WAIT_FOREVER) {
47              return super.getSizeSync();
48          } else {
49              try {
50                  return (Long) getResult(super.getSize(TaskMode.ASYNC), timeout);
51              }
52              catch (AlreadyExistsException e) {throw new NoSuccessException(e);}
53  			catch (IncorrectURLException e) {throw new NoSuccessException(e);}
54  			catch (DoesNotExistException e) {throw new NoSuccessException(e);}
55              catch (SagaIOException e) {throw new NoSuccessException(e);} 
56          }
57      }
58      
59      public long getSize(int flags) throws NotImplementedException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, IncorrectStateException, TimeoutException, NoSuccessException {
60          float timeout = this.getTimeout("getSize");
61          if (timeout == WAIT_FOREVER) {
62              return super.getSizeSync(flags);
63          } else {
64              try {
65                  return (Long) getResult(super.getSize(TaskMode.ASYNC, flags), timeout);
66              }
67              catch (AlreadyExistsException e) {throw new NoSuccessException(e);}
68  			catch (IncorrectURLException e) {throw new NoSuccessException(e);}
69  			catch (DoesNotExistException e) {throw new NoSuccessException(e);}
70              catch (SagaIOException e) {throw new NoSuccessException(e);}
71          }
72      }
73      // </extra specs>
74  
75      public long getSize(URL name, int flags) throws NotImplementedException, IncorrectURLException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, IncorrectStateException, DoesNotExistException, TimeoutException, NoSuccessException {
76          float timeout = this.getTimeout("getSize");
77          if (timeout == WAIT_FOREVER) {
78              return super.getSizeSync(name, flags);
79          } else {
80              try {
81                  return (Long) getResult(super.getSize(TaskMode.ASYNC, name, flags), timeout);
82              }
83              catch (AlreadyExistsException e) {throw new NoSuccessException(e);}
84              catch (SagaIOException e) {throw new NoSuccessException(e);}
85          }
86      }
87  
88      public long getSize(URL name) throws NotImplementedException, IncorrectURLException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, IncorrectStateException, DoesNotExistException, TimeoutException, NoSuccessException {
89          float timeout = this.getTimeout("getSize");
90          if (timeout == WAIT_FOREVER) {
91              return super.getSizeSync(name);
92          } else {
93              try {
94                  return (Long) getResult(super.getSize(TaskMode.ASYNC, name), timeout);
95              }
96              catch (AlreadyExistsException e) {throw new NoSuccessException(e);}
97              catch (SagaIOException e) {throw new NoSuccessException(e);}
98          }
99      }
100 
101     public boolean isFile(URL name) throws NotImplementedException, IncorrectURLException, DoesNotExistException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, IncorrectStateException, TimeoutException, NoSuccessException {
102         float timeout = this.getTimeout("isFile");
103         if (timeout == WAIT_FOREVER) {
104             return super.isFileSync(name);
105         } else {
106             try {
107                 return (Boolean) getResult(super.isFile(TaskMode.ASYNC, name), timeout);
108             }
109             catch (AlreadyExistsException e) {throw new NoSuccessException(e);}
110             catch (SagaIOException e) {throw new NoSuccessException(e);}
111         }
112     }
113 
114     public Directory openDirectory(URL name, int flags) throws NotImplementedException, IncorrectURLException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, IncorrectStateException, AlreadyExistsException, DoesNotExistException, TimeoutException, NoSuccessException {
115         float timeout = this.getTimeout("openDirectory");
116         if (timeout == WAIT_FOREVER) {
117             return super.openDirectory(name, flags);
118         } else {
119             throw new NotImplementedException("Configuring user timeout is not supported for method: openDirectory");
120         }
121     }
122 
123     public Directory openDirectory(URL name) throws NotImplementedException, IncorrectURLException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, IncorrectStateException, AlreadyExistsException, DoesNotExistException, TimeoutException, NoSuccessException {
124         float timeout = this.getTimeout("openDirectory");
125         if (timeout == WAIT_FOREVER) {
126             return super.openDirectory(name);
127         } else {
128             throw new NotImplementedException("Configuring user timeout is not supported for method: openDirectory");
129         }
130     }
131 
132     public File openFile(URL name, int flags) throws NotImplementedException, IncorrectURLException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, IncorrectStateException, AlreadyExistsException, DoesNotExistException, TimeoutException, NoSuccessException {
133         float timeout = this.getTimeout("openFile");
134         if (timeout == WAIT_FOREVER) {
135             return super.openFile(name, flags);
136         } else {
137             throw new NotImplementedException("Configuring user timeout is not supported for method: openFile");
138         }
139     }
140 
141     public File openFile(URL name) throws NotImplementedException, IncorrectURLException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, IncorrectStateException, AlreadyExistsException, DoesNotExistException, TimeoutException, NoSuccessException {
142         float timeout = this.getTimeout("openFile");
143         if (timeout == WAIT_FOREVER) {
144             return super.openFile(name);
145         } else {
146             throw new NotImplementedException("Configuring user timeout is not supported for method: openFile");
147         }
148     }
149 
150     public FileInputStream openFileInputStream(URL name) throws NotImplementedException, IncorrectURLException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, IncorrectStateException, AlreadyExistsException, DoesNotExistException, TimeoutException, NoSuccessException {
151         float timeout = this.getTimeout("openFileInputStream");
152         if (timeout == WAIT_FOREVER) {
153             return super.openFileInputStreamSync(name);
154         } else {
155             try {
156                 return (FileInputStream) getResult(super.openFileInputStream(TaskMode.ASYNC, name), timeout);
157             }
158             catch (SagaIOException e) {throw new NoSuccessException(e);}
159         }
160     }
161 
162     public FileOutputStream openFileOutputStream(URL name) throws NotImplementedException, IncorrectURLException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, IncorrectStateException, AlreadyExistsException, DoesNotExistException, TimeoutException, NoSuccessException {
163         float timeout = this.getTimeout("openFileOutputStream");
164         if (timeout == WAIT_FOREVER) {
165             return super.openFileOutputStreamSync(name);
166         } else {
167             try {
168                 return (FileOutputStream) getResult(super.openFileOutputStream(TaskMode.ASYNC, name), timeout);
169             }
170             catch (SagaIOException e) {throw new NoSuccessException(e);}
171         }
172     }
173 
174     public FileOutputStream openFileOutputStream(URL name, boolean append) throws NotImplementedException, IncorrectURLException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, IncorrectStateException, AlreadyExistsException, DoesNotExistException, TimeoutException, NoSuccessException {
175         float timeout = this.getTimeout("openFileOutputStream");
176         if (timeout == WAIT_FOREVER) {
177             return super.openFileOutputStreamSync(name, append);
178         } else {
179             try {
180                 return (FileOutputStream) getResult(super.openFileOutputStream(TaskMode.ASYNC, name, append), timeout);
181             }
182             catch (SagaIOException e) {throw new NoSuccessException(e);}
183         }
184     }
185 
186     ////////////////////////////////////////// private methods //////////////////////////////////////////
187 
188     private float getTimeout(String methodName) throws NoSuccessException {
189         return getTimeout(Directory.class, methodName, m_url.getScheme());
190     }
191 }