View Javadoc

1   package fr.in2p3.jsaga.impl.namespace;
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.DirectoryImpl;
10  import fr.in2p3.jsaga.impl.file.FileImpl;
11  import fr.in2p3.jsaga.impl.logicalfile.LogicalDirectoryImpl;
12  import fr.in2p3.jsaga.impl.logicalfile.LogicalFileImpl;
13  import fr.in2p3.jsaga.sync.namespace.SyncNSFactory;
14  import org.ogf.saga.error.*;
15  import org.ogf.saga.namespace.*;
16  import org.ogf.saga.session.Session;
17  import org.ogf.saga.url.URL;
18  
19  /* ***************************************************
20   * *** Centre de Calcul de l'IN2P3 - Lyon (France) ***
21   * ***             http://cc.in2p3.fr/             ***
22   * ***************************************************
23   * File:   AbstractSyncNSFactoryImpl
24   * Author: Sylvain Reynaud (sreynaud@in2p3.fr)
25   * Date:   29 mai 2009
26   * ***************************************************
27   * Description:                                      */
28  /**
29   *
30   */
31  public abstract class AbstractSyncNSFactoryImpl extends NSFactory implements SyncNSFactory {
32      private static final boolean PLUGIN_TYPE = DataAdaptorFactory.PHYSICAL;
33      private DataAdaptorFactory m_adaptorFactory;
34  
35      public AbstractSyncNSFactoryImpl(DataAdaptorFactory adaptorFactory) {
36          m_adaptorFactory = adaptorFactory;
37      }
38  
39      /**
40       * Notes:
41       * <br> - do not check existance of entry if flag <code>JSAGAFlags.BYPASSEXIST</code> is set.
42       * <br> - do not throw BadParameterException exception if entry is a directory, create a NSDirectory object instead.
43       */
44      public NSEntry doCreateNSEntrySync(Session session, URL name, int flags) throws NotImplementedException, IncorrectURLException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, AlreadyExistsException, DoesNotExistException, TimeoutException, NoSuccessException {
45          if (name.getPath().endsWith("/")) {
46              return this.doCreateNSDirectorySync(session, name, flags);
47          } else {
48              return this.doCreateNSFileSync(session, name, flags);
49          }
50      }
51  
52      /**
53       * Notes:
54       * <br> - do not check existance of entry if flag <code>JSAGAFlags.BYPASSEXIST</code> is set.
55       * <br> - support the CREATEPARENTS flag (from specification of method makeDir).
56       */
57      public NSDirectory doCreateNSDirectorySync(Session session, URL name, int flags) throws NotImplementedException, IncorrectURLException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, AlreadyExistsException, DoesNotExistException, TimeoutException, NoSuccessException {
58          DataAdaptor adaptor = m_adaptorFactory.getDataAdaptorAndConnect(name, session, PLUGIN_TYPE);
59          boolean isPhysical = adaptor instanceof FileReader || adaptor instanceof FileWriter;
60          boolean isLogical = adaptor instanceof LogicalReader || adaptor instanceof LogicalWriter;
61          if (isPhysical || !isLogical) {
62              return new DirectoryImpl(session, name, adaptor, flags);
63          } else {
64              return new LogicalDirectoryImpl(session, name, adaptor, flags);
65          }
66      }
67  
68      /**
69       * Notes:
70       * <br> - do not check existance of entry if flag <code>JSAGAFlags.BYPASSEXIST</code> is set.
71       * <br> - support the CREATEPARENTS flag (from specification of method makeDir).
72       */
73      private NSEntry doCreateNSFileSync(Session session, URL name, int flags) throws NotImplementedException, IncorrectURLException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, AlreadyExistsException, DoesNotExistException, TimeoutException, NoSuccessException {
74          DataAdaptor adaptor = m_adaptorFactory.getDataAdaptorAndConnect(name, session, PLUGIN_TYPE);
75          boolean isPhysical = adaptor instanceof FileReader || adaptor instanceof FileWriter;
76          boolean isLogical = adaptor instanceof LogicalReader || adaptor instanceof LogicalWriter;
77          if (isPhysical || !isLogical) {
78              return new FileImpl(session, name, adaptor, flags);
79          } else {
80              return new LogicalFileImpl(session, name, adaptor, flags);
81          }
82      }
83  }