View Javadoc

1   package fr.in2p3.jsaga.impl.file;
2   
3   import fr.in2p3.jsaga.adaptor.data.DataAdaptor;
4   import fr.in2p3.jsaga.adaptor.data.read.FileReader;
5   import fr.in2p3.jsaga.adaptor.data.read.LogicalReader;
6   import fr.in2p3.jsaga.adaptor.data.write.FileWriter;
7   import fr.in2p3.jsaga.adaptor.data.write.LogicalWriter;
8   import fr.in2p3.jsaga.engine.factories.DataAdaptorFactory;
9   import fr.in2p3.jsaga.impl.file.stream.FileStreamFactoryImpl;
10  import fr.in2p3.jsaga.sync.file.SyncFileFactory;
11  import org.ogf.saga.error.*;
12  import org.ogf.saga.file.*;
13  import org.ogf.saga.session.Session;
14  import org.ogf.saga.url.URL;
15  
16  /* ***************************************************
17   * *** Centre de Calcul de l'IN2P3 - Lyon (France) ***
18   * ***             http://cc.in2p3.fr/             ***
19   * ***************************************************
20   * File:   AbstractSyncFileFactoryImpl
21   * Author: Sylvain Reynaud (sreynaud@in2p3.fr)
22   * Date:   29 mai 2009
23   * ***************************************************
24   * Description:                                      */
25  /**
26   *
27   */
28  public abstract class AbstractSyncFileFactoryImpl extends FileFactory implements SyncFileFactory {
29      private static final boolean PLUGIN_TYPE = DataAdaptorFactory.PHYSICAL;
30      private DataAdaptorFactory m_adaptorFactory;
31  
32      public AbstractSyncFileFactoryImpl(DataAdaptorFactory adaptorFactory) {
33          m_adaptorFactory = adaptorFactory;
34      }
35  
36      protected IOVec doCreateIOVec(byte[] data, int lenIn) throws BadParameterException {
37          throw new BadParameterException("Not implemented by the SAGA engine");
38      }
39  
40      protected IOVec doCreateIOVec(int size, int lenIn) throws BadParameterException, NoSuccessException {
41          throw new BadParameterException("Not implemented by the SAGA engine");
42      }
43  
44      protected IOVec doCreateIOVec(byte[] data) throws BadParameterException, NoSuccessException {
45          throw new BadParameterException("Not implemented by the SAGA engine");
46      }
47  
48      protected IOVec doCreateIOVec(int size) throws BadParameterException, NoSuccessException {
49          throw new BadParameterException("Not implemented by the SAGA engine");
50      }
51  
52      public File doCreateFileSync(Session session, URL name, int flags) throws NotImplementedException, IncorrectURLException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, AlreadyExistsException, DoesNotExistException, TimeoutException, NoSuccessException {
53          DataAdaptor adaptor = m_adaptorFactory.getDataAdaptorAndConnect(name, session, PLUGIN_TYPE);
54          boolean isPhysical = adaptor instanceof FileReader || adaptor instanceof FileWriter;
55          boolean isLogical = adaptor instanceof LogicalReader || adaptor instanceof LogicalWriter;
56          if (isPhysical || !isLogical) {
57              return new FileImpl(session, name, adaptor, flags);
58          } else {
59              throw new BadParameterException("Not a physical file URL: "+name);
60          }
61      }
62  
63      public FileInputStream doCreateFileInputStreamSync(Session session, URL name) throws NotImplementedException, IncorrectURLException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, AlreadyExistsException, DoesNotExistException, TimeoutException, NoSuccessException {
64          DataAdaptor adaptor = m_adaptorFactory.getDataAdaptorAndConnect(name, session, PLUGIN_TYPE);
65          boolean disconnectable = true;
66          return FileStreamFactoryImpl.newFileInputStream(session, name, adaptor, disconnectable);
67      }
68      public static FileInputStream openFileInputStream(Session session, URL name, DataAdaptor adaptor) throws NotImplementedException, IncorrectURLException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, DoesNotExistException, TimeoutException, NoSuccessException {
69          boolean disconnectable = false;
70          return FileStreamFactoryImpl.newFileInputStream(session, name, adaptor, disconnectable);
71      }
72  
73      public FileOutputStream doCreateFileOutputStreamSync(Session session, URL name, boolean append) throws NotImplementedException, IncorrectURLException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, AlreadyExistsException, DoesNotExistException, TimeoutException, NoSuccessException {
74          DataAdaptor adaptor = m_adaptorFactory.getDataAdaptorAndConnect(name, session, PLUGIN_TYPE);
75          boolean disconnectable = true;
76          boolean exclusive = false;
77          return FileStreamFactoryImpl.newFileOutputStream(session, name, adaptor, disconnectable, append, exclusive);
78      }
79      public static FileOutputStream openFileOutputStream(Session session, URL name, DataAdaptor adaptor, boolean append, boolean exclusive) throws NotImplementedException, IncorrectURLException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, AlreadyExistsException, DoesNotExistException, TimeoutException, NoSuccessException {
80          boolean disconnectable = false;
81          return FileStreamFactoryImpl.newFileOutputStream(session, name, adaptor, disconnectable, append, exclusive);
82      }
83  
84      public Directory doCreateDirectorySync(Session session, URL name, int flags) throws NotImplementedException, IncorrectURLException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, AlreadyExistsException, DoesNotExistException, TimeoutException, NoSuccessException {
85          DataAdaptor adaptor = m_adaptorFactory.getDataAdaptorAndConnect(name, session, PLUGIN_TYPE);
86          boolean isPhysical = adaptor instanceof FileReader || adaptor instanceof FileWriter;
87          boolean isLogical = adaptor instanceof LogicalReader || adaptor instanceof LogicalWriter;
88          if (isPhysical || !isLogical) {
89              return new DirectoryImpl(session, name, adaptor, flags);
90          } else {
91              throw new BadParameterException("Not a physical directory URL: "+name);
92          }
93      }
94  }